From 788bcf361db340f0e5c06679b19266a6898ef0de Mon Sep 17 00:00:00 2001
From: ManlyMarco <39247311+ManlyMarco@users.noreply.github.com>
Date: Thu, 2 Oct 2025 13:43:42 +0200
Subject: [PATCH 1/6] Refactor inspector member collecting code
---
.../RuntimeUnityEditor.Core.projitems | 1 +
.../Inspector/Inspector.InspectorTab.cs | 211 +---------------
.../Windows/Inspector/MemberCollector.cs | 236 ++++++++++++++++++
3 files changed, 242 insertions(+), 206 deletions(-)
create mode 100644 RuntimeUnityEditor.Core/Windows/Inspector/MemberCollector.cs
diff --git a/RuntimeUnityEditor.Core/RuntimeUnityEditor.Core.projitems b/RuntimeUnityEditor.Core/RuntimeUnityEditor.Core.projitems
index fe394b5..c46ca27 100644
--- a/RuntimeUnityEditor.Core/RuntimeUnityEditor.Core.projitems
+++ b/RuntimeUnityEditor.Core/RuntimeUnityEditor.Core.projitems
@@ -87,6 +87,7 @@
+
diff --git a/RuntimeUnityEditor.Core/Windows/Inspector/Inspector.InspectorTab.cs b/RuntimeUnityEditor.Core/Windows/Inspector/Inspector.InspectorTab.cs
index 467566d..1c37a4c 100644
--- a/RuntimeUnityEditor.Core/Windows/Inspector/Inspector.InspectorTab.cs
+++ b/RuntimeUnityEditor.Core/Windows/Inspector/Inspector.InspectorTab.cs
@@ -39,7 +39,7 @@ public InspectorStackEntryBase CurrentStackItem
public void Clear()
{
InspectorStack.Clear();
- CacheAllMembers(null);
+ _fieldCache.Clear();
}
public void Pop()
@@ -68,218 +68,17 @@ public void Push(InspectorStackEntryBase stackEntry)
LoadStackEntry(stackEntry);
}
- private static IEnumerable MethodsToCacheEntries(object instance, Type ownerType, IEnumerable methodsToCheck)
- {
- var cacheItems = methodsToCheck
- .Where(x => !x.IsConstructor && !x.IsSpecialName)
- .Where(f => !f.IsDefined(typeof(CompilerGeneratedAttribute), false))
- .Where(x => x.Name != "MemberwiseClone" && x.Name != "obj_address") // Instant game crash
- .Select(m => new MethodCacheEntry(instance, m, ownerType)).Cast();
- return cacheItems;
- }
-
- private void CacheAllMembers(InstanceStackEntry entry)
- {
- _fieldCache.Clear();
-
- var objectToOpen = entry?.Instance;
- if (objectToOpen == null) return;
-
- var type = objectToOpen.GetType();
-
- try
- {
- CallbackCacheEntry GetExportTexEntry(Texture texture)
- {
- return new CallbackCacheEntry("Export Texture to file",
- "Encode the texture to a PNG and save it to a new file",
- texture.SaveTextureToFileWithDialog);
- }
-
- if (objectToOpen is Component cmp)
- {
- if (ObjectTreeViewer.Initialized)
- {
- _fieldCache.Add(new CallbackCacheEntry("Open in Scene Object Browser",
- "Navigate to GameObject this Component is attached to",
- () => ObjectTreeViewer.Instance.SelectAndShowObject(cmp.transform)));
- }
-
- if (objectToOpen is UnityEngine.UI.Image img)
- _fieldCache.Add(GetExportTexEntry(img.mainTexture));
- else if (objectToOpen is Renderer rend && MeshExport.CanExport(rend))
- {
- _fieldCache.Add(new CallbackCacheEntry("Export mesh to .obj", "Save base mesh used by this renderer to file", () => MeshExport.ExportObj(rend, false, false)));
- _fieldCache.Add(new CallbackCacheEntry("Export mesh to .obj (Baked)", "Bakes current pose into the exported mesh", () => MeshExport.ExportObj(rend, true, false)));
- _fieldCache.Add(new CallbackCacheEntry("Export mesh to .obj (World)", "Bakes pose while keeping world position", () => MeshExport.ExportObj(rend, true, true)));
- }
- }
- else if (objectToOpen is GameObject castedObj)
- {
- if (ObjectTreeViewer.Initialized)
- {
- _fieldCache.Add(new CallbackCacheEntry("Open in Scene Object Browser",
- "Navigate to this object in the Scene Object Browser",
- () => ObjectTreeViewer.Instance.SelectAndShowObject(castedObj.transform)));
- }
-#if !IL2CPP
- _fieldCache.Add(new ReadonlyCacheEntry("Child objects", castedObj.transform.Cast().ToArray()));
-#endif
- _fieldCache.Add(new ReadonlyCacheEntry("Components", castedObj.AbstractGetAllComponents()));
- }
- else if (objectToOpen is Texture tex)
- {
- _fieldCache.Add(GetExportTexEntry(tex));
- }
-
- // If we somehow enter a string, this allows user to see what the string actually says
- if (type == typeof(string))
- {
- _fieldCache.Add(new ReadonlyCacheEntry("this", objectToOpen));
- }
- else if (objectToOpen is Transform)
- {
- // Prevent the list overloads from listing subcomponents
- }
- else if (objectToOpen is IList list)
- {
- for (var i = 0; i < list.Count; i++)
- _fieldCache.Add(new ListCacheEntry(list, i));
- }
- else if (objectToOpen is IEnumerable enumerable)
- {
- _fieldCache.AddRange(enumerable.Cast