大幅优化

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,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using DG.Tweening;
using Ichni.RhythmGame;
using Unity.VisualScripting;
@@ -35,6 +36,21 @@ namespace Ichni.Editor
tabList.Add(tab);
return tab;
}
public async Task<HierarchyTab> GenerateTabAsync(GameElement targetElement, GameElement parentElement)
{
var request = InstantiateAsync(hierarchyTabPrefab, tabContainer);
// 等待实例化过程完成
while (!request.isDone)
{
await Task.Yield(); // 异步地等待下一帧
}
HierarchyTab tab = request.Result[0].GetComponent<HierarchyTab>();
tab.SetTab(targetElement, parentElement);
tabList.Add(tab);
// 返回实例化的游戏对象
return tab;
}
public bool isExpand = false;
private RectTransform rectTransform;
public void Expand()
@@ -127,7 +143,7 @@ namespace Ichni.Editor
{
elem.parentElement.connectedTab.ExpandOrFold(true);
}
else if (elem.parentElement.connectedTab.ienumerator is null)
else if (!elem.parentElement.connectedTab.isExpandDone)
{
elem.parentElement.connectedTab.ExpandOrFold();
elem.parentElement.connectedTab.ExpandOrFold(true);//合上再展开,这思路也是没谁了

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;
}
}
}

View File

@@ -17,7 +17,7 @@ namespace Ichni.Editor
public UnityAction onCloseWindow;
public UnityAction onQuit;
protected void InitializeWindow(string titleText, UnityAction closeAction = null)
protected void InitializeWindow(string titleText, UnityAction closeAction = null, Vector3 targetScale = default)
{
title.text = titleText;
onCloseWindow = closeAction;
@@ -30,7 +30,7 @@ namespace Ichni.Editor
Destroy(gameObject);
});
});
StartCoroutine(WindowAnim.ShowPanelOnScale(gameObject));
this.transform.DOScale(targetScale == default ? Vector3.one : targetScale, 0.2f).SetEase(Ease.OutBack).From(Vector3.zero);
}
}
}

View File

@@ -13,7 +13,23 @@ namespace Ichni.Editor
public TMP_Text intervalUnitText;
public float time;
public int index;
public bool isInScreen
{
get => _isInScreen;
set
{
_isInScreen = value;
if (_isInScreen)
{
transform.localScale = Vector3.one;
}
else
{
transform.localScale = Vector3.zero;
}
}
}
private bool _isInScreen = false;
// [Title("poss")]
// public Vector3 position;

View File

@@ -16,7 +16,7 @@ namespace Ichni.Editor
public GameObject timePointerPrefab;
public List<TimePointer> timePointerList;
public List<TimePointer> ActivePointer => timePointerList.FindAll(pointer => pointer.gameObject.activeSelf);
public List<TimePointer> ActivePointer => timePointerList.FindAll(pointer => pointer.isInScreen);
private TimePointer NowPointer;
public RectTransform moveTabPoint;
@@ -45,7 +45,6 @@ namespace Ichni.Editor
timePointer.intervalUnitText.text = (i * timeline.timePerBeat).ToString("F3");
timePointer.GetComponent<RectTransform>().localPosition = new Vector3(i * timePointerInterval, 0f, 0f);
timePointer.index = i;
timePointer.gameObject.SetActive(false);
}
// for (int i = -1; i > -songInformation.delay / timeline.timePerBeat; i--)
// {
@@ -77,21 +76,22 @@ namespace Ichni.Editor
{
while (NowPointer.index < timePointerList.Count - 1 && NowPointer.index * timeline.timePerBeat < EditorManager.instance.songInformation.songTime)
{
NowPointer.gameObject.SetActive(false);
NowPointer.isInScreen = false;
NowPointer = timePointerList[NowPointer.index + 1];
}
while (NowPointer.index > 0 && NowPointer.index * timeline.timePerBeat >= EditorManager.instance.songInformation.songTime)
{
NowPointer.gameObject.SetActive(true);
NowPointer.isInScreen = true;
NowPointer = timePointerList[NowPointer.index - 1 >= 0 ? NowPointer.index - 1 : 0];
}
}
for (int i = NowPointer.index + 1; i < timePointerList.Count; i++)
{
timePointerList[i].gameObject.SetActive(true);
timePointerList[i].isInScreen = true;
if (timePointerList[i].GetComponent<RectTransform>().position.x > rightSide.position.x)
{
timePointerList[i].gameObject.SetActive(false);
timePointerList[i].isInScreen = false;
break;
}
}

View File

@@ -6,43 +6,7 @@ using UnityEngine;
public static class WindowAnim
{
public static IEnumerator ShowPanelOnScale(GameObject gameObject)
{
AnimationCurve animationCurve = new AnimationCurve(
new Keyframe(0, 0),
new Keyframe(0.25f, 0.55f),
new Keyframe(0.5f, 0.85f),
new Keyframe(0.75f, 0.97f),
new Keyframe(1, 1)
);
float timer = 0;
while (timer <= 1)
{
gameObject.transform.localScale = Vector3.one * animationCurve.Evaluate(timer);
timer += Time.deltaTime * 5f;
yield return null;
}
gameObject.transform.localScale = Vector3.one;
}
public static IEnumerator HidePanelOnscale(GameObject gameObject, bool DestoryOrNot = false)
{
AnimationCurve animationCurve = new AnimationCurve(
new Keyframe(0, 0),
new Keyframe(0.25f, 0.55f),
new Keyframe(0.5f, 0.85f),
new Keyframe(0.75f, 0.97f),
new Keyframe(1, 1)
);
float timer = 1;
while (timer >= 0)
{
gameObject.transform.localScale = Vector3.one * animationCurve.Evaluate(timer);
timer += Time.deltaTime * 5f;
yield return null;
}
gameObject.transform.localScale = Vector3.zero;
}
public static IEnumerator Shake(GameObject gameObject)
{
float timer = 0f;