选择可显示项
本来想做启闭的懒得做了
This commit is contained in:
@@ -41,8 +41,18 @@ namespace Ichni.Editor
|
||||
}
|
||||
public IEnumerator TryGetTab(GameElement targetElement)
|
||||
{
|
||||
|
||||
StandardInspectionElement.GenerateForLoading();
|
||||
// targetElement.ScanAndAddEnableTypes();
|
||||
// if (!targetElement.GetChildrenByTypes().Contains(targetElement))
|
||||
// {
|
||||
// var tab = EditorManager.instance.uiManager.hierarchy.GenerateTab(targetElement, null);
|
||||
// tab.SelectGameElement();
|
||||
// Destroy(tab.gameObject);
|
||||
// EditorManager.instance.uiManager.hierarchy.tabList.Remove(tab);
|
||||
// yield break;
|
||||
// }
|
||||
// EditorManager.instance.uiManager.inspector.ClearInspector();
|
||||
// EditorManager.instance.uiManager.inspector.SetInspector(targetElement);
|
||||
//StandardInspectionElement.GenerateForLoading();
|
||||
// 1. 向上找到最近的有Tab的祖先
|
||||
Stack<GameElement> stack = new Stack<GameElement>();
|
||||
GameElement current = targetElement;
|
||||
@@ -58,9 +68,17 @@ namespace Ichni.Editor
|
||||
{
|
||||
var elem = stack.Pop();
|
||||
// 只展开父Tab,不直接生成Tab
|
||||
if (elem.parentElement != null && elem.parentElement.connectedTab != null && !elem.parentElement.connectedTab.isExpanded)
|
||||
if (elem.parentElement != null && elem.parentElement.connectedTab != null)
|
||||
{
|
||||
elem.parentElement.connectedTab.ExpandOrFold();
|
||||
if (!elem.parentElement.connectedTab.isExpanded)
|
||||
{
|
||||
elem.parentElement.connectedTab.ExpandOrFold(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
elem.parentElement.connectedTab.ExpandOrFold();
|
||||
elem.parentElement.connectedTab.ExpandOrFold(true);//合上再展开,这思路也是没谁了
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
// 等待当前elem的Tab生成
|
||||
@@ -72,15 +90,36 @@ namespace Ichni.Editor
|
||||
}
|
||||
|
||||
// 3. 等待目标Tab实例化
|
||||
while (targetElement.connectedTab == null)
|
||||
while (targetElement.connectedTab is 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;
|
||||
|
||||
// 修正定位算法
|
||||
yield return null; // 等待布局刷新
|
||||
RectTransform tabRect = finalTab.GetComponent<RectTransform>();
|
||||
RectTransform containerRect = tabContainer;
|
||||
RectTransform viewportRect = scrollRect.viewport != null ? scrollRect.viewport : scrollRect.GetComponent<RectTransform>();
|
||||
|
||||
// Tab相对于内容顶部的距离(正值为下,负值为上)
|
||||
float tabTop = -tabRect.anchoredPosition.y;
|
||||
float tabHeight = tabRect.rect.height;
|
||||
float contentHeight = containerRect.rect.height;
|
||||
float viewportHeight = viewportRect.rect.height;
|
||||
|
||||
// 目标:让Tab居中(或尽量居中)
|
||||
float targetCenter = tabTop + tabHeight / 2f;
|
||||
float viewportCenter = viewportHeight / 2f;
|
||||
float scrollOffset = targetCenter - viewportCenter;
|
||||
|
||||
// normalizedPosition = 1 - (scrollOffset / (contentHeight - viewportHeight))
|
||||
float denominator = Mathf.Max(1f, contentHeight - viewportHeight);
|
||||
float normalized = 1f - Mathf.Clamp01(scrollOffset / denominator);
|
||||
|
||||
scrollRect.verticalNormalizedPosition = normalized;
|
||||
finalTab.SelectGameElement();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user