Signed-off-by: TRADER_FOER <lhf190@outlook.com>

This commit is contained in:
2026-05-02 22:10:19 +08:00
parent 91bc3a269b
commit 648269d509
12 changed files with 236 additions and 165 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DG.Tweening;
using Lean.Pool;
using Ichni.RhythmGame;
using Michsky.MUIP;
using Sirenix.Utilities;
@@ -35,10 +36,20 @@ namespace Ichni.Editor
public DoubleCheckButton deleteButton;
public TMP_Text tabButtonText;
public void SetTab(GameElement targetElement, GameElement parentElement)
private List<GameObject> indentationLines = new List<GameObject>();
public void SetTab(GameElement targetElement, GameElement parentElement, bool animate = true)
{
transform.localScale = Vector3.one;
transform.DOScale(Vector3.one, 0.2f).SetEase(Ease.OutCirc).From(new Vector3(1, 0, 1));
if (animate)
{
transform.localScale = Vector3.one;
transform.DOScale(Vector3.one, 0.2f).SetEase(Ease.OutCirc).From(new Vector3(1, 0, 1));
}
else
{
transform.DOKill();
transform.localScale = Vector3.one;
}
connectedGameElement = targetElement;
tabButtonText.text = targetElement.elementName;
targetElement.connectedTab = this;
@@ -46,6 +57,14 @@ namespace Ichni.Editor
this.isSelected = false;
this.childTabList = new List<HierarchyTab>();
// 清除旧的缩进线
for (int i = indentationLines.Count - 1; i >= 0; i--)
{
if (indentationLines[i] != null)
Destroy(indentationLines[i]);
}
indentationLines.Clear();
if (parentElement == null)
{
this.tabLayer = 0;
@@ -62,7 +81,10 @@ namespace Ichni.Editor
if (!this.parentTab.isExpanded)
{
this.isExpanded = false;
var pt = this.parentTab;
SetExpansion(false);
pt.SetStatus();
return;
}
for (int i = 1; i <= this.tabLayer; i++)
@@ -70,14 +92,17 @@ namespace Ichni.Editor
float lineX = 30 * i - 15;
var d = Instantiate(indentationLinePrefab, tabRect);
d.GetComponent<RectTransform>().anchoredPosition = new Vector2(lineX, 0);
indentationLines.Add(d);
}
parentTab.SetStatus();
parentTab?.SetStatus();
}
float posX = (30 * tabLayer);
tabMainRect.anchoredPosition = new Vector2(posX, tabMainRect.anchoredPosition.y);
tabButton.onClick.RemoveAllListeners();
tabButton.onClick.AddListener(SelectGameElement);
expandButton.onClick.RemoveAllListeners();
expandButton.onClick.AddListener(ExpandOrFold);
deleteButton.onConfirm = () => EditorManager.instance.operationManager.CopyPasteDeleteModule.DeleteElement(connectedGameElement);
@@ -87,6 +112,13 @@ namespace Ichni.Editor
private void OnDestroy()
{
transform.DOKill();
// 清除缩进线
for (int i = indentationLines.Count - 1; i >= 0; i--)
{
if (indentationLines[i] != null)
Destroy(indentationLines[i]);
}
indentationLines.Clear();
}
public void SetStatus()
@@ -293,9 +325,6 @@ namespace Ichni.Editor
connectedGameElement.ScanAndAddEnableTypes();
List<GameElement> FixedList = !forceAllExPand ? connectedGameElement.GetChildrenByTypes() : connectedGameElement.childElementList;
// float startTime = Time.realtimeSinceStartup;
// connectedGameElement.childElementList.Sort();//TODO: 后续可以让玩家手动快速排序
Debug.Log(FixedList.Count);
ExpandAsync(FixedList);
}
@@ -313,19 +342,57 @@ namespace Ichni.Editor
{
if (!expand && isExpanded)
{
for (int i = childTabList.Count; i > 0; i--)
for (int i = childTabList.Count - 1; i >= 0; i--)
{
childTabList[i - 1].SetExpansion(expand); //false
if (childTabList[i] != null)
childTabList[i].SetExpansion(expand);
}
}
if (!expand)
{
parentTab.childTabList.Remove(this);
Destroy(gameObject);
EditorManager.instance.uiManager.hierarchy.tabList.Remove(this);
CleanupAndDespawn();
}
}
private void CleanupAndDespawn()
{
if (connectedGameElement != null)
{
// 如果该元素还在选中列表中,先移除(须在 connectedTab=null 之前执行)
if (isSelected)
{
var sel = EditorManager.instance.operationManager.currentSelectedElements;
sel.Remove(connectedGameElement);
isSelected = false;
}
connectedGameElement.connectedTab = null;
}
parentTab?.childTabList.Remove(this);
EditorManager.instance.uiManager.hierarchy.tabList.Remove(this);
transform.DOKill();
tabButton.onClick.RemoveAllListeners();
expandButton.onClick.RemoveAllListeners();
for (int i = indentationLines.Count - 1; i >= 0; i--)
{
if (indentationLines[i] != null)
Destroy(indentationLines[i]);
}
indentationLines.Clear();
connectedGameElement = null;
parentTab = null;
childTabList?.Clear();
isExpanded = false;
isExpandDone = true;
tabLayer = 0;
LeanPool.Despawn(gameObject);
}
private void ExpandAnim()
{
expandButton.transform.DORotate(new Vector3(0, 0, !isExpanded ? 0f : 180f), 0.2f);
@@ -341,12 +408,36 @@ namespace Ichni.Editor
{
var childElement = FixedList[index];
EditorManager.instance.uiManager.hierarchy.GenerateTab(childElement, connectedGameElement);
Debug.Log($"生成子Tab{childElement.elementName},索引:{index},总数:{FixedList.Count}");
// 如果处理时间超过帧时间限制,直接继续执行而不等待
// 移除了原来的 yield return null 等待逻辑
}
}
public IEnumerator ExpandSyncBatched()
{
connectedGameElement.ScanAndAddEnableTypes();
isExpanded = true;
isExpandDone = false;
ExpandAnim();
var children = connectedGameElement.childElementList;
int batchCount = 0;
for (int i = 0; i < children.Count; i++)
{
if (!isExpanded) break;
if (children[i].connectedTab == null)
{
EditorManager.instance.uiManager.hierarchy.GenerateTab(children[i], connectedGameElement, false);
batchCount++;
if (batchCount >= 15)
{
batchCount = 0;
yield return null;
if (!isExpanded) break;
}
}
}
isExpandDone = true;
}
async void ExpandAsync(List<GameElement> FixedList)
{
isExpandDone = false;
@@ -355,7 +446,6 @@ namespace Ichni.Editor
var childElement = FixedList[index];
await EditorManager.instance.uiManager.hierarchy.GenerateTabAsync(childElement, connectedGameElement);
Debug.Log($"生成子Tab{childElement.elementName},索引:{index},总数:{FixedList.Count}");
if (!isExpanded) break;
}