125 lines
3.8 KiB
C#
125 lines
3.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Ichni.RhythmGame;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Ichni.Editor
|
|
{
|
|
public partial class HierarchyTab : MonoBehaviour
|
|
{
|
|
public GameObject indentationLinePrefab;
|
|
|
|
public GameElement connectedGameElement;
|
|
public HierarchyTab parentTab;
|
|
public List<HierarchyTab> childTabList;
|
|
|
|
public int tabLayer;
|
|
public bool isSelected;
|
|
public bool isExpanded;
|
|
|
|
public RectTransform tabRect;
|
|
public LayoutElement layoutElement;
|
|
public RectTransform tabMainRect;
|
|
public Button tabButton;
|
|
public Button expandButton;
|
|
public Button gotoButton;
|
|
public TMP_Text tabButtonText;
|
|
|
|
|
|
public void SetTab(GameElement targetElement, GameElement parentElement)
|
|
{
|
|
tabButtonText.text = targetElement.elementName;
|
|
targetElement.connectedTab = this;
|
|
this.isExpanded = false;
|
|
this.isSelected = false;
|
|
this.childTabList = new List<HierarchyTab>();
|
|
|
|
if (parentElement == null)
|
|
{
|
|
this.tabLayer = 0;
|
|
this.parentTab = null;
|
|
this.transform.SetAsLastSibling();
|
|
}
|
|
else
|
|
{
|
|
this.parentTab = parentElement.connectedTab;
|
|
this.tabLayer = this.parentTab.tabLayer + 1;
|
|
|
|
this.parentTab.childTabList.Add(this);
|
|
this.transform.SetSiblingIndex(this.parentTab.transform.GetSiblingIndex() +
|
|
GetAllChildrenCount(this.parentTab));
|
|
|
|
if (!this.parentTab.isExpanded)
|
|
{
|
|
this.isExpanded = false;
|
|
SetExpansion(false);
|
|
}
|
|
|
|
for (int i = 1; i <= this.tabLayer; i++)
|
|
{
|
|
float lineX = 10 * i;
|
|
Instantiate(indentationLinePrefab, tabRect).GetComponent<RectTransform>().anchoredPosition = new Vector2(lineX, 0);
|
|
}
|
|
}
|
|
|
|
float posX = -25 + 10 * tabLayer;
|
|
tabMainRect.anchoredPosition = new Vector2(posX, tabMainRect.anchoredPosition.y);
|
|
|
|
expandButton.onClick.AddListener(ExpandOrFold);
|
|
}
|
|
}
|
|
|
|
public partial class HierarchyTab
|
|
{
|
|
private int GetAllChildrenCount(HierarchyTab tab)
|
|
{
|
|
int c = tab.childTabList.Count;
|
|
|
|
for (int i = 0; i < tab.childTabList.Count; i++)
|
|
{
|
|
c += GetAllChildrenCount(tab.childTabList[i]);
|
|
}
|
|
|
|
return c;
|
|
}
|
|
|
|
private void ExpandOrFold()
|
|
{
|
|
this.childTabList.RemoveAll(s => s == null);
|
|
bool op = !isExpanded;
|
|
|
|
for (int i = 0; i < childTabList.Count; i++)
|
|
{
|
|
childTabList[i].SetExpansion(op);
|
|
}
|
|
|
|
isExpanded = op;
|
|
}
|
|
|
|
private void SetExpansion(bool expand)
|
|
{
|
|
if (!(expand == true && isExpanded == false))
|
|
{
|
|
foreach (var tab in childTabList)
|
|
{
|
|
tab.SetExpansion(expand);
|
|
}
|
|
}
|
|
|
|
if (expand)
|
|
{
|
|
gameObject.SetActive(true);
|
|
tabRect.localScale = Vector3.one;
|
|
layoutElement.ignoreLayout = false;
|
|
}
|
|
else
|
|
{
|
|
tabRect.localScale = Vector3.zero;
|
|
layoutElement.ignoreLayout = true;
|
|
gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
} |