#if UNITY_2019_4_OR_NEWER
using System.IO;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
public class TreeNode
{
///
/// 子节点集合
///
public List Children = new List(10);
///
/// 父节点
///
public TreeNode Parent { get; set; }
///
/// 用户数据
///
public object UserData { get; set; }
///
/// 是否展开
///
public bool IsExpanded { get; set; } = false;
public TreeNode(object userData)
{
UserData = userData;
}
///
/// 添加子节点
///
public void AddChild(TreeNode child)
{
child.Parent = this;
Children.Add(child);
}
///
/// 清理所有子节点
///
public void ClearChildren()
{
foreach(var child in Children)
{
child.Parent = null;
}
Children.Clear();
}
///
/// 计算节点的深度
///
public int GetDepth()
{
int depth = 0;
TreeNode current = this;
while (current.Parent != null)
{
depth++;
current = current.Parent;
}
return depth;
}
}
}
#endif