mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-16 00:07:52 +08:00
Some progress on inspector rewrites, most of the framework figured out now.
This commit is contained in:
@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI.ObjectPool;
|
||||
using UnityExplorer.UI.Panels;
|
||||
using UnityExplorer.UI.Utility;
|
||||
using UnityExplorer.UI.Widgets;
|
||||
|
||||
@ -25,6 +27,137 @@ namespace UnityExplorer.UI.Inspectors
|
||||
public ButtonListSource<Component> ComponentList;
|
||||
private ScrollPool<ButtonCell> componentScroll;
|
||||
|
||||
private readonly List<GameObject> _rootEntries = new List<GameObject>();
|
||||
|
||||
public override void OnBorrowedFromPool(object target)
|
||||
{
|
||||
base.OnBorrowedFromPool(target);
|
||||
|
||||
Target = target as GameObject;
|
||||
|
||||
NameText.text = Target.name;
|
||||
Tab.TabText.text = $"[G] {Target.name}";
|
||||
|
||||
RuntimeProvider.Instance.StartCoroutine(InitCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator InitCoroutine()
|
||||
{
|
||||
yield return null;
|
||||
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(InspectorPanel.Instance.ContentRect);
|
||||
|
||||
TransformTree.Rebuild();
|
||||
|
||||
ComponentList.ScrollPool.Rebuild();
|
||||
UpdateComponents();
|
||||
}
|
||||
|
||||
public override void OnReturnToPool()
|
||||
{
|
||||
base.OnReturnToPool();
|
||||
|
||||
// release component and transform lists
|
||||
this.TransformTree.ScrollPool.ReturnCells();
|
||||
this.TransformTree.ScrollPool.SetUninitialized();
|
||||
|
||||
this.ComponentList.ScrollPool.ReturnCells();
|
||||
this.ComponentList.ScrollPool.SetUninitialized();
|
||||
}
|
||||
|
||||
private float timeOfLastUpdate;
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (!this.IsActive)
|
||||
return;
|
||||
|
||||
if (Target.IsNullOrDestroyed(false))
|
||||
{
|
||||
InspectorManager.ReleaseInspector(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time.time - timeOfLastUpdate > 1f)
|
||||
{
|
||||
timeOfLastUpdate = Time.time;
|
||||
|
||||
// Refresh children and components
|
||||
TransformTree.RefreshData(true, false);
|
||||
|
||||
UpdateComponents();
|
||||
|
||||
Tab.TabText.text = $"[G] {Target.name}";
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<GameObject> GetTransformEntries()
|
||||
{
|
||||
_rootEntries.Clear();
|
||||
for (int i = 0; i < Target.transform.childCount; i++)
|
||||
_rootEntries.Add(Target.transform.GetChild(i).gameObject);
|
||||
return _rootEntries;
|
||||
}
|
||||
|
||||
private readonly List<Component> _componentEntries = new List<Component>();
|
||||
|
||||
private List<Component> GetComponentEntries()
|
||||
{
|
||||
return _componentEntries;
|
||||
}
|
||||
|
||||
private static readonly Dictionary<string, string> compToStringCache = new Dictionary<string, string>();
|
||||
|
||||
private void SetComponentCell(ButtonCell cell, int index)
|
||||
{
|
||||
if (index < 0 || index >= _componentEntries.Count)
|
||||
{
|
||||
cell.Disable();
|
||||
return;
|
||||
}
|
||||
|
||||
cell.Enable();
|
||||
|
||||
var comp = _componentEntries[index];
|
||||
var type = comp.GetActualType();
|
||||
|
||||
if (!compToStringCache.ContainsKey(type.AssemblyQualifiedName))
|
||||
{
|
||||
compToStringCache.Add(type.AssemblyQualifiedName,
|
||||
$"<color={SignatureHighlighter.NAMESPACE}>{type.Namespace}</color>.{SignatureHighlighter.HighlightTypeName(type)}");
|
||||
}
|
||||
|
||||
cell.Button.ButtonText.text = compToStringCache[type.AssemblyQualifiedName];
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void UpdateComponents()
|
||||
{
|
||||
_componentEntries.Clear();
|
||||
var comps = Target.GetComponents<Component>();
|
||||
foreach (var comp in comps)
|
||||
_componentEntries.Add(comp);
|
||||
|
||||
ComponentList.RefreshData();
|
||||
ComponentList.ScrollPool.RefreshCells(true);
|
||||
}
|
||||
|
||||
protected override void OnCloseClicked()
|
||||
{
|
||||
InspectorManager.ReleaseInspector(this);
|
||||
}
|
||||
|
||||
public override GameObject CreateContent(GameObject parent)
|
||||
{
|
||||
uiRoot = UIFactory.CreateVerticalGroup(Pool<GameObjectInspector>.Instance.InactiveHolder,
|
||||
@ -54,120 +187,5 @@ namespace UnityExplorer.UI.Inspectors
|
||||
|
||||
return uiRoot;
|
||||
}
|
||||
|
||||
private readonly List<GameObject> _rootEntries = new List<GameObject>();
|
||||
|
||||
private IEnumerable<GameObject> GetTransformEntries()
|
||||
{
|
||||
_rootEntries.Clear();
|
||||
for (int i = 0; i < Target.transform.childCount; i++)
|
||||
_rootEntries.Add(Target.transform.GetChild(i).gameObject);
|
||||
return _rootEntries;
|
||||
}
|
||||
|
||||
private readonly List<Component> _componentEntries = new List<Component>();
|
||||
|
||||
private List<Component> GetComponentEntries()
|
||||
{
|
||||
return _componentEntries;
|
||||
}
|
||||
|
||||
private static readonly Dictionary<Type, string> compToStringCache = new Dictionary<Type, string>();
|
||||
|
||||
private void SetComponentCell(ButtonCell cell, int index)
|
||||
{
|
||||
if (index < 0 || index >= _componentEntries.Count)
|
||||
{
|
||||
cell.Disable();
|
||||
return;
|
||||
}
|
||||
|
||||
cell.Enable();
|
||||
|
||||
var comp = _componentEntries[index];
|
||||
var type = comp.GetActualType();
|
||||
|
||||
if (!compToStringCache.ContainsKey(type))
|
||||
{
|
||||
compToStringCache.Add(type,
|
||||
$"<color={SignatureHighlighter.NAMESPACE}>{type.Namespace}</color>.{SignatureHighlighter.HighlightTypeName(type)}");
|
||||
}
|
||||
|
||||
cell.Button.ButtonText.text = compToStringCache[type];
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public override void OnBorrowedFromPool(object target)
|
||||
{
|
||||
base.OnBorrowedFromPool(target);
|
||||
|
||||
Target = target as GameObject;
|
||||
|
||||
NameText.text = Target.name;
|
||||
this.Tab.TabText.text = $"[G] {Target.name}";
|
||||
|
||||
TransformTree.Rebuild();
|
||||
|
||||
ComponentList.ScrollPool.Rebuild();
|
||||
UpdateComponents();
|
||||
}
|
||||
|
||||
public override void OnReturnToPool()
|
||||
{
|
||||
base.OnReturnToPool();
|
||||
|
||||
// release component and transform lists
|
||||
this.TransformTree.ScrollPool.ReturnCells();
|
||||
this.TransformTree.ScrollPool.SetUninitialized();
|
||||
|
||||
this.ComponentList.ScrollPool.ReturnCells();
|
||||
this.ComponentList.ScrollPool.SetUninitialized();
|
||||
}
|
||||
|
||||
private float timeOfLastUpdate;
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
// todo update tab title? or put that in InspectorBase update?
|
||||
|
||||
if (!this.IsActive)
|
||||
return;
|
||||
|
||||
if (Time.time - timeOfLastUpdate > 1f)
|
||||
{
|
||||
timeOfLastUpdate = Time.time;
|
||||
|
||||
// Refresh children and components
|
||||
TransformTree.RefreshData(true, false);
|
||||
|
||||
UpdateComponents();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateComponents()
|
||||
{
|
||||
_componentEntries.Clear();
|
||||
foreach (var comp in Target.GetComponents<Component>())
|
||||
_componentEntries.Add(comp);
|
||||
|
||||
ComponentList.RefreshData();
|
||||
ComponentList.ScrollPool.RefreshCells(true);
|
||||
}
|
||||
|
||||
protected override void OnCloseClicked()
|
||||
{
|
||||
InspectorManager.ReleaseInspector(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user