212 lines
7.7 KiB
C#
212 lines
7.7 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using DG.Tweening;
|
||
using Ichni.RhythmGame;
|
||
using Michsky.MUIP;
|
||
using Sirenix.Utilities;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.InputSystem;
|
||
using UnityEngine.Serialization;
|
||
using UnityEngine.UI;
|
||
|
||
namespace Ichni.Editor
|
||
{
|
||
public partial class HierarchyTab : MonoBehaviour
|
||
{
|
||
public GameObject indentationLinePrefab;
|
||
|
||
public GameElement connectedGameElement;
|
||
public HierarchyTab parentTab;
|
||
public List<HierarchyTab> childTabList;
|
||
|
||
public int tabLayer;
|
||
public bool isSelected;
|
||
public bool isExpanded;
|
||
public Image BgImage;
|
||
public RectTransform tabRect;
|
||
public LayoutElement layoutElement;
|
||
public RectTransform tabMainRect;
|
||
public Button tabButton;
|
||
public Button expandButton;
|
||
public DoubleCheckButton deleteButton;
|
||
public TMP_Text tabButtonText;
|
||
|
||
public void SetTab(GameElement targetElement, GameElement parentElement)
|
||
{
|
||
tabMainRect.localScale = Vector3.zero;
|
||
StartCoroutine(WindowAnim.ShowPanelOnScale(tabMainRect.gameObject));
|
||
|
||
connectedGameElement = targetElement;
|
||
tabButtonText.text = targetElement.elementName;
|
||
targetElement.connectedTab = this;
|
||
this.isExpanded = false;
|
||
this.isSelected = false;
|
||
this.childTabList = new List<HierarchyTab>();
|
||
|
||
if (parentElement == null)
|
||
{
|
||
this.tabLayer = 0;
|
||
this.parentTab = null;
|
||
this.transform.SetAsLastSibling();
|
||
}
|
||
else
|
||
{
|
||
this.parentTab = parentElement.connectedTab;
|
||
parentElement.connectedTab.childTabList.Add(this);
|
||
this.tabLayer = this.parentTab.tabLayer + 1;
|
||
this.transform.SetSiblingIndex(this.parentTab.transform.GetSiblingIndex() + GetAllChildrenCount(this.parentTab));
|
||
|
||
if (!this.parentTab.isExpanded)
|
||
{
|
||
this.isExpanded = false;
|
||
SetExpansion(false);
|
||
}
|
||
|
||
for (int i = 1; i <= this.tabLayer; i++)
|
||
{
|
||
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();
|
||
}
|
||
|
||
|
||
float posX = (30 * tabLayer);
|
||
tabMainRect.anchoredPosition = new Vector2(posX, tabMainRect.anchoredPosition.y);
|
||
tabButton.onClick.AddListener(SelectGameElement);
|
||
expandButton.onClick.AddListener(ExpandOrFold);
|
||
deleteButton.onConfirm = () => EditorManager.instance.operationManager.CopyPasteDeleteModule.DeleteElement(connectedGameElement);
|
||
|
||
SetStatus();
|
||
}
|
||
public void SetStatus()
|
||
{
|
||
expandButton.gameObject.SetActive(!connectedGameElement.childElementList.IsNullOrEmpty());
|
||
|
||
}
|
||
}
|
||
|
||
public partial class HierarchyTab
|
||
{
|
||
private int GetAllChildrenCount(HierarchyTab tab)
|
||
{
|
||
int c = tab.childTabList.Count;
|
||
|
||
for (int i = 0; i < tab.childTabList.Count; i++)
|
||
{
|
||
c += GetAllChildrenCount(tab.childTabList[i]);
|
||
}
|
||
|
||
return c;
|
||
}
|
||
public void ExecuteOrSelect()
|
||
{
|
||
if (EditorManager.instance.uiManager.hierarchy.NeedExecute)
|
||
{
|
||
EditorManager.instance.uiManager.hierarchy.upLoadElement = connectedGameElement;
|
||
}
|
||
else
|
||
{
|
||
SelectGameElement();
|
||
}
|
||
}
|
||
|
||
public void SelectGameElement()
|
||
{
|
||
if (Keyboard.current.leftCtrlKey.isPressed)
|
||
{
|
||
if (!isSelected)
|
||
{
|
||
EditorManager.instance.operationManager.AddSelectElement(connectedGameElement);
|
||
}
|
||
else
|
||
{
|
||
EditorManager.instance.operationManager.RemoveSelectElement(connectedGameElement);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
EditorManager.instance.operationManager.ClearSelectedElements();
|
||
EditorManager.instance.operationManager.AddSelectElement(connectedGameElement);
|
||
}
|
||
|
||
EditorManager.instance.uiManager.inspector.SetInspector(connectedGameElement);
|
||
EditorManager.instance.timeline.SetTimeLine(connectedGameElement);
|
||
}
|
||
public IEnumerator ienumerator = null;
|
||
public void ExpandOrFold()
|
||
{
|
||
ExpandOrFold(false);
|
||
}
|
||
public void ExpandOrFold(bool forceAllExPand = false)
|
||
{
|
||
this.childTabList.RemoveAll(s => s == null);
|
||
isExpanded = !isExpanded;
|
||
ExpandAnim();
|
||
if (isExpanded)
|
||
{
|
||
connectedGameElement.ScanAndAddEnableTypes();
|
||
List<GameElement> FixedList = !forceAllExPand ? connectedGameElement.GetChildrenByTypes() : connectedGameElement.childElementList;
|
||
|
||
// float startTime = Time.realtimeSinceStartup;
|
||
// connectedGameElement.childElementList.Sort();//TODO: 后续可以让玩家手动快速排序
|
||
Debug.Log(FixedList.Count);
|
||
ienumerator = ExpandOverTime(FixedList);
|
||
StartCoroutine(ienumerator);
|
||
|
||
}
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void SetExpansion(bool expand)
|
||
{
|
||
if (!expand && isExpanded)
|
||
{
|
||
for (int i = childTabList.Count; i > 0; i--)
|
||
{
|
||
childTabList[i - 1].SetExpansion(expand); //false
|
||
}
|
||
}
|
||
|
||
if (!expand)
|
||
{
|
||
parentTab.childTabList.Remove(this);
|
||
Destroy(gameObject);
|
||
EditorManager.instance.uiManager.hierarchy.tabList.Remove(this);
|
||
}
|
||
}
|
||
private void ExpandAnim()
|
||
{
|
||
expandButton.transform.DORotate(new Vector3(0, 0, !isExpanded ? 0f : 180f), 0.2f);
|
||
}
|
||
private IEnumerator ExpandOverTime(List<GameElement> FixedList)//帧率过低的时候等一下再实例化
|
||
{
|
||
float StrandTimeWhileStartUp = EditorManager.instance.CurrentFrameRate;
|
||
float startTime = Time.realtimeSinceStartup;
|
||
for (var index = 0; index < FixedList.Count; index++)
|
||
{
|
||
int hasYield = 0;
|
||
while (Time.realtimeSinceStartup - startTime > 1f / StrandTimeWhileStartUp * 3f && hasYield <= 2)
|
||
{
|
||
yield return null;
|
||
hasYield += 1;
|
||
}
|
||
var childElement = FixedList[index];
|
||
EditorManager.instance.uiManager.hierarchy.GenerateTab(childElement, connectedGameElement);
|
||
print($"生成子Tab:{childElement.elementName},索引:{index},总数:{FixedList.Count}");
|
||
}
|
||
}
|
||
}
|
||
} |