Signed-off-by: TRADER_FOER <lhf190@outlook.com>
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
using Lean.Pool;
|
||||
using Ichni.RhythmGame;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
@@ -29,26 +30,23 @@ namespace Ichni.Editor
|
||||
rectTransform = this.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
public HierarchyTab GenerateTab(GameElement targetElement, GameElement parentElement)
|
||||
public HierarchyTab GenerateTab(GameElement targetElement, GameElement parentElement, bool animate = true)
|
||||
{
|
||||
HierarchyTab tab = Instantiate(hierarchyTabPrefab, tabContainer).GetComponent<HierarchyTab>();
|
||||
tab.SetTab(targetElement, parentElement);
|
||||
if (targetElement.connectedTab != null) return targetElement.connectedTab;
|
||||
|
||||
HierarchyTab tab = LeanPool.Spawn(hierarchyTabPrefab, tabContainer).GetComponent<HierarchyTab>();
|
||||
tab.SetTab(targetElement, parentElement, animate);
|
||||
tabList.Add(tab);
|
||||
return tab;
|
||||
}
|
||||
public async Task<HierarchyTab> GenerateTabAsync(GameElement targetElement, GameElement parentElement)
|
||||
{
|
||||
var request = InstantiateAsync(hierarchyTabPrefab, tabContainer);
|
||||
if (targetElement.connectedTab != null) return targetElement.connectedTab;
|
||||
|
||||
// 等待实例化过程完成
|
||||
while (!request.isDone)
|
||||
{
|
||||
await Task.Yield(); // 异步地等待下一帧
|
||||
}
|
||||
HierarchyTab tab = request.Result[0].GetComponent<HierarchyTab>();
|
||||
HierarchyTab tab = LeanPool.Spawn(hierarchyTabPrefab, tabContainer).GetComponent<HierarchyTab>();
|
||||
tab.SetTab(targetElement, parentElement);
|
||||
tabList.Add(tab);
|
||||
// 返回实例化的游戏对象
|
||||
await Task.Yield();
|
||||
return tab;
|
||||
}
|
||||
public bool isExpand = false;
|
||||
@@ -100,29 +98,20 @@ namespace Ichni.Editor
|
||||
{
|
||||
if (targetElement.connectedTab != null)
|
||||
{
|
||||
// 如果已经有Tab了,直接选中
|
||||
targetElement.connectedTab.SelectGameElement();
|
||||
getTabPos(targetElement.connectedTab);
|
||||
return;
|
||||
}
|
||||
targetElement.ScanAndAddEnableTypes();
|
||||
if (!EditorManager.instance.ExpandWhileClick)
|
||||
{
|
||||
var tab = EditorManager.instance.uiManager.hierarchy.GenerateTab(targetElement, null);
|
||||
tab.SelectGameElement();
|
||||
Destroy(tab.gameObject);
|
||||
EditorManager.instance.uiManager.hierarchy.tabList.Remove(tab);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(TryGetTab(targetElement));
|
||||
}
|
||||
|
||||
StartCoroutine(TryGetTab(targetElement));
|
||||
|
||||
}
|
||||
|
||||
public IEnumerator TryGetTab(GameElement targetElement)
|
||||
{
|
||||
// 1. 向上找到最近的有Tab的祖先
|
||||
// 1. 向上收集所有没有Tab的祖先
|
||||
Stack<GameElement> stack = new Stack<GameElement>();
|
||||
GameElement current = targetElement;
|
||||
while (current != null && current.connectedTab == null)
|
||||
@@ -131,47 +120,42 @@ namespace Ichni.Editor
|
||||
current = current.parentElement;
|
||||
}
|
||||
|
||||
// 2. 如果有Tab的祖先存在,依次展开回目标
|
||||
HierarchyTab parentTab = current != null ? current.connectedTab : null;
|
||||
// 2. 从顶层祖先开始,逐层同步展开
|
||||
while (stack.Count > 0)
|
||||
{
|
||||
var elem = stack.Pop();
|
||||
// 只展开父Tab,不直接生成Tab
|
||||
if (elem.parentElement != null && elem.parentElement.connectedTab != null)
|
||||
{
|
||||
if (!elem.parentElement.connectedTab.isExpanded)
|
||||
{
|
||||
elem.parentElement.connectedTab.ExpandOrFold(true);
|
||||
}
|
||||
else if (!elem.parentElement.connectedTab.isExpandDone)
|
||||
{
|
||||
elem.parentElement.connectedTab.ExpandOrFold();
|
||||
elem.parentElement.connectedTab.ExpandOrFold(true);//合上再展开,这思路也是没谁了
|
||||
}
|
||||
else
|
||||
{
|
||||
//他就在展开了,等下就好了
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
// 等待当前elem的Tab生成
|
||||
while (elem.connectedTab == null)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
parentTab = elem.connectedTab;
|
||||
}
|
||||
|
||||
// 3. 等待目标Tab实例化
|
||||
while (targetElement.connectedTab is null)
|
||||
{
|
||||
var parentTab = elem.parentElement?.connectedTab;
|
||||
|
||||
if (parentTab != null)
|
||||
{
|
||||
if (!parentTab.isExpanded)
|
||||
{
|
||||
StartCoroutine(parentTab.ExpandSyncBatched());
|
||||
yield return new WaitUntil(() => parentTab.isExpandDone);
|
||||
}
|
||||
else if (elem.connectedTab == null)
|
||||
{
|
||||
// 父节点已展开但当前元素缺失Tab(刚添加或曾被折叠),直接补生成
|
||||
GenerateTab(elem, elem.parentElement, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (elem.connectedTab == null)
|
||||
GenerateTab(elem, null, false);
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
yield return null; // 等待一帧,确保UI更新
|
||||
|
||||
// 3. 最终确保目标Tab存在
|
||||
if (targetElement.connectedTab == null)
|
||||
{
|
||||
GenerateTab(targetElement, targetElement.parentElement, false);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
getTabPos(targetElement.connectedTab);
|
||||
|
||||
|
||||
}
|
||||
void getTabPos(HierarchyTab finalTab)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user