From 217b93ef4f523f114dbb805f08171f41590900f1 Mon Sep 17 00:00:00 2001 From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com> Date: Thu, 3 Sep 2020 20:58:04 +1000 Subject: [PATCH] 1.5.2 * Added ability to force Reflection Inspector for GameObjects and Transforms if you hold Left Shift while clicking the Inspect button * Fixed a bug causing duplicate windows to open when you inspect Transforms, the current active window will now be focused. Note: does not apply if you hold Left Shift for forced reflection. --- src/CachedObjects/CacheGameObject.cs | 25 +-------------- src/Helpers/UIHelpers.cs | 14 +++++--- src/Windows/GameObjectWindow.cs | 6 +++- src/Windows/WindowManager.cs | 48 ++++++++++++++++++---------- 4 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/CachedObjects/CacheGameObject.cs b/src/CachedObjects/CacheGameObject.cs index 34bf0af..f9a60f9 100644 --- a/src/CachedObjects/CacheGameObject.cs +++ b/src/CachedObjects/CacheGameObject.cs @@ -10,32 +10,9 @@ namespace Explorer { public class CacheGameObject : CacheObjectBase { - private GameObject GameObj - { - get - { - if (m_gameObject == null) - { - if (Value is Il2CppSystem.Object ilObj) - { - var ilType = ilObj.GetIl2CppType(); - - if (ilType == ReflectionHelpers.GameObjectType || ilType == ReflectionHelpers.TransformType) - { - m_gameObject = ilObj.TryCast() ?? ilObj.TryCast()?.gameObject; - } - } - } - - return m_gameObject; - } - } - - private GameObject m_gameObject; - public override void DrawValue(Rect window, float width) { - UIHelpers.GameobjButton(GameObj, null, false, width); + UIHelpers.GameobjButton(Value, null, false, width); } public override void UpdateValue() diff --git a/src/Helpers/UIHelpers.cs b/src/Helpers/UIHelpers.cs index cbf4bd9..922eff6 100644 --- a/src/Helpers/UIHelpers.cs +++ b/src/Helpers/UIHelpers.cs @@ -22,8 +22,10 @@ namespace Explorer } // helper for drawing a styled button for a GameObject or Transform - public static void GameobjButton(GameObject obj, Action specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380) + public static void GameobjButton(object _obj, Action specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380) { + var obj = (_obj as GameObject) ?? (_obj as Transform).gameObject; + bool children = obj.transform.childCount > 0; string label = children ? "[" + obj.transform.childCount + " children] " : ""; @@ -49,11 +51,13 @@ namespace Explorer color = Color.red; } - FastGameobjButton(obj, color, label, obj.activeSelf, specialInspectMethod, showSmallInspectBtn, width); + FastGameobjButton(_obj, color, label, obj.activeSelf, specialInspectMethod, showSmallInspectBtn, width); } - public static void FastGameobjButton(GameObject obj, Color activeColor, string label, bool enabled, Action specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380) + public static void FastGameobjButton(object _obj, Color activeColor, string label, bool enabled, Action specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380) { + var obj = _obj as GameObject ?? (_obj as Transform).gameObject; + if (!obj) { GUILayout.Label("null", null); @@ -83,7 +87,7 @@ namespace Explorer } else { - WindowManager.InspectObject(obj, out bool _); + WindowManager.InspectObject(_obj, out bool _); } } @@ -94,7 +98,7 @@ namespace Explorer if (showSmallInspectBtn) { - SmallInspectButton(obj); + SmallInspectButton(_obj); } GUILayout.EndHorizontal(); diff --git a/src/Windows/GameObjectWindow.cs b/src/Windows/GameObjectWindow.cs index 75cb2ce..908ee96 100644 --- a/src/Windows/GameObjectWindow.cs +++ b/src/Windows/GameObjectWindow.cs @@ -175,12 +175,16 @@ namespace Explorer GUILayout.Label("Scene: " + (m_scene == "" ? "n/a" : m_scene) + "", null); if (m_scene == UnityHelpers.ActiveSceneName) { - if (GUILayout.Button("< View in Scene Explorer", new GUILayoutOption[] { GUILayout.Width(230) })) + if (GUILayout.Button("Send to Scene View", new GUILayoutOption[] { GUILayout.Width(150) })) { ScenePage.Instance.SetTransformTarget(m_object.transform); MainMenu.SetCurrentPage(0); } } + if (GUILayout.Button("Reflection Inspect", new GUILayoutOption[] { GUILayout.Width(150) })) + { + WindowManager.InspectObject(Target, out _, true); + } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); diff --git a/src/Windows/WindowManager.cs b/src/Windows/WindowManager.cs index 29fc7e0..0288438 100644 --- a/src/Windows/WindowManager.cs +++ b/src/Windows/WindowManager.cs @@ -86,34 +86,50 @@ namespace Explorer // ========= Public Helpers ========= - public static UIWindow InspectObject(object obj, out bool createdNew) + public static UIWindow InspectObject(object obj, out bool createdNew, bool forceReflection = false) { createdNew = false; - UnityEngine.Object uObj = null; - if (obj is UnityEngine.Object) + if (Input.GetKey(KeyCode.LeftShift)) { - uObj = obj as UnityEngine.Object; + forceReflection = true; + } + + Il2CppSystem.Object iObj = null; + if (obj is Il2CppSystem.Object isObj) + { + iObj = isObj; } - foreach (var window in Windows) + if (!forceReflection) { - bool equals = ReferenceEquals(obj, window.Target); - - if (!equals && uObj != null && window.Target is UnityEngine.Object uTarget) + foreach (var window in Windows) { - equals = uObj.m_CachedPtr == uTarget.m_CachedPtr; - } + bool equals = ReferenceEquals(obj, window.Target); - if (equals) - { - FocusWindow(window); - return window; + if (!equals && iObj is Il2CppSystem.Object iCurrent && window.Target is Il2CppSystem.Object iTarget) + { + if (iCurrent.GetIl2CppType() != iTarget.GetIl2CppType()) + { + if (iCurrent is Transform transform) + { + iCurrent = transform.gameObject; + } + } + + equals = iCurrent.Pointer == iTarget.Pointer; + } + + if (equals) + { + FocusWindow(window); + return window; + } } } createdNew = true; - if (obj is GameObject || obj is Transform) + if (!forceReflection && (obj is GameObject || obj is Transform)) { return InspectGameObject(obj as GameObject ?? (obj as Transform).gameObject); } @@ -144,7 +160,7 @@ namespace Explorer return new_window; } - public static UIWindow InspectReflection(object obj) + private static UIWindow InspectReflection(object obj) { var new_window = UIWindow.CreateWindow(obj); FocusWindow(new_window);