64 lines
1.4 KiB
C#
64 lines
1.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace XED
|
|
{
|
|
public class TreeItem
|
|
{
|
|
public TwinObject twinObject;
|
|
//public UI_HierarchyItem View;
|
|
public event Action onDestroyTreeItem;
|
|
|
|
public int depth
|
|
{
|
|
get
|
|
{
|
|
TreeItem curr = parent;
|
|
int result = 0;
|
|
while (curr != null)
|
|
{
|
|
result++;
|
|
curr = curr.parent;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
public List<TreeItem> children = new List<TreeItem>();
|
|
public TreeItem parent;
|
|
public bool expanded = true;
|
|
public event Action<TreeItem> onExpand;
|
|
public event Action<TreeItem> onFold;
|
|
|
|
public TreeItem(TwinObject to)
|
|
{
|
|
twinObject = to;
|
|
}
|
|
|
|
internal void Add(TreeItem t)
|
|
{
|
|
children.Add(t);
|
|
}
|
|
|
|
internal void RemoveChild(TreeItem c)
|
|
{
|
|
children.Remove(c);
|
|
}
|
|
|
|
public void OnExpand(bool value)
|
|
{
|
|
expanded = value;
|
|
if (value)
|
|
onExpand?.Invoke(this);
|
|
else
|
|
onFold?.Invoke(this);
|
|
}
|
|
|
|
public void DestroyTreeItem()
|
|
{
|
|
onDestroyTreeItem?.Invoke();
|
|
}
|
|
}
|
|
}
|