Files
ichni_Creator_Studio/Assets/Scripts/DynamicUI/Hierarchy/HierarchyTab.cs

141 lines
4.4 KiB
C#
Raw Normal View History

2025-02-09 23:47:42 -05:00
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;
2025-02-11 22:58:56 -05:00
2025-02-09 23:47:42 -05:00
public GameElement connectedGameElement;
public HierarchyTab parentTab;
public List<HierarchyTab> childTabList;
public List<int> IDqueue;
2025-02-11 22:58:56 -05:00
2025-02-09 23:47:42 -05:00
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)
{
2025-02-11 22:58:56 -05:00
connectedGameElement = targetElement;
2025-02-09 23:47:42 -05:00
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();
2025-02-11 22:58:56 -05:00
}
else
{
2025-02-09 23:47:42 -05:00
this.parentTab = parentElement.connectedTab;
parentElement.connectedTab.childTabList.Add(this);
2025-02-09 23:47:42 -05:00
this.tabLayer = this.parentTab.tabLayer + 1;
2025-02-11 22:58:56 -05:00
2025-02-09 23:47:42 -05:00
this.transform.SetSiblingIndex(this.parentTab.transform.GetSiblingIndex() +
this.parentTab.connectedGameElement.childElementList.Count);
2025-02-09 23:47:42 -05:00
if (!this.parentTab.isExpanded)
{
this.isExpanded = false;
SetExpansion(false);
}
for (int i = 1; i <= this.tabLayer; i++)
{
float lineX = 30 * i;
2025-02-09 23:47:42 -05:00
Instantiate(indentationLinePrefab, tabRect).GetComponent<RectTransform>().anchoredPosition = new Vector2(lineX, 0);
}
}
2025-02-11 22:58:56 -05:00
2025-02-09 23:47:42 -05:00
float posX = -25 +( 30 * tabLayer);
2025-02-09 23:47:42 -05:00
tabMainRect.anchoredPosition = new Vector2(posX, tabMainRect.anchoredPosition.y);
2025-02-11 22:58:56 -05:00
tabButton.onClick.AddListener(SelectGameElement);
2025-02-09 23:47:42 -05:00
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;
}
2025-02-11 22:58:56 -05:00
private void SelectGameElement()
{
2025-02-17 14:46:14 -05:00
EditorManager.instance.uiManager.inspector.SetInspector(connectedGameElement);
2025-02-11 22:58:56 -05:00
}
2025-02-09 23:47:42 -05:00
private void ExpandOrFold()
{
this.childTabList.RemoveAll(s => s == null);
2025-02-11 22:58:56 -05:00
isExpanded = !isExpanded;
2025-02-09 23:47:42 -05:00
2025-02-11 22:58:56 -05:00
if (isExpanded)
{
expandButton.transform.Rotate(new Vector3(0, 0, 180));
foreach (GameElement i in connectedGameElement.childElementList)
{
HierarchyTab a = EditorManager.instance.uiManager.hierarchy.GenerateTab(i, connectedGameElement);
childTabList.Add(a);
}
2025-02-11 22:58:56 -05:00
}
else
{
expandButton.transform.Rotate(new Vector3(0, 0, 180));
2025-02-11 22:58:56 -05:00
for (int i = childTabList.Count - 1; i >= 0; i--)
{
childTabList[i].SetExpansion(isExpanded);
}
2025-02-09 23:47:42 -05:00
}
}
private void SetExpansion(bool expand)
{
2025-02-11 22:58:56 -05:00
if (!expand && isExpanded)
2025-02-09 23:47:42 -05:00
{
for(int i=childTabList.Count;i>0;i--)
2025-02-09 23:47:42 -05:00
{
childTabList[i-1].SetExpansion(expand); //false
2025-02-09 23:47:42 -05:00
}
}
if (!expand)
2025-02-09 23:47:42 -05:00
{
parentTab.childTabList.Remove(this);
2025-02-11 22:58:56 -05:00
Destroy(gameObject);
2025-02-09 23:47:42 -05:00
}
}
}
}