Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 217b93e

Browse files
committed
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.
1 parent 42156e1 commit 217b93e

File tree

4 files changed

+47
-46
lines changed

4 files changed

+47
-46
lines changed

src/CachedObjects/CacheGameObject.cs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,9 @@ namespace Explorer
1010
{
1111
public class CacheGameObject : CacheObjectBase
1212
{
13-
private GameObject GameObj
14-
{
15-
get
16-
{
17-
if (m_gameObject == null)
18-
{
19-
if (Value is Il2CppSystem.Object ilObj)
20-
{
21-
var ilType = ilObj.GetIl2CppType();
22-
23-
if (ilType == ReflectionHelpers.GameObjectType || ilType == ReflectionHelpers.TransformType)
24-
{
25-
m_gameObject = ilObj.TryCast<GameObject>() ?? ilObj.TryCast<Transform>()?.gameObject;
26-
}
27-
}
28-
}
29-
30-
return m_gameObject;
31-
}
32-
}
33-
34-
private GameObject m_gameObject;
35-
3613
public override void DrawValue(Rect window, float width)
3714
{
38-
UIHelpers.GameobjButton(GameObj, null, false, width);
15+
UIHelpers.GameobjButton(Value, null, false, width);
3916
}
4017

4118
public override void UpdateValue()

src/Helpers/UIHelpers.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ public static void InstantiateButton(Object obj, float width = 100)
2222
}
2323

2424
// helper for drawing a styled button for a GameObject or Transform
25-
public static void GameobjButton(GameObject obj, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
25+
public static void GameobjButton(object _obj, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
2626
{
27+
var obj = (_obj as GameObject) ?? (_obj as Transform).gameObject;
28+
2729
bool children = obj.transform.childCount > 0;
2830

2931
string label = children ? "[" + obj.transform.childCount + " children] " : "";
@@ -49,11 +51,13 @@ public static void GameobjButton(GameObject obj, Action<Transform> specialInspec
4951
color = Color.red;
5052
}
5153

52-
FastGameobjButton(obj, color, label, obj.activeSelf, specialInspectMethod, showSmallInspectBtn, width);
54+
FastGameobjButton(_obj, color, label, obj.activeSelf, specialInspectMethod, showSmallInspectBtn, width);
5355
}
5456

55-
public static void FastGameobjButton(GameObject obj, Color activeColor, string label, bool enabled, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
57+
public static void FastGameobjButton(object _obj, Color activeColor, string label, bool enabled, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
5658
{
59+
var obj = _obj as GameObject ?? (_obj as Transform).gameObject;
60+
5761
if (!obj)
5862
{
5963
GUILayout.Label("<i><color=red>null</color></i>", null);
@@ -83,7 +87,7 @@ public static void FastGameobjButton(GameObject obj, Color activeColor, string l
8387
}
8488
else
8589
{
86-
WindowManager.InspectObject(obj, out bool _);
90+
WindowManager.InspectObject(_obj, out bool _);
8791
}
8892
}
8993

@@ -94,7 +98,7 @@ public static void FastGameobjButton(GameObject obj, Color activeColor, string l
9498

9599
if (showSmallInspectBtn)
96100
{
97-
SmallInspectButton(obj);
101+
SmallInspectButton(_obj);
98102
}
99103

100104
GUILayout.EndHorizontal();

src/Windows/GameObjectWindow.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,16 @@ public override void WindowFunction(int windowID)
175175
GUILayout.Label("Scene: <color=cyan>" + (m_scene == "" ? "n/a" : m_scene) + "</color>", null);
176176
if (m_scene == UnityHelpers.ActiveSceneName)
177177
{
178-
if (GUILayout.Button("<color=#00FF00>< View in Scene Explorer</color>", new GUILayoutOption[] { GUILayout.Width(230) }))
178+
if (GUILayout.Button("<color=#00FF00>Send to Scene View</color>", new GUILayoutOption[] { GUILayout.Width(150) }))
179179
{
180180
ScenePage.Instance.SetTransformTarget(m_object.transform);
181181
MainMenu.SetCurrentPage(0);
182182
}
183183
}
184+
if (GUILayout.Button("Reflection Inspect", new GUILayoutOption[] { GUILayout.Width(150) }))
185+
{
186+
WindowManager.InspectObject(Target, out _, true);
187+
}
184188
GUILayout.EndHorizontal();
185189

186190
GUILayout.BeginHorizontal(null);

src/Windows/WindowManager.cs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,34 +86,50 @@ public void OnGUI()
8686

8787
// ========= Public Helpers =========
8888

89-
public static UIWindow InspectObject(object obj, out bool createdNew)
89+
public static UIWindow InspectObject(object obj, out bool createdNew, bool forceReflection = false)
9090
{
9191
createdNew = false;
9292

93-
UnityEngine.Object uObj = null;
94-
if (obj is UnityEngine.Object)
93+
if (Input.GetKey(KeyCode.LeftShift))
9594
{
96-
uObj = obj as UnityEngine.Object;
95+
forceReflection = true;
9796
}
98-
99-
foreach (var window in Windows)
97+
98+
Il2CppSystem.Object iObj = null;
99+
if (obj is Il2CppSystem.Object isObj)
100100
{
101-
bool equals = ReferenceEquals(obj, window.Target);
101+
iObj = isObj;
102+
}
102103

103-
if (!equals && uObj != null && window.Target is UnityEngine.Object uTarget)
104+
if (!forceReflection)
105+
{
106+
foreach (var window in Windows)
104107
{
105-
equals = uObj.m_CachedPtr == uTarget.m_CachedPtr;
106-
}
108+
bool equals = ReferenceEquals(obj, window.Target);
107109

108-
if (equals)
109-
{
110-
FocusWindow(window);
111-
return window;
110+
if (!equals && iObj is Il2CppSystem.Object iCurrent && window.Target is Il2CppSystem.Object iTarget)
111+
{
112+
if (iCurrent.GetIl2CppType() != iTarget.GetIl2CppType())
113+
{
114+
if (iCurrent is Transform transform)
115+
{
116+
iCurrent = transform.gameObject;
117+
}
118+
}
119+
120+
equals = iCurrent.Pointer == iTarget.Pointer;
121+
}
122+
123+
if (equals)
124+
{
125+
FocusWindow(window);
126+
return window;
127+
}
112128
}
113129
}
114130

115131
createdNew = true;
116-
if (obj is GameObject || obj is Transform)
132+
if (!forceReflection && (obj is GameObject || obj is Transform))
117133
{
118134
return InspectGameObject(obj as GameObject ?? (obj as Transform).gameObject);
119135
}
@@ -144,7 +160,7 @@ private static UIWindow InspectGameObject(GameObject obj)
144160
return new_window;
145161
}
146162

147-
public static UIWindow InspectReflection(object obj)
163+
private static UIWindow InspectReflection(object obj)
148164
{
149165
var new_window = UIWindow.CreateWindow<ReflectionWindow>(obj);
150166
FocusWindow(new_window);

0 commit comments

Comments
 (0)