123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using System;
- using System.Collections.Generic;
- using UnityEditor;
- using UnityEngine;
- namespace XGame.Editor.Asset.Addressable
- {
- /// <summary>
- /// 文件夹
- /// </summary>
- public class AddressableAssetFold : AddressableAssetEntry
- {
- private readonly List<AddressableAssetEntry> childs;
- //private bool isFoldout;
- private bool isSort;
- public override EntryType EnType => EntryType.Fold;
- private event Action addChildrenEvent;
- public event Action AddChildrenEvent
- {
- add { addChildrenEvent += value; }
- remove { addChildrenEvent -= value; }
- }
- public AddressableAssetFold(string path) : base(path)
- {
- childs = new List<AddressableAssetEntry>();
- isSort = false;
- }
- public void AddChild(AddressableAssetEntry entry)
- {
- if (entry.Parent != null && entry.Parent.Equals(this))
- {
- Debug.LogError($"Add Child Repeat. Parent:{Path} Child:{entry.Path}");
- return;
- }
- childs.Add(entry);
- entry.Parent = this;
- isSort = true;
- }
- public void RemoveChild(AddressableAssetEntry entry)
- {
- if (childs.Contains(entry))
- {
- childs.Remove(entry);
- }
- entry.Parent = null;
- }
- public AddressableAssetEntry GetChild(string path)
- {
- return childs.Find((entry => entry.Path.Equals(path)));
- }
- public bool Contains(string path)
- {
- return childs.Find((entry => entry.Path.Equals(path))) != null;
- }
- /// <summary>
- /// 节点数量
- /// </summary>
- public int ChildCount => childs.Count;
- protected override void OnSetParent()
- {
- }
- protected override void OnGUI()
- {
- EditorGUILayout.BeginVertical();
- IsFoldout = EditorGUILayout.Foldout(IsFoldout, ShowName);
- if (IsFoldout)
- {
- if (addChildrenEvent != null)
- {
- addChildrenEvent.Invoke();
- addChildrenEvent = null;
- }
- if (isSort)
- {
- isSort = false;
- childs.Sort();
- }
- for (int i = 0; i < childs.Count;)
- {
- var child = childs[i];
- child.GUI();
- if (child.Parent != null)
- {
- i++;
- }
- }
- }
- EditorGUILayout.EndVertical();
- }
- protected override void OnClear()
- {
- foreach (var child in childs)
- {
- child.Clear();
- }
- childs.Clear();
- addChildrenEvent = null;
- isSort = false;
- }
- }
- }
|