87 lines
3.1 KiB
C#
87 lines
3.1 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using Ichni.RhythmGame;
|
||
using Unity.VisualScripting;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
namespace Ichni.Editor
|
||
{
|
||
public class Hierarchy : StaticWindow
|
||
{
|
||
public GameObject hierarchyTabPrefab;
|
||
public RectTransform tabContainer;
|
||
public Button addFolderButton;
|
||
public List<HierarchyTab> tabList;
|
||
|
||
private void Awake()
|
||
{
|
||
tabList = new List<HierarchyTab>();
|
||
addFolderButton.onClick.AddListener(() =>
|
||
{
|
||
ElementFolder.GenerateElement("New Folder", Guid.NewGuid(), new List<string>(), true, null);
|
||
});
|
||
}
|
||
|
||
public HierarchyTab GenerateTab(GameElement targetElement, GameElement parentElement)
|
||
{
|
||
HierarchyTab tab = Instantiate(hierarchyTabPrefab, tabContainer).GetComponent<HierarchyTab>();
|
||
tab.SetTab(targetElement, parentElement);
|
||
tabList.Add(tab);
|
||
return tab;
|
||
}
|
||
|
||
public ScrollRect scrollRect;
|
||
public Vector2 vector2;
|
||
public void FindTab(GameElement targetElement, bool findparent = false)
|
||
{
|
||
//targetElement.SetUpInspector();
|
||
StartCoroutine(TryGetTab(targetElement));
|
||
}
|
||
public IEnumerator TryGetTab(GameElement targetElement)
|
||
{
|
||
|
||
StandardInspectionElement.GenerateForLoading();
|
||
// 1. 向上找到最近的有Tab的祖先
|
||
Stack<GameElement> stack = new Stack<GameElement>();
|
||
GameElement current = targetElement;
|
||
while (current != null && current.connectedTab == null)
|
||
{
|
||
stack.Push(current);
|
||
current = current.parentElement;
|
||
}
|
||
|
||
// 2. 如果有Tab的祖先存在,依次展开回目标
|
||
HierarchyTab parentTab = current != null ? current.connectedTab : null;
|
||
while (stack.Count > 0)
|
||
{
|
||
var elem = stack.Pop();
|
||
// 只展开父Tab,不直接生成Tab
|
||
if (elem.parentElement != null && elem.parentElement.connectedTab != null && !elem.parentElement.connectedTab.isExpanded)
|
||
{
|
||
elem.parentElement.connectedTab.ExpandOrFold();
|
||
yield return null;
|
||
}
|
||
// 等待当前elem的Tab生成
|
||
while (elem.connectedTab == null)
|
||
{
|
||
yield return null;
|
||
}
|
||
parentTab = elem.connectedTab;
|
||
}
|
||
|
||
// 3. 等待目标Tab实例化
|
||
while (targetElement.connectedTab == null)
|
||
{
|
||
yield return null;
|
||
}
|
||
|
||
HierarchyTab finalTab = targetElement.connectedTab;
|
||
float Tablocalpos = (-finalTab.transform.localPosition.y) - (tabContainer.sizeDelta.y / 4f);
|
||
float pct = Tablocalpos / tabContainer.sizeDelta.y;
|
||
scrollRect.verticalNormalizedPosition = 1f - pct;
|
||
finalTab.SelectGameElement();
|
||
}
|
||
}
|
||
} |