mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-13 23:36:35 +08:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
f00134b283 | |||
3b6b9768fb | |||
5fbfa1b7aa | |||
7d26965c12 | |||
862523399a | |||
0afccadc64 | |||
0e37e8030c | |||
621a9cd72e | |||
56be5414f9 | |||
b8c4be473f |
@ -414,11 +414,15 @@ namespace UnityExplorer.CSConsole
|
|||||||
|
|
||||||
static bool usingEventSystemDictionaryMembers;
|
static bool usingEventSystemDictionaryMembers;
|
||||||
|
|
||||||
static readonly AmbiguousMemberHandler<EventSystem, GameObject> m_CurrentSelected_Handler_Normal = new("m_CurrentSelected", "m_currentSelected");
|
static readonly AmbiguousMemberHandler<EventSystem, GameObject> m_CurrentSelected_Handler_Normal
|
||||||
static readonly AmbiguousMemberHandler<EventSystem, Dictionary<int, GameObject>> m_CurrentSelected_Handler_Dictionary = new("m_CurrentSelected", "m_currentSelected");
|
= new(true, true, "m_CurrentSelected", "m_currentSelected");
|
||||||
|
static readonly AmbiguousMemberHandler<EventSystem, Dictionary<int, GameObject>> m_CurrentSelected_Handler_Dictionary
|
||||||
|
= new(true, true, "m_CurrentSelected", "m_currentSelected");
|
||||||
|
|
||||||
static readonly AmbiguousMemberHandler<EventSystem, bool> m_SelectionGuard_Handler_Normal = new("m_SelectionGuard", "m_selectionGuard");
|
static readonly AmbiguousMemberHandler<EventSystem, bool> m_SelectionGuard_Handler_Normal
|
||||||
static readonly AmbiguousMemberHandler<EventSystem, Dictionary<int, bool>> m_SelectionGuard_Handler_Dictionary = new("m_SelectionGuard", "m_selectionGuard");
|
= new(true, true, "m_SelectionGuard", "m_selectionGuard");
|
||||||
|
static readonly AmbiguousMemberHandler<EventSystem, Dictionary<int, bool>> m_SelectionGuard_Handler_Dictionary
|
||||||
|
= new(true, true, "m_SelectionGuard", "m_selectionGuard");
|
||||||
|
|
||||||
static void SetCurrentSelectedGameObject(EventSystem instance, GameObject value)
|
static void SetCurrentSelectedGameObject(EventSystem instance, GameObject value)
|
||||||
{
|
{
|
||||||
|
@ -51,13 +51,8 @@ namespace UnityExplorer.CSConsole
|
|||||||
ReferenceAssembly(asm);
|
ReferenceAssembly(asm);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CompilerContext context;
|
|
||||||
|
|
||||||
private static CompilerContext BuildContext(TextWriter tw)
|
private static CompilerContext BuildContext(TextWriter tw)
|
||||||
{
|
{
|
||||||
if (context != null)
|
|
||||||
return context;
|
|
||||||
|
|
||||||
_reportPrinter = new StreamReportPrinter(tw);
|
_reportPrinter = new StreamReportPrinter(tw);
|
||||||
|
|
||||||
var settings = new CompilerSettings
|
var settings = new CompilerSettings
|
||||||
@ -70,7 +65,7 @@ namespace UnityExplorer.CSConsole
|
|||||||
EnhancedWarnings = false
|
EnhancedWarnings = false
|
||||||
};
|
};
|
||||||
|
|
||||||
return context = new CompilerContext(settings, _reportPrinter);
|
return new CompilerContext(settings, _reportPrinter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ImportAppdomainAssemblies(Action<Assembly> import)
|
private static void ImportAppdomainAssemblies(Action<Assembly> import)
|
||||||
|
@ -37,7 +37,8 @@ namespace UnityExplorer.CacheObject
|
|||||||
this.NameLabelText = this is CacheMethod
|
this.NameLabelText = this is CacheMethod
|
||||||
? SignatureHighlighter.HighlightMethod(member as MethodInfo)
|
? SignatureHighlighter.HighlightMethod(member as MethodInfo)
|
||||||
: SignatureHighlighter.Parse(member.DeclaringType, false, member);
|
: SignatureHighlighter.Parse(member.DeclaringType, false, member);
|
||||||
this.NameForFiltering = $"{member.DeclaringType.Name}.{member.Name}";
|
|
||||||
|
this.NameForFiltering = SignatureHighlighter.RemoveHighlighting(NameLabelText);
|
||||||
this.NameLabelTextRaw = NameForFiltering;
|
this.NameLabelTextRaw = NameForFiltering;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,26 +165,8 @@ namespace UnityExplorer.CacheObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#region Cache Member Util
|
#region Cache Member Util
|
||||||
|
|
||||||
//public static bool CanParseArgs(ParameterInfo[] parameters)
|
|
||||||
//{
|
|
||||||
// foreach (var param in parameters)
|
|
||||||
// {
|
|
||||||
// var pType = param.ParameterType;
|
|
||||||
//
|
|
||||||
// if (pType.IsByRef && pType.HasElementType)
|
|
||||||
// pType = pType.GetElementType();
|
|
||||||
//
|
|
||||||
// if (pType != null && ParseUtility.CanParse(pType))
|
|
||||||
// continue;
|
|
||||||
// else
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
//}
|
|
||||||
|
|
||||||
public static List<CacheMember> GetCacheMembers(object inspectorTarget, Type _type, ReflectionInspector _inspector)
|
public static List<CacheMember> GetCacheMembers(object inspectorTarget, Type _type, ReflectionInspector _inspector)
|
||||||
{
|
{
|
||||||
var list = new List<CacheMember>();
|
var list = new List<CacheMember>();
|
||||||
|
@ -18,7 +18,7 @@ namespace UnityExplorer
|
|||||||
public static class ExplorerCore
|
public static class ExplorerCore
|
||||||
{
|
{
|
||||||
public const string NAME = "UnityExplorer";
|
public const string NAME = "UnityExplorer";
|
||||||
public const string VERSION = "4.5.8";
|
public const string VERSION = "4.5.10";
|
||||||
public const string AUTHOR = "Sinai";
|
public const string AUTHOR = "Sinai";
|
||||||
public const string GUID = "com.sinai.unityexplorer";
|
public const string GUID = "com.sinai.unityexplorer";
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
this.Target = newTarget;
|
this.Target = newTarget;
|
||||||
GOControls.UpdateGameObjectInfo(true, true);
|
GOControls.UpdateGameObjectInfo(true, true);
|
||||||
GOControls.UpdateTransformControlValues(true);
|
GOControls.UpdateTransformControlValues(true);
|
||||||
TransformTree.RefreshData(true, false);
|
TransformTree.RefreshData(true, false, true, false);
|
||||||
UpdateComponents();
|
UpdateComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
|
|
||||||
GOControls.UpdateGameObjectInfo(false, false);
|
GOControls.UpdateGameObjectInfo(false, false);
|
||||||
|
|
||||||
TransformTree.RefreshData(true, false);
|
TransformTree.RefreshData(true, false, false, false);
|
||||||
UpdateComponents();
|
UpdateComponents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,7 +220,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
var newObject = new GameObject(input);
|
var newObject = new GameObject(input);
|
||||||
newObject.transform.parent = GOTarget.transform;
|
newObject.transform.parent = GOTarget.transform;
|
||||||
|
|
||||||
TransformTree.RefreshData(true, false);
|
TransformTree.RefreshData(true, false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAddComponentClicked(string input)
|
private void OnAddComponentClicked(string input)
|
||||||
|
@ -133,7 +133,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
currentBaseTabText = $"{prefix} {SignatureHighlighter.Parse(TargetType, false)}";
|
currentBaseTabText = $"{prefix} {SignatureHighlighter.Parse(TargetType, false)}";
|
||||||
Tab.TabText.text = currentBaseTabText;
|
Tab.TabText.text = currentBaseTabText;
|
||||||
NameText.text = SignatureHighlighter.Parse(TargetType, true);
|
NameText.text = SignatureHighlighter.Parse(TargetType, true);
|
||||||
HiddenNameText.Text = TargetType.FullName;
|
HiddenNameText.Text = SignatureHighlighter.RemoveHighlighting(NameText.text);
|
||||||
|
|
||||||
string asmText;
|
string asmText;
|
||||||
if (TargetType.Assembly is AssemblyBuilder || string.IsNullOrEmpty(TargetType.Assembly.Location))
|
if (TargetType.Assembly is AssemblyBuilder || string.IsNullOrEmpty(TargetType.Assembly.Location))
|
||||||
|
@ -64,7 +64,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
public void UpdateTree()
|
public void UpdateTree()
|
||||||
{
|
{
|
||||||
SceneHandler.Update();
|
SceneHandler.Update();
|
||||||
Tree.RefreshData(true);
|
Tree.RefreshData(true, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void JumpToTransform(Transform transform)
|
public void JumpToTransform(Transform transform)
|
||||||
@ -94,7 +94,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
|
|
||||||
SceneHandler.SelectedScene = SceneHandler.LoadedScenes[value];
|
SceneHandler.SelectedScene = SceneHandler.LoadedScenes[value];
|
||||||
SceneHandler.Update();
|
SceneHandler.Update();
|
||||||
Tree.RefreshData(true);
|
Tree.RefreshData(true, true, true, false);
|
||||||
OnSelectedSceneChanged(SceneHandler.SelectedScene.Value);
|
OnSelectedSceneChanged(SceneHandler.SelectedScene.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tree.CurrentFilter = input;
|
Tree.CurrentFilter = input;
|
||||||
Tree.RefreshData(true, true);
|
Tree.RefreshData(true, false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TryLoadScene(LoadSceneMode mode, Dropdown allSceneDrop)
|
private void TryLoadScene(LoadSceneMode mode, Dropdown allSceneDrop)
|
||||||
@ -239,6 +239,17 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
|
|
||||||
refreshRow.SetActive(false);
|
refreshRow.SetActive(false);
|
||||||
|
|
||||||
|
// tree labels row
|
||||||
|
|
||||||
|
var labelsRow = UIFactory.CreateHorizontalGroup(toolbar, "LabelsRow", true, true, true, true, 2, new Vector4(2, 2, 2, 2));
|
||||||
|
UIFactory.SetLayoutElement(labelsRow, minHeight: 30, flexibleHeight: 0);
|
||||||
|
|
||||||
|
var nameLabel = UIFactory.CreateLabel(labelsRow, "NameLabel", "Name", TextAnchor.MiddleLeft, color: Color.grey);
|
||||||
|
UIFactory.SetLayoutElement(nameLabel.gameObject, flexibleWidth: 9999, minHeight: 25);
|
||||||
|
|
||||||
|
var indexLabel = UIFactory.CreateLabel(labelsRow, "IndexLabel", "Sibling Index", TextAnchor.MiddleLeft, fontSize: 12, color: Color.grey);
|
||||||
|
UIFactory.SetLayoutElement(indexLabel.gameObject, minWidth: 100, flexibleWidth: 0, minHeight: 25);
|
||||||
|
|
||||||
// Transform Tree
|
// Transform Tree
|
||||||
|
|
||||||
var scrollPool = UIFactory.CreateScrollPool<TransformCell>(uiRoot, "TransformTree", out GameObject scrollObj,
|
var scrollPool = UIFactory.CreateScrollPool<TransformCell>(uiRoot, "TransformTree", out GameObject scrollObj,
|
||||||
@ -248,7 +259,7 @@ namespace UnityExplorer.ObjectExplorer
|
|||||||
|
|
||||||
Tree = new TransformTree(scrollPool, GetRootEntries);
|
Tree = new TransformTree(scrollPool, GetRootEntries);
|
||||||
Tree.Init();
|
Tree.Init();
|
||||||
Tree.RefreshData(true, true);
|
Tree.RefreshData(true, true, true, false);
|
||||||
//scrollPool.Viewport.GetComponent<Mask>().enabled = false;
|
//scrollPool.Viewport.GetComponent<Mask>().enabled = false;
|
||||||
//UIRoot.GetComponent<Mask>().enabled = false;
|
//UIRoot.GetComponent<Mask>().enabled = false;
|
||||||
|
|
||||||
|
@ -17,8 +17,9 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
public int ChildCount { get; internal set; }
|
public int ChildCount { get; internal set; }
|
||||||
public string Name { get; internal set; }
|
public string Name { get; internal set; }
|
||||||
public bool Enabled { get; internal set; }
|
public bool Enabled { get; internal set; }
|
||||||
|
public int SiblingIndex { get; internal set; }
|
||||||
|
|
||||||
public bool Expanded => Tree.IsCellExpanded(InstanceID);
|
public bool Expanded => Tree.IsTransformExpanded(InstanceID);
|
||||||
|
|
||||||
public CachedTransform(TransformTree tree, Transform transform, int depth, CachedTransform parent = null)
|
public CachedTransform(TransformTree tree, Transform transform, int depth, CachedTransform parent = null)
|
||||||
{
|
{
|
||||||
@ -26,27 +27,32 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
Value = transform;
|
Value = transform;
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
InstanceID = transform.GetInstanceID();
|
InstanceID = transform.GetInstanceID();
|
||||||
|
SiblingIndex = transform.GetSiblingIndex();
|
||||||
Update(transform, depth);
|
Update(transform, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Update(Transform transform, int depth)
|
public bool Update(Transform transform, int depth)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool changed = false;
|
||||||
|
|
||||||
if (Value != transform
|
if (Value != transform
|
||||||
|| depth != Depth
|
|| depth != Depth
|
||||||
|| ChildCount != transform.childCount
|
|| ChildCount != transform.childCount
|
||||||
|| Name != transform.name
|
|| Name != transform.name
|
||||||
|| Enabled != transform.gameObject.activeSelf)
|
|| Enabled != transform.gameObject.activeSelf
|
||||||
|
|| SiblingIndex != transform.GetSiblingIndex())
|
||||||
{
|
{
|
||||||
|
changed = true;
|
||||||
|
|
||||||
Value = transform;
|
Value = transform;
|
||||||
Depth = depth;
|
Depth = depth;
|
||||||
ChildCount = transform.childCount;
|
ChildCount = transform.childCount;
|
||||||
Name = transform.name;
|
Name = transform.name;
|
||||||
Enabled = transform.gameObject.activeSelf;
|
Enabled = transform.gameObject.activeSelf;
|
||||||
ret = true;
|
SiblingIndex = transform.GetSiblingIndex();
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ using UniverseLib.UI;
|
|||||||
using UniverseLib.UI.Models;
|
using UniverseLib.UI.Models;
|
||||||
using UniverseLib.UI.Widgets;
|
using UniverseLib.UI.Widgets;
|
||||||
using UniverseLib.UI.Widgets.ScrollView;
|
using UniverseLib.UI.Widgets.ScrollView;
|
||||||
|
using UniverseLib.Utility;
|
||||||
|
|
||||||
namespace UnityExplorer.UI.Widgets
|
namespace UnityExplorer.UI.Widgets
|
||||||
{
|
{
|
||||||
@ -36,6 +37,7 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
public ButtonRef ExpandButton;
|
public ButtonRef ExpandButton;
|
||||||
public ButtonRef NameButton;
|
public ButtonRef NameButton;
|
||||||
public Toggle EnabledToggle;
|
public Toggle EnabledToggle;
|
||||||
|
public InputFieldRef SiblingIndex;
|
||||||
|
|
||||||
public LayoutElement spacer;
|
public LayoutElement spacer;
|
||||||
|
|
||||||
@ -77,6 +79,9 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
|
|
||||||
EnabledToggle.Set(cached.Value.gameObject.activeSelf, false);
|
EnabledToggle.Set(cached.Value.gameObject.activeSelf, false);
|
||||||
|
|
||||||
|
if (!SiblingIndex.Component.isFocused)
|
||||||
|
SiblingIndex.Text = cached.Value.GetSiblingIndex().ToString();
|
||||||
|
|
||||||
int childCount = cached.Value.childCount;
|
int childCount = cached.Value.childCount;
|
||||||
if (childCount > 0)
|
if (childCount > 0)
|
||||||
{
|
{
|
||||||
@ -118,6 +123,17 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
OnEnableToggled?.Invoke(cachedTransform);
|
OnEnableToggled?.Invoke(cachedTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnSiblingIndexEndEdit(string input)
|
||||||
|
{
|
||||||
|
if (this.cachedTransform == null || !this.cachedTransform.Value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (int.TryParse(input.Trim(), out int index))
|
||||||
|
this.cachedTransform.Value.SetSiblingIndex(index);
|
||||||
|
|
||||||
|
this.SiblingIndex.Text = this.cachedTransform.Value.GetSiblingIndex().ToString();
|
||||||
|
}
|
||||||
|
|
||||||
public GameObject CreateContent(GameObject parent)
|
public GameObject CreateContent(GameObject parent)
|
||||||
{
|
{
|
||||||
UIRoot = UIFactory.CreateUIObject("TransformCell", parent);
|
UIRoot = UIFactory.CreateUIObject("TransformCell", parent);
|
||||||
@ -152,10 +168,22 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
nameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
nameLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||||
nameLabel.alignment = TextAnchor.MiddleLeft;
|
nameLabel.alignment = TextAnchor.MiddleLeft;
|
||||||
|
|
||||||
Color normal = new Color(0.11f, 0.11f, 0.11f);
|
// Sibling index input
|
||||||
Color highlight = new Color(0.25f, 0.25f, 0.25f);
|
|
||||||
Color pressed = new Color(0.05f, 0.05f, 0.05f);
|
SiblingIndex = UIFactory.CreateInputField(this.UIRoot, "SiblingIndexInput", string.Empty);
|
||||||
Color disabled = new Color(1, 1, 1, 0);
|
SiblingIndex.Component.textComponent.fontSize = 11;
|
||||||
|
SiblingIndex.Component.textComponent.alignment = TextAnchor.MiddleRight;
|
||||||
|
var siblingImage = SiblingIndex.GameObject.GetComponent<Image>();
|
||||||
|
siblingImage.color = new(0f, 0f, 0f, 0.25f);
|
||||||
|
UIFactory.SetLayoutElement(SiblingIndex.GameObject, 35, 20, 0, 0);
|
||||||
|
SiblingIndex.Component.GetOnEndEdit().AddListener(OnSiblingIndexEndEdit);
|
||||||
|
|
||||||
|
// Setup selectables
|
||||||
|
|
||||||
|
Color normal = new(0.11f, 0.11f, 0.11f);
|
||||||
|
Color highlight = new(0.25f, 0.25f, 0.25f);
|
||||||
|
Color pressed = new(0.05f, 0.05f, 0.05f);
|
||||||
|
Color disabled = new(1, 1, 1, 0);
|
||||||
RuntimeHelper.SetColorBlock(ExpandButton.Component, normal, highlight, pressed, disabled);
|
RuntimeHelper.SetColorBlock(ExpandButton.Component, normal, highlight, pressed, disabled);
|
||||||
RuntimeHelper.SetColorBlock(NameButton.Component, normal, highlight, pressed, disabled);
|
RuntimeHelper.SetColorBlock(NameButton.Component, normal, highlight, pressed, disabled);
|
||||||
|
|
||||||
|
@ -2,12 +2,9 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Linq;
|
using System.Diagnostics;
|
||||||
using System.Text;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
|
||||||
using UniverseLib;
|
using UniverseLib;
|
||||||
using UniverseLib.UI.Widgets;
|
|
||||||
using UniverseLib.UI.Widgets.ScrollView;
|
using UniverseLib.UI.Widgets.ScrollView;
|
||||||
using UniverseLib.Utility;
|
using UniverseLib.Utility;
|
||||||
|
|
||||||
@ -20,22 +17,36 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
|
|
||||||
public ScrollPool<TransformCell> ScrollPool;
|
public ScrollPool<TransformCell> ScrollPool;
|
||||||
|
|
||||||
|
// IMPORTANT CAVEAT WITH OrderedDictionary:
|
||||||
|
// While the performance is mostly good, there are two methods we should NEVER use:
|
||||||
|
// - Remove(object)
|
||||||
|
// - set_Item[object]
|
||||||
|
// These two methods have extremely bad performance due to using IndexOfKey(), which iterates the whole dictionary.
|
||||||
|
// Currently we do not use either of these methods, so everything should be constant time hash lookups.
|
||||||
|
// We DO make use of get_Item[object], get_Item[index], Add, Insert and RemoveAt, which OrderedDictionary perfectly meets our needs for.
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Key: UnityEngine.Transform instance ID<br/>
|
/// Key: UnityEngine.Transform instance ID<br/>
|
||||||
/// Value: CachedTransform
|
/// Value: CachedTransform
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal readonly OrderedDictionary cachedTransforms = new OrderedDictionary();
|
internal readonly OrderedDictionary cachedTransforms = new();
|
||||||
|
|
||||||
// for keeping track of which actual transforms are expanded or not, outside of the cache data.
|
// for keeping track of which actual transforms are expanded or not, outside of the cache data.
|
||||||
private readonly HashSet<int> expandedInstanceIDs = new HashSet<int>();
|
private readonly HashSet<int> expandedInstanceIDs = new();
|
||||||
private readonly HashSet<int> autoExpandedIDs = new HashSet<int>();
|
private readonly HashSet<int> autoExpandedIDs = new();
|
||||||
|
|
||||||
private readonly HashSet<int> visited = new HashSet<int>();
|
// state for Traverse parse
|
||||||
private bool needRefresh;
|
private readonly HashSet<int> visited = new();
|
||||||
|
private bool needRefreshUI;
|
||||||
private int displayIndex;
|
private int displayIndex;
|
||||||
|
int prevDisplayIndex;
|
||||||
|
|
||||||
public int ItemCount => cachedTransforms.Count;
|
private Coroutine refreshCoroutine;
|
||||||
|
private readonly Stopwatch traversedThisFrame = new();
|
||||||
|
|
||||||
|
// ScrollPool item count. PrevDisplayIndex is the highest index + 1 from our last traverse.
|
||||||
|
public int ItemCount => prevDisplayIndex;
|
||||||
|
|
||||||
|
// Search filter
|
||||||
public bool Filtering => !string.IsNullOrEmpty(currentFilter);
|
public bool Filtering => !string.IsNullOrEmpty(currentFilter);
|
||||||
private bool wasFiltering;
|
private bool wasFiltering;
|
||||||
|
|
||||||
@ -62,44 +73,24 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
GetRootEntriesMethod = getRootEntriesMethod;
|
GetRootEntriesMethod = getRootEntriesMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnCellBorrowed(TransformCell cell)
|
// Initialize and reset
|
||||||
{
|
|
||||||
cell.OnExpandToggled += OnCellExpandToggled;
|
|
||||||
cell.OnGameObjectClicked += OnGameObjectClicked;
|
|
||||||
cell.OnEnableToggled += OnCellEnableToggled;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnGameObjectClicked(GameObject obj)
|
|
||||||
{
|
|
||||||
if (OnClickOverrideHandler != null)
|
|
||||||
OnClickOverrideHandler.Invoke(obj);
|
|
||||||
else
|
|
||||||
InspectorManager.Inspect(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnCellExpandToggled(CachedTransform cache)
|
|
||||||
{
|
|
||||||
var instanceID = cache.InstanceID;
|
|
||||||
if (expandedInstanceIDs.Contains(instanceID))
|
|
||||||
expandedInstanceIDs.Remove(instanceID);
|
|
||||||
else
|
|
||||||
expandedInstanceIDs.Add(instanceID);
|
|
||||||
|
|
||||||
RefreshData(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnCellEnableToggled(CachedTransform cache)
|
|
||||||
{
|
|
||||||
cache.Value.gameObject.SetActive(!cache.Value.gameObject.activeSelf);
|
|
||||||
|
|
||||||
RefreshData(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Must be called externally from owner of this TransformTree
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
ScrollPool.Initialize(this);
|
ScrollPool.Initialize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called to completely reset the tree, ie. switching inspected GameObject
|
||||||
|
public void Rebuild()
|
||||||
|
{
|
||||||
|
autoExpandedIDs.Clear();
|
||||||
|
expandedInstanceIDs.Clear();
|
||||||
|
|
||||||
|
RefreshData(true, true, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called to completely wipe our data (ie, GameObject inspector returning to pool)
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
this.cachedTransforms.Clear();
|
this.cachedTransforms.Clear();
|
||||||
@ -107,14 +98,21 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
autoExpandedIDs.Clear();
|
autoExpandedIDs.Clear();
|
||||||
expandedInstanceIDs.Clear();
|
expandedInstanceIDs.Clear();
|
||||||
this.ScrollPool.Refresh(true, true);
|
this.ScrollPool.Refresh(true, true);
|
||||||
|
if (refreshCoroutine != null)
|
||||||
|
{
|
||||||
|
RuntimeHelper.StopCoroutine(refreshCoroutine);
|
||||||
|
refreshCoroutine = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsCellExpanded(int instanceID)
|
// Checks if the given Instance ID is expanded or not
|
||||||
|
public bool IsTransformExpanded(int instanceID)
|
||||||
{
|
{
|
||||||
return Filtering ? autoExpandedIDs.Contains(instanceID)
|
return Filtering ? autoExpandedIDs.Contains(instanceID)
|
||||||
: expandedInstanceIDs.Contains(instanceID);
|
: expandedInstanceIDs.Contains(instanceID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Jumps to a specific Transform in the tree and highlights it.
|
||||||
public void JumpAndExpandToTransform(Transform transform)
|
public void JumpAndExpandToTransform(Transform transform)
|
||||||
{
|
{
|
||||||
// make sure all parents of the object are expanded
|
// make sure all parents of the object are expanded
|
||||||
@ -128,8 +126,9 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
parent = parent.parent;
|
parent = parent.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh cached transforms (no UI rebuild yet)
|
// Refresh cached transforms (no UI rebuild yet).
|
||||||
RefreshData(false);
|
// Stop existing coroutine and do it oneshot.
|
||||||
|
RefreshData(false, false, true, true);
|
||||||
|
|
||||||
int transformID = transform.GetInstanceID();
|
int transformID = transform.GetInstanceID();
|
||||||
|
|
||||||
@ -162,62 +161,88 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
button.OnDeselect(null);
|
button.OnDeselect(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Rebuild()
|
// Perform a Traverse and optionally refresh the ScrollPool as well.
|
||||||
|
// If oneShot, then this happens instantly with no yield.
|
||||||
|
public void RefreshData(bool andRefreshUI, bool jumpToTop, bool stopExistingCoroutine, bool oneShot)
|
||||||
{
|
{
|
||||||
autoExpandedIDs.Clear();
|
if (refreshCoroutine != null)
|
||||||
expandedInstanceIDs.Clear();
|
{
|
||||||
|
if (stopExistingCoroutine)
|
||||||
RefreshData(true, true);
|
{
|
||||||
|
RuntimeHelper.StopCoroutine(refreshCoroutine);
|
||||||
|
refreshCoroutine = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RefreshData(bool andReload = false, bool jumpToTop = false)
|
|
||||||
{
|
|
||||||
visited.Clear();
|
visited.Clear();
|
||||||
displayIndex = 0;
|
displayIndex = 0;
|
||||||
needRefresh = false;
|
needRefreshUI = false;
|
||||||
|
traversedThisFrame.Reset();
|
||||||
|
traversedThisFrame.Start();
|
||||||
|
|
||||||
var rootObjects = GetRootEntriesMethod.Invoke();
|
IEnumerable<GameObject> rootObjects = GetRootEntriesMethod.Invoke();
|
||||||
|
|
||||||
//int displayIndex = 0;
|
refreshCoroutine = RuntimeHelper.StartCoroutine(RefreshCoroutine(rootObjects, andRefreshUI, jumpToTop, oneShot));
|
||||||
foreach (var obj in rootObjects)
|
}
|
||||||
if (obj) Traverse(obj.transform);
|
|
||||||
|
// Coroutine for batched updates, max 2000 gameobjects per frame so FPS doesn't get tanked when there is like 100k gameobjects.
|
||||||
|
// if "oneShot", then this will NOT be batched (if we need an immediate full update).
|
||||||
|
IEnumerator RefreshCoroutine(IEnumerable<GameObject> rootObjects, bool andRefreshUI, bool jumpToTop, bool oneShot)
|
||||||
|
{
|
||||||
|
foreach (var gameObj in rootObjects)
|
||||||
|
{
|
||||||
|
if (gameObj)
|
||||||
|
{
|
||||||
|
var enumerator = Traverse(gameObj.transform, null, 0, oneShot);
|
||||||
|
while (enumerator.MoveNext())
|
||||||
|
{
|
||||||
|
if (!oneShot)
|
||||||
|
yield return enumerator.Current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Prune displayed transforms that we didnt visit in that traverse
|
// Prune displayed transforms that we didnt visit in that traverse
|
||||||
for (int i = cachedTransforms.Count - 1; i >= 0; i--)
|
for (int i = cachedTransforms.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
var obj = (CachedTransform)cachedTransforms[i];
|
var cached = (CachedTransform)cachedTransforms[i];
|
||||||
if (!visited.Contains(obj.InstanceID))
|
if (!visited.Contains(cached.InstanceID))
|
||||||
{
|
{
|
||||||
cachedTransforms.Remove(obj.InstanceID);
|
cachedTransforms.RemoveAt(i);
|
||||||
needRefresh = true;
|
needRefreshUI = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!needRefresh)
|
if (andRefreshUI && needRefreshUI)
|
||||||
return;
|
ScrollPool.Refresh(true, jumpToTop);
|
||||||
|
|
||||||
//displayedObjects.Clear();
|
prevDisplayIndex = displayIndex;
|
||||||
|
refreshCoroutine = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (andReload)
|
// Recursive method to check a Transform and its children (if expanded).
|
||||||
|
// Parent and depth can be null/default.
|
||||||
|
private IEnumerator Traverse(Transform transform, CachedTransform parent, int depth, bool oneShot)
|
||||||
{
|
{
|
||||||
if (!jumpToTop)
|
// Let's only tank 2ms of each frame (60->53fps)
|
||||||
ScrollPool.Refresh(true);
|
if (traversedThisFrame.ElapsedMilliseconds > 2)
|
||||||
else
|
{
|
||||||
ScrollPool.Refresh(true, true);
|
yield return null;
|
||||||
}
|
traversedThisFrame.Reset();
|
||||||
|
traversedThisFrame.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Traverse(Transform transform, CachedTransform parent = null, int depth = 0)
|
|
||||||
{
|
|
||||||
int instanceID = transform.GetInstanceID();
|
int instanceID = transform.GetInstanceID();
|
||||||
|
|
||||||
if (visited.Contains(instanceID))
|
if (visited.Contains(instanceID))
|
||||||
return;
|
yield break;
|
||||||
|
|
||||||
if (Filtering)
|
if (Filtering)
|
||||||
{
|
{
|
||||||
if (!FilterHierarchy(transform))
|
if (!FilterHierarchy(transform))
|
||||||
return;
|
yield break;
|
||||||
|
|
||||||
visited.Add(instanceID);
|
visited.Add(instanceID);
|
||||||
|
|
||||||
@ -231,12 +256,25 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
if (cachedTransforms.Contains(instanceID))
|
if (cachedTransforms.Contains(instanceID))
|
||||||
{
|
{
|
||||||
cached = (CachedTransform)cachedTransforms[(object)instanceID];
|
cached = (CachedTransform)cachedTransforms[(object)instanceID];
|
||||||
|
int prevSiblingIdx = cached.SiblingIndex;
|
||||||
if (cached.Update(transform, depth))
|
if (cached.Update(transform, depth))
|
||||||
needRefresh = true;
|
{
|
||||||
|
needRefreshUI = true;
|
||||||
|
|
||||||
|
// If the sibling index changed, we need to shuffle it in our cached transforms list.
|
||||||
|
if (prevSiblingIdx != cached.SiblingIndex)
|
||||||
|
{
|
||||||
|
cachedTransforms.Remove(instanceID);
|
||||||
|
if (cachedTransforms.Count <= displayIndex)
|
||||||
|
cachedTransforms.Add(instanceID, cached);
|
||||||
|
else
|
||||||
|
cachedTransforms.Insert(displayIndex, instanceID, cached);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
needRefresh = true;
|
needRefreshUI = true;
|
||||||
cached = new CachedTransform(this, transform, depth, parent);
|
cached = new CachedTransform(this, transform, depth, parent);
|
||||||
if (cachedTransforms.Count <= displayIndex)
|
if (cachedTransforms.Count <= displayIndex)
|
||||||
cachedTransforms.Add(instanceID, cached);
|
cachedTransforms.Add(instanceID, cached);
|
||||||
@ -246,10 +284,17 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
|
|
||||||
displayIndex++;
|
displayIndex++;
|
||||||
|
|
||||||
if (IsCellExpanded(instanceID) && cached.Value.childCount > 0)
|
if (IsTransformExpanded(instanceID) && cached.Value.childCount > 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < transform.childCount; i++)
|
for (int i = 0; i < transform.childCount; i++)
|
||||||
Traverse(transform.GetChild(i), cached, depth + 1);
|
{
|
||||||
|
var enumerator = Traverse(transform.GetChild(i), cached, depth + 1, oneShot);
|
||||||
|
while (enumerator.MoveNext())
|
||||||
|
{
|
||||||
|
if (!oneShot)
|
||||||
|
yield return enumerator.Current;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,13 +321,44 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
if (Filtering)
|
if (Filtering)
|
||||||
{
|
{
|
||||||
if (cell.cachedTransform.Name.ContainsIgnoreCase(currentFilter))
|
if (cell.cachedTransform.Name.ContainsIgnoreCase(currentFilter))
|
||||||
{
|
|
||||||
cell.NameButton.ButtonText.color = Color.green;
|
cell.NameButton.ButtonText.color = Color.green;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
cell.Disable();
|
cell.Disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnCellBorrowed(TransformCell cell)
|
||||||
|
{
|
||||||
|
cell.OnExpandToggled += OnCellExpandToggled;
|
||||||
|
cell.OnGameObjectClicked += OnGameObjectClicked;
|
||||||
|
cell.OnEnableToggled += OnCellEnableToggled;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnGameObjectClicked(GameObject obj)
|
||||||
|
{
|
||||||
|
if (OnClickOverrideHandler != null)
|
||||||
|
OnClickOverrideHandler.Invoke(obj);
|
||||||
|
else
|
||||||
|
InspectorManager.Inspect(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnCellExpandToggled(CachedTransform cache)
|
||||||
|
{
|
||||||
|
var instanceID = cache.InstanceID;
|
||||||
|
if (expandedInstanceIDs.Contains(instanceID))
|
||||||
|
expandedInstanceIDs.Remove(instanceID);
|
||||||
|
else
|
||||||
|
expandedInstanceIDs.Add(instanceID);
|
||||||
|
|
||||||
|
RefreshData(true, false, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnCellEnableToggled(CachedTransform cache)
|
||||||
|
{
|
||||||
|
cache.Value.gameObject.SetActive(!cache.Value.gameObject.activeSelf);
|
||||||
|
|
||||||
|
RefreshData(true, false, true, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,13 +175,13 @@
|
|||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="UniverseLib.Mono">
|
<Reference Include="UniverseLib.Mono">
|
||||||
<HintPath>packages\UniverseLib.1.2.10\lib\net35\UniverseLib.Mono.dll</HintPath>
|
<HintPath>packages\UniverseLib.1.2.15\lib\net35\UniverseLib.Mono.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<!-- Il2Cpp refs -->
|
<!-- Il2Cpp refs -->
|
||||||
<ItemGroup Condition="'$(IsCpp)'=='true'">
|
<ItemGroup Condition="'$(IsCpp)'=='true'">
|
||||||
<Reference Include="UniverseLib.IL2CPP">
|
<Reference Include="UniverseLib.IL2CPP">
|
||||||
<HintPath>packages\UniverseLib.1.2.10\lib\net472\UniverseLib.IL2CPP.dll</HintPath>
|
<HintPath>packages\UniverseLib.1.2.15\lib\net472\UniverseLib.IL2CPP.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="UnhollowerBaseLib, Version=0.4.22.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="UnhollowerBaseLib, Version=0.4.22.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>packages\Il2CppAssemblyUnhollower.BaseLib.0.4.22\lib\net472\UnhollowerBaseLib.dll</HintPath>
|
<HintPath>packages\Il2CppAssemblyUnhollower.BaseLib.0.4.22\lib\net472\UnhollowerBaseLib.dll</HintPath>
|
||||||
|
@ -6,6 +6,6 @@
|
|||||||
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.18.2" targetFramework="net35" />
|
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.18.2" targetFramework="net35" />
|
||||||
<package id="Mono.Cecil" version="0.10.4" targetFramework="net35" />
|
<package id="Mono.Cecil" version="0.10.4" targetFramework="net35" />
|
||||||
<package id="Samboy063.Tomlet" version="3.1.3" targetFramework="net472" />
|
<package id="Samboy063.Tomlet" version="3.1.3" targetFramework="net472" />
|
||||||
<package id="UniverseLib" version="1.2.10" targetFramework="net35" />
|
<package id="UniverseLib" version="1.2.15" targetFramework="net35" />
|
||||||
<package id="UniverseLib.Analyzers" version="1.0.3" targetFramework="net35" developmentDependency="true" />
|
<package id="UniverseLib.Analyzers" version="1.0.3" targetFramework="net35" developmentDependency="true" />
|
||||||
</packages>
|
</packages>
|
Reference in New Issue
Block a user