2021-04-26 19:56:21 +10:00
|
|
|
|
using System;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
using System.Collections;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityExplorer.UI.ObjectPool;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
using UnityExplorer.UI.Panels;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
using UnityExplorer.UI.Utility;
|
|
|
|
|
using UnityExplorer.UI.Widgets;
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.UI.Inspectors
|
|
|
|
|
{
|
|
|
|
|
public class GameObjectInspector : InspectorBase
|
|
|
|
|
{
|
2021-05-03 01:29:02 +10:00
|
|
|
|
//public GameObject Target;
|
|
|
|
|
public GameObject GOTarget => Target as GameObject;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
|
|
|
|
private Text NameText;
|
|
|
|
|
|
|
|
|
|
public TransformTree TransformTree;
|
|
|
|
|
private ScrollPool<TransformCell> transformScroll;
|
|
|
|
|
|
|
|
|
|
public ButtonListSource<Component> ComponentList;
|
|
|
|
|
private ScrollPool<ButtonCell> componentScroll;
|
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
private readonly List<GameObject> _rootEntries = new List<GameObject>();
|
|
|
|
|
|
|
|
|
|
public override void OnBorrowedFromPool(object target)
|
2021-04-26 19:56:21 +10:00
|
|
|
|
{
|
2021-04-27 21:22:48 +10:00
|
|
|
|
base.OnBorrowedFromPool(target);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
Target = target as GameObject;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
NameText.text = GOTarget.name;
|
|
|
|
|
Tab.TabText.text = $"[G] {GOTarget.name}";
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
RuntimeProvider.Instance.StartCoroutine(InitCoroutine());
|
|
|
|
|
}
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
private IEnumerator InitCoroutine()
|
|
|
|
|
{
|
|
|
|
|
yield return null;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(InspectorPanel.Instance.ContentRect);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
TransformTree.Rebuild();
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-04-30 23:12:18 +10:00
|
|
|
|
ComponentList.ScrollPool.Refresh(true, true);
|
2021-04-27 21:22:48 +10:00
|
|
|
|
UpdateComponents();
|
2021-04-26 19:56:21 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
public override void OnReturnToPool()
|
|
|
|
|
{
|
|
|
|
|
base.OnReturnToPool();
|
|
|
|
|
|
2021-04-30 23:12:18 +10:00
|
|
|
|
//// release component and transform lists
|
|
|
|
|
//this.TransformTree.ScrollPool.ReleaseCells();
|
|
|
|
|
//this.TransformTree.ScrollPool.SetUninitialized();
|
|
|
|
|
//
|
|
|
|
|
//this.ComponentList.ScrollPool.ReleaseCells();
|
|
|
|
|
//this.ComponentList.ScrollPool.SetUninitialized();
|
2021-04-27 21:22:48 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private float timeOfLastUpdate;
|
|
|
|
|
|
|
|
|
|
public override void Update()
|
|
|
|
|
{
|
|
|
|
|
if (!this.IsActive)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (Target.IsNullOrDestroyed(false))
|
|
|
|
|
{
|
|
|
|
|
InspectorManager.ReleaseInspector(this);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-03 21:02:01 +10:00
|
|
|
|
if (timeOfLastUpdate.OccuredEarlierThan(1))
|
2021-04-27 21:22:48 +10:00
|
|
|
|
{
|
2021-05-03 21:02:01 +10:00
|
|
|
|
timeOfLastUpdate = Time.realtimeSinceStartup;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
|
|
|
|
|
// Refresh children and components
|
|
|
|
|
TransformTree.RefreshData(true, false);
|
|
|
|
|
|
|
|
|
|
UpdateComponents();
|
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
Tab.TabText.text = $"[G] {GOTarget.name}";
|
2021-04-27 21:22:48 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
|
|
|
|
private IEnumerable<GameObject> GetTransformEntries()
|
|
|
|
|
{
|
|
|
|
|
_rootEntries.Clear();
|
2021-05-03 01:29:02 +10:00
|
|
|
|
for (int i = 0; i < GOTarget.transform.childCount; i++)
|
|
|
|
|
_rootEntries.Add(GOTarget.transform.GetChild(i).gameObject);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
return _rootEntries;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly List<Component> _componentEntries = new List<Component>();
|
|
|
|
|
|
|
|
|
|
private List<Component> GetComponentEntries()
|
|
|
|
|
{
|
|
|
|
|
return _componentEntries;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
private static readonly Dictionary<string, string> compToStringCache = new Dictionary<string, string>();
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
|
|
|
|
private void SetComponentCell(ButtonCell cell, int index)
|
|
|
|
|
{
|
|
|
|
|
if (index < 0 || index >= _componentEntries.Count)
|
2021-04-27 21:22:48 +10:00
|
|
|
|
{
|
2021-04-26 19:56:21 +10:00
|
|
|
|
cell.Disable();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cell.Enable();
|
|
|
|
|
|
|
|
|
|
var comp = _componentEntries[index];
|
|
|
|
|
var type = comp.GetActualType();
|
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
if (!compToStringCache.ContainsKey(type.AssemblyQualifiedName))
|
2021-04-26 19:56:21 +10:00
|
|
|
|
{
|
2021-05-01 20:55:27 +10:00
|
|
|
|
compToStringCache.Add(type.AssemblyQualifiedName, SignatureHighlighter.ParseFullType(type, true));
|
2021-04-26 19:56:21 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
cell.Button.ButtonText.text = compToStringCache[type.AssemblyQualifiedName];
|
2021-04-26 19:56:21 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ShouldDisplay(Component comp, string filter) => true;
|
|
|
|
|
|
|
|
|
|
private void OnComponentClicked(int index)
|
|
|
|
|
{
|
|
|
|
|
if (index < 0 || index >= _componentEntries.Count)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var comp = _componentEntries[index];
|
|
|
|
|
if (comp)
|
|
|
|
|
InspectorManager.Inspect(comp);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
private void UpdateComponents()
|
2021-04-26 19:56:21 +10:00
|
|
|
|
{
|
2021-04-27 21:22:48 +10:00
|
|
|
|
_componentEntries.Clear();
|
2021-05-03 01:29:02 +10:00
|
|
|
|
var comps = GOTarget.GetComponents<Component>();
|
2021-04-27 21:22:48 +10:00
|
|
|
|
foreach (var comp in comps)
|
|
|
|
|
_componentEntries.Add(comp);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
ComponentList.RefreshData();
|
2021-04-30 23:12:18 +10:00
|
|
|
|
ComponentList.ScrollPool.Refresh(true);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
protected override void OnCloseClicked()
|
2021-04-26 19:56:21 +10:00
|
|
|
|
{
|
2021-04-27 21:22:48 +10:00
|
|
|
|
InspectorManager.ReleaseInspector(this);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
public override GameObject CreateContent(GameObject parent)
|
2021-04-26 19:56:21 +10:00
|
|
|
|
{
|
2021-05-01 20:55:27 +10:00
|
|
|
|
UIRoot = UIFactory.CreateVerticalGroup(Pool<GameObjectInspector>.Instance.InactiveHolder,
|
2021-04-27 21:22:48 +10:00
|
|
|
|
"GameObjectInspector", true, true, true, true, 5, new Vector4(4, 4, 4, 4), new Color(0.12f, 0.12f, 0.12f));
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
NameText = UIFactory.CreateLabel(UIRoot, "Title", "not set", TextAnchor.MiddleLeft, fontSize: 20);
|
2021-04-27 21:22:48 +10:00
|
|
|
|
UIFactory.SetLayoutElement(NameText.gameObject, minHeight: 30, flexibleHeight: 0);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
var listHolder = UIFactory.CreateHorizontalGroup(UIRoot, "ListHolder", true, true, true, true, 5, new Vector4(2, 2, 2, 2));
|
2021-04-27 21:22:48 +10:00
|
|
|
|
UIFactory.SetLayoutElement(listHolder, flexibleWidth: 9999, flexibleHeight: 9999);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
transformScroll = UIFactory.CreateScrollPool<TransformCell>(listHolder, "TransformTree", out GameObject transformObj,
|
|
|
|
|
out GameObject transformContent, new Color(0.11f, 0.11f, 0.11f));
|
|
|
|
|
UIFactory.SetLayoutElement(transformObj, flexibleHeight: 9999);
|
|
|
|
|
UIFactory.SetLayoutElement(transformContent, flexibleHeight: 9999);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
componentScroll = UIFactory.CreateScrollPool<ButtonCell>(listHolder, "ComponentList", out GameObject compObj,
|
|
|
|
|
out GameObject compContent, new Color(0.11f, 0.11f, 0.11f));
|
|
|
|
|
UIFactory.SetLayoutElement(compObj, flexibleHeight: 9999);
|
|
|
|
|
UIFactory.SetLayoutElement(compContent, flexibleHeight: 9999);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
TransformTree = new TransformTree(transformScroll) { GetRootEntriesMethod = GetTransformEntries };
|
|
|
|
|
TransformTree.Init();
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
ComponentList = new ButtonListSource<Component>(componentScroll, GetComponentEntries, SetComponentCell, ShouldDisplay, OnComponentClicked);
|
|
|
|
|
componentScroll.Initialize(ComponentList);
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
return UIRoot;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|