优化hierarchy

即时生成和删除tab(不会做动态刷新
基本上hierarchy的性能就到这了,之后还是做点辅助工具防止1000+的栏展开吧
(重要)bug测试不完全,需要再加改进
This commit is contained in:
2025-02-12 01:57:18 +08:00
parent 30653e133b
commit 1b3c3556a1
8 changed files with 72 additions and 36 deletions

View File

@@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using Ichni.RhythmGame;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
@@ -8,16 +9,24 @@ namespace Ichni.Editor
{
public class Hierarchy : StaticWindow
{
public GameObject Nouse;
public GameObject hierarchyTabPrefab;
public RectTransform tabContainer;
public List<HierarchyTab> tabList;
//public int ID=0;
public void GenerateTab(GameElement targetElement, GameElement parentElement)
public HierarchyTab GenerateTab(GameElement targetElement, GameElement parentElement,int reuse=-1)
{
HierarchyTab tab = Instantiate(hierarchyTabPrefab, tabContainer).GetComponent<HierarchyTab>();
HierarchyTab tab =Instantiate(hierarchyTabPrefab, tabContainer).GetComponent<HierarchyTab>();;
//if(parentElement.connectedTab!=null)tab.transform.SetSiblingIndex(parentElement.connectedTab.transform.GetSiblingIndex());
tab.SetTab(targetElement, parentElement);
tabList.Add(tab);
tab.hierarchy=this;
return tab;
}

View File

@@ -14,7 +14,8 @@ namespace Ichni.Editor
public GameElement connectedGameElement;
public HierarchyTab parentTab;
public List<HierarchyTab> childTabList;
public List<int> IDqueue;
public int tabLayer;
public bool isSelected;
public bool isExpanded;
@@ -26,10 +27,12 @@ namespace Ichni.Editor
public Button expandButton;
public Button gotoButton;
public TMP_Text tabButtonText;
public Hierarchy hierarchy;
public void SetTab(GameElement targetElement, GameElement parentElement)
{
connectedGameElement=targetElement;
tabButtonText.text = targetElement.elementName;
targetElement.connectedTab = this;
this.isExpanded = false;
@@ -41,15 +44,15 @@ namespace Ichni.Editor
this.tabLayer = 0;
this.parentTab = null;
this.transform.SetAsLastSibling();
}
else
{
}else{
this.parentTab = parentElement.connectedTab;
parentElement.connectedTab.childTabList.Add(this);
this.tabLayer = this.parentTab.tabLayer + 1;
this.parentTab.childTabList.Add(this);
this.transform.SetSiblingIndex(this.parentTab.transform.GetSiblingIndex() +
GetAllChildrenCount(this.parentTab));
this.parentTab.connectedGameElement.childElementList.Count);
if (!this.parentTab.isExpanded)
{
@@ -59,12 +62,13 @@ namespace Ichni.Editor
for (int i = 1; i <= this.tabLayer; i++)
{
float lineX = 10 * i;
float lineX = 30 * i;
Instantiate(indentationLinePrefab, tabRect).GetComponent<RectTransform>().anchoredPosition = new Vector2(lineX, 0);
}
}
float posX = -25 + 10 * tabLayer;
float posX = -5 + 30 * tabLayer;
tabMainRect.anchoredPosition = new Vector2(posX, tabMainRect.anchoredPosition.y);
expandButton.onClick.AddListener(ExpandOrFold);
@@ -88,38 +92,44 @@ namespace Ichni.Editor
private void ExpandOrFold()
{
this.childTabList.RemoveAll(s => s == null);
bool op = !isExpanded;
isExpanded=!isExpanded;
for (int i = 0; i < childTabList.Count; i++)
{
childTabList[i].SetExpansion(op);
if(isExpanded){
expandButton.transform.Rotate(new Vector3(0,0,180));
foreach(GameElement i in connectedGameElement.childElementList){
HierarchyTab a=hierarchy.GenerateTab(i,connectedGameElement);
childTabList.Add(a);
}
}else{
expandButton.transform.Rotate(new Vector3(0,0,180));
for (int i = childTabList.Count-1; i>=0; i--)
{
childTabList[i].SetExpansion(isExpanded);
}
}
isExpanded = op;
}
private void SetExpansion(bool expand)
{
if (!(expand == true && isExpanded == false))
if (!expand&&isExpanded)
{
foreach (var tab in childTabList)
{
tab.SetExpansion(expand);
tab.SetExpansion(expand);//false
}
}
if (expand)
if (!expand)
{
gameObject.SetActive(true);
tabRect.localScale = Vector3.one;
layoutElement.ignoreLayout = false;
}
else
{
tabRect.localScale = Vector3.zero;
layoutElement.ignoreLayout = true;
gameObject.SetActive(false);
parentTab.childTabList.Remove(this);
Destroy(gameObject);
}
}
}
}

View File

@@ -58,7 +58,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Color: {r: 0.6415094, g: 0.6415094, b: 0.6415094, a: 0.39215687}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1