大幅优化

Signed-off-by: TRAfoer <lhf190@outlook.com>
This commit is contained in:
2025-10-05 11:45:32 +08:00
parent e145d65d38
commit 725009e354
66 changed files with 616229 additions and 175087 deletions

View File

@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using DG.Tweening;
using Ichni.RhythmGame;
using Michsky.MUIP;
@@ -35,9 +36,8 @@ namespace Ichni.Editor
public void SetTab(GameElement targetElement, GameElement parentElement)
{
tabMainRect.localScale = Vector3.zero;
StartCoroutine(WindowAnim.ShowPanelOnScale(tabMainRect.gameObject));
transform.localScale = Vector3.one;
transform.DOScale(Vector3.one, 0.2f).SetEase(Ease.OutCirc).From(new Vector3(1, 0, 1));
connectedGameElement = targetElement;
tabButtonText.text = targetElement.elementName;
targetElement.connectedTab = this;
@@ -69,7 +69,6 @@ namespace Ichni.Editor
float lineX = 30 * i - 15;
var d = Instantiate(indentationLinePrefab, tabRect);
d.GetComponent<RectTransform>().anchoredPosition = new Vector2(lineX, 0);
StartCoroutine(WindowAnim.ShowPanelOnScale(d.gameObject));
}
parentTab.SetStatus();
}
@@ -82,7 +81,13 @@ namespace Ichni.Editor
deleteButton.onConfirm = () => EditorManager.instance.operationManager.CopyPasteDeleteModule.DeleteElement(connectedGameElement);
SetStatus();
}
private void OnDestroy()
{
transform.DOKill();
}
public void SetStatus()
{
expandButton.gameObject.SetActive(!connectedGameElement.childElementList.IsNullOrEmpty());
@@ -155,7 +160,6 @@ namespace Ichni.Editor
EditorManager.instance.uiManager.inspector.SetInspector(connectedGameElement);
}
public IEnumerator ienumerator = null;
public void ExpandOrFold()
{
ExpandOrFold(false);
@@ -173,15 +177,12 @@ namespace Ichni.Editor
// float startTime = Time.realtimeSinceStartup;
// connectedGameElement.childElementList.Sort();//TODO: 后续可以让玩家手动快速排序
Debug.Log(FixedList.Count);
ienumerator = ExpandOverTime(FixedList);
StartCoroutine(ienumerator);
ExpandAsync(FixedList);
}
else
{
//expandButton.transform.Rotate(new Vector3(0, 0, 180));
StopCoroutine(ienumerator);
ienumerator = null;
for (int i = childTabList.Count - 1; i >= 0; i--)
{
childTabList[i].SetExpansion(isExpanded);
@@ -210,22 +211,37 @@ namespace Ichni.Editor
{
expandButton.transform.DORotate(new Vector3(0, 0, !isExpanded ? 0f : 180f), 0.2f);
}
private IEnumerator ExpandOverTime(List<GameElement> FixedList)//帧率过低的时候等一下再实例化
public bool isExpandDone = true;
private void ExpandImmediately(List<GameElement> FixedList)
{
float StrandTimeWhileStartUp = EditorManager.instance.CurrentFrameRate;
float startTime = Time.realtimeSinceStartup;
float frameTime = 1f / StrandTimeWhileStartUp * 3f;
for (var index = 0; index < FixedList.Count; index++)
{
int hasYield = 0;
while (Time.realtimeSinceStartup - startTime > 1f / StrandTimeWhileStartUp * 3f && hasYield <= 1)
{
yield return null;
hasYield += 1;
}
var childElement = FixedList[index];
EditorManager.instance.uiManager.hierarchy.GenerateTab(childElement, connectedGameElement);
print($"生成子Tab{childElement.elementName},索引:{index},总数:{FixedList.Count}");
Debug.Log($"生成子Tab{childElement.elementName},索引:{index},总数:{FixedList.Count}");
// 如果处理时间超过帧时间限制,直接继续执行而不等待
// 移除了原来的 yield return null 等待逻辑
}
}
async void ExpandAsync(List<GameElement> FixedList)
{
isExpandDone = false;
for (var index = 0; index < FixedList.Count; index++)
{
var childElement = FixedList[index];
await EditorManager.instance.uiManager.hierarchy.GenerateTabAsync(childElement, connectedGameElement);
Debug.Log($"生成子Tab{childElement.elementName},索引:{index},总数:{FixedList.Count}");
if (!isExpanded) break;
}
isExpandDone = true;
}
}
}