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

87 lines
3.1 KiB
C#
Raw Normal View History

2025-03-08 23:11:55 -05:00
using System;
2025-02-09 23:47:42 -05:00
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame;
using Unity.VisualScripting;
2025-02-09 23:47:42 -05:00
using UnityEngine;
using UnityEngine.UI;
2025-02-09 23:47:42 -05:00
namespace Ichni.Editor
{
public class Hierarchy : StaticWindow
{
public GameObject hierarchyTabPrefab;
public RectTransform tabContainer;
2025-03-08 23:11:55 -05:00
public Button addFolderButton;
2025-02-09 23:47:42 -05:00
public List<HierarchyTab> tabList;
2025-02-11 22:58:56 -05:00
2025-03-08 23:11:55 -05:00
private void Awake()
{
tabList = new List<HierarchyTab>();
addFolderButton.onClick.AddListener(() =>
{
ElementFolder.GenerateElement("New Folder", Guid.NewGuid(), new List<string>(), true, null);
});
}
2025-02-11 22:58:56 -05:00
public HierarchyTab GenerateTab(GameElement targetElement, GameElement parentElement)
2025-02-09 23:47:42 -05:00
{
2025-02-11 22:58:56 -05:00
HierarchyTab tab = Instantiate(hierarchyTabPrefab, tabContainer).GetComponent<HierarchyTab>();
2025-02-09 23:47:42 -05:00
tab.SetTab(targetElement, parentElement);
tabList.Add(tab);
return tab;
2025-02-09 23:47:42 -05:00
}
2025-03-16 00:42:27 +08:00
2025-05-11 14:12:47 +08:00
public ScrollRect scrollRect;
public Vector2 vector2;
public void FindTab(GameElement targetElement, bool findparent = false)
{
2025-06-14 20:47:45 +08:00
//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)
{
2025-06-14 20:47:45 +08:00
stack.Push(current);
current = current.parentElement;
}
2025-06-14 20:47:45 +08:00
// 2. 如果有Tab的祖先存在依次展开回目标
HierarchyTab parentTab = current != null ? current.connectedTab : null;
while (stack.Count > 0)
{
2025-06-14 20:47:45 +08:00
var elem = stack.Pop();
// 只展开父Tab不直接生成Tab
if (elem.parentElement != null && elem.parentElement.connectedTab != null && !elem.parentElement.connectedTab.isExpanded)
2025-05-24 14:34:12 +08:00
{
2025-06-14 20:47:45 +08:00
elem.parentElement.connectedTab.ExpandOrFold();
yield return null;
2025-05-24 14:34:12 +08:00
}
2025-06-14 20:47:45 +08:00
// 等待当前elem的Tab生成
while (elem.connectedTab == null)
2025-05-24 14:34:12 +08:00
{
2025-06-14 20:47:45 +08:00
yield return null;
2025-05-24 14:34:12 +08:00
}
2025-06-14 20:47:45 +08:00
parentTab = elem.connectedTab;
}
2025-05-24 14:34:12 +08:00
2025-06-14 20:47:45 +08:00
// 3. 等待目标Tab实例化
while (targetElement.connectedTab == null)
{
yield return null;
}
2025-06-14 20:47:45 +08:00
HierarchyTab finalTab = targetElement.connectedTab;
float Tablocalpos = (-finalTab.transform.localPosition.y) - (tabContainer.sizeDelta.y / 4f);
2025-05-11 14:12:47 +08:00
float pct = Tablocalpos / tabContainer.sizeDelta.y;
scrollRect.verticalNormalizedPosition = 1f - pct;
2025-06-14 20:47:45 +08:00
finalTab.SelectGameElement();
}
2025-02-09 23:47:42 -05:00
}
}