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 GOTarget => Target as GameObject;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-05-15 20:39:56 +10:00
|
|
|
|
// Top info
|
|
|
|
|
|
|
|
|
|
private InputFieldRef NameInput;
|
|
|
|
|
private GameObject PathRow;
|
|
|
|
|
private InputFieldRef PathInput;
|
|
|
|
|
|
|
|
|
|
// Child and comp lists
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
|
|
|
|
public TransformTree TransformTree;
|
|
|
|
|
private ScrollPool<TransformCell> transformScroll;
|
2021-05-13 00:58:23 +10:00
|
|
|
|
private readonly List<GameObject> cachedChildren = new List<GameObject>();
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
|
|
|
|
public ButtonListSource<Component> ComponentList;
|
|
|
|
|
private ScrollPool<ButtonCell> componentScroll;
|
|
|
|
|
|
2021-04-27 21:22:48 +10:00
|
|
|
|
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-05-03 01:29:02 +10:00
|
|
|
|
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-05-13 00:58:23 +10:00
|
|
|
|
}
|
|
|
|
|
protected override void OnCloseClicked()
|
|
|
|
|
{
|
|
|
|
|
InspectorManager.ReleaseInspector(this);
|
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
|
|
|
|
|
2021-05-13 00:58:23 +10:00
|
|
|
|
private void RefreshTopInfo()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Transform and Component Lists
|
|
|
|
|
|
2021-04-26 19:56:21 +10:00
|
|
|
|
private IEnumerable<GameObject> GetTransformEntries()
|
|
|
|
|
{
|
2021-05-13 00:58:23 +10:00
|
|
|
|
cachedChildren.Clear();
|
2021-05-03 01:29:02 +10:00
|
|
|
|
for (int i = 0; i < GOTarget.transform.childCount; i++)
|
2021-05-13 00:58:23 +10:00
|
|
|
|
cachedChildren.Add(GOTarget.transform.GetChild(i).gameObject);
|
|
|
|
|
return cachedChildren;
|
2021-04-26 19:56:21 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly List<Component> _componentEntries = new List<Component>();
|
2021-05-04 20:39:54 +10:00
|
|
|
|
private readonly HashSet<int> _compInstanceIDs = new HashSet<int>();
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
|
|
|
|
private List<Component> GetComponentEntries()
|
|
|
|
|
{
|
|
|
|
|
return _componentEntries;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-04 20:39:54 +10:00
|
|
|
|
private void UpdateComponents()
|
|
|
|
|
{
|
|
|
|
|
// Check if we actually need to refresh the component cells or not.
|
|
|
|
|
// Doing this check is far more efficient than blindly setting cells.
|
|
|
|
|
|
|
|
|
|
var comps = GOTarget.GetComponents<Component>();
|
|
|
|
|
|
|
|
|
|
bool needRefresh = false;
|
|
|
|
|
if (comps.Length != _componentEntries.Count)
|
|
|
|
|
needRefresh = true;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var comp in comps)
|
|
|
|
|
{
|
|
|
|
|
if (!_compInstanceIDs.Contains(comp.GetInstanceID()))
|
|
|
|
|
{
|
|
|
|
|
needRefresh = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!needRefresh)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_componentEntries.Clear();
|
|
|
|
|
_compInstanceIDs.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (var comp in comps)
|
|
|
|
|
{
|
|
|
|
|
_componentEntries.Add(comp);
|
|
|
|
|
_compInstanceIDs.Add(comp.GetInstanceID());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ComponentList.RefreshData();
|
|
|
|
|
ComponentList.ScrollPool.Refresh(true);
|
|
|
|
|
}
|
|
|
|
|
|
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-06 04:02:42 +10:00
|
|
|
|
compToStringCache.Add(type.AssemblyQualifiedName, SignatureHighlighter.Parse(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-05-13 00:58:23 +10:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region UI Construction
|
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-15 20:39:56 +10:00
|
|
|
|
// Title row
|
|
|
|
|
|
|
|
|
|
var titleRow = UIFactory.CreateUIObject("TitleRow", UIRoot);
|
|
|
|
|
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(titleRow, false, false, true, true, 5);
|
|
|
|
|
|
|
|
|
|
var titleLabel = UIFactory.CreateLabel(titleRow, "Title", SignatureHighlighter.Parse(typeof(GameObject), true),
|
|
|
|
|
TextAnchor.MiddleLeft, fontSize: 17);
|
|
|
|
|
UIFactory.SetLayoutElement(titleLabel.gameObject, minHeight: 30, flexibleHeight: 0, flexibleWidth: 9999);
|
|
|
|
|
|
|
|
|
|
// Update button
|
|
|
|
|
var updateBtn = UIFactory.CreateButton(titleRow, "UpdateButton", "Update Info", new Color(0.2f, 0.3f, 0.2f));
|
|
|
|
|
UIFactory.SetLayoutElement(updateBtn.Component.gameObject, minHeight: 25, minWidth: 200);
|
|
|
|
|
updateBtn.OnClick += () => { ExplorerCore.Log("TODO!"); };
|
|
|
|
|
|
|
|
|
|
// ~~~~~~ Top info ~~~~~~
|
|
|
|
|
|
|
|
|
|
// parent / path row
|
|
|
|
|
|
|
|
|
|
this.PathRow = UIFactory.CreateUIObject("ParentRow", UIRoot);
|
|
|
|
|
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(this.PathRow, false, false, true, true, 5, 2, 2, 2, 2);
|
|
|
|
|
UIFactory.SetLayoutElement(this.PathRow, minHeight: 25, flexibleHeight: 100, flexibleWidth: 9999);
|
|
|
|
|
|
|
|
|
|
var viewParentButton = UIFactory.CreateButton(PathRow, "ViewParentButton", "View Parent", new Color(0.3f, 0.3f, 0.3f));
|
|
|
|
|
UIFactory.SetLayoutElement(viewParentButton.Component.gameObject, minHeight: 25, minWidth: 80);
|
|
|
|
|
viewParentButton.OnClick += () => { ExplorerCore.LogWarning("TODO!"); };
|
|
|
|
|
|
|
|
|
|
this.PathInput = UIFactory.CreateInputField(PathRow, "PathInput", "No parent (root object)");
|
|
|
|
|
UIFactory.SetLayoutElement(PathInput.UIRoot, minHeight: 25, minWidth: 100, flexibleWidth: 9999);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ~~~~~~ Child and comp lists ~~~~~~
|
2021-04-26 19:56:21 +10:00
|
|
|
|
|
2021-05-15 20:39:56 +10:00
|
|
|
|
var listTitles = UIFactory.CreateUIObject("ListTitles", UIRoot);
|
|
|
|
|
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(listTitles, true, true, true, true, 5, 2, 2, 2, 2);
|
|
|
|
|
UIFactory.SetLayoutElement(listTitles, flexibleWidth: 9999, flexibleHeight: 30);
|
|
|
|
|
UIFactory.CreateLabel(listTitles, "ChildListTitle", "Children", TextAnchor.MiddleCenter, default, false, 15);
|
|
|
|
|
UIFactory.CreateLabel(listTitles, "CompListTitle", "Components", TextAnchor.MiddleCenter, default, false, 15);
|
|
|
|
|
|
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
|
|
|
|
}
|
2021-05-13 00:58:23 +10:00
|
|
|
|
|
|
|
|
|
#endregion
|
2021-04-26 19:56:21 +10:00
|
|
|
|
}
|
|
|
|
|
}
|