@@ -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);//合上再展开,这思路也是没谁了
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user