mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 14:17:51 +08:00
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.
This commit is contained in:
parent
42156e1160
commit
217b93ef4f
@ -10,32 +10,9 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
public class CacheGameObject : CacheObjectBase
|
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<GameObject>() ?? ilObj.TryCast<Transform>()?.gameObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_gameObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private GameObject m_gameObject;
|
|
||||||
|
|
||||||
public override void DrawValue(Rect window, float width)
|
public override void DrawValue(Rect window, float width)
|
||||||
{
|
{
|
||||||
UIHelpers.GameobjButton(GameObj, null, false, width);
|
UIHelpers.GameobjButton(Value, null, false, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdateValue()
|
public override void UpdateValue()
|
||||||
|
@ -22,8 +22,10 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// helper for drawing a styled button for a GameObject or Transform
|
// helper for drawing a styled button for a GameObject or Transform
|
||||||
public static void GameobjButton(GameObject obj, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
|
public static void GameobjButton(object _obj, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
|
||||||
{
|
{
|
||||||
|
var obj = (_obj as GameObject) ?? (_obj as Transform).gameObject;
|
||||||
|
|
||||||
bool children = obj.transform.childCount > 0;
|
bool children = obj.transform.childCount > 0;
|
||||||
|
|
||||||
string label = children ? "[" + obj.transform.childCount + " children] " : "";
|
string label = children ? "[" + obj.transform.childCount + " children] " : "";
|
||||||
@ -49,11 +51,13 @@ namespace Explorer
|
|||||||
color = Color.red;
|
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<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
|
public static void FastGameobjButton(object _obj, Color activeColor, string label, bool enabled, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
|
||||||
{
|
{
|
||||||
|
var obj = _obj as GameObject ?? (_obj as Transform).gameObject;
|
||||||
|
|
||||||
if (!obj)
|
if (!obj)
|
||||||
{
|
{
|
||||||
GUILayout.Label("<i><color=red>null</color></i>", null);
|
GUILayout.Label("<i><color=red>null</color></i>", null);
|
||||||
@ -83,7 +87,7 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WindowManager.InspectObject(obj, out bool _);
|
WindowManager.InspectObject(_obj, out bool _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +98,7 @@ namespace Explorer
|
|||||||
|
|
||||||
if (showSmallInspectBtn)
|
if (showSmallInspectBtn)
|
||||||
{
|
{
|
||||||
SmallInspectButton(obj);
|
SmallInspectButton(_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
|
@ -175,12 +175,16 @@ namespace Explorer
|
|||||||
GUILayout.Label("Scene: <color=cyan>" + (m_scene == "" ? "n/a" : m_scene) + "</color>", null);
|
GUILayout.Label("Scene: <color=cyan>" + (m_scene == "" ? "n/a" : m_scene) + "</color>", null);
|
||||||
if (m_scene == UnityHelpers.ActiveSceneName)
|
if (m_scene == UnityHelpers.ActiveSceneName)
|
||||||
{
|
{
|
||||||
if (GUILayout.Button("<color=#00FF00>< View in Scene Explorer</color>", new GUILayoutOption[] { GUILayout.Width(230) }))
|
if (GUILayout.Button("<color=#00FF00>Send to Scene View</color>", new GUILayoutOption[] { GUILayout.Width(150) }))
|
||||||
{
|
{
|
||||||
ScenePage.Instance.SetTransformTarget(m_object.transform);
|
ScenePage.Instance.SetTransformTarget(m_object.transform);
|
||||||
MainMenu.SetCurrentPage(0);
|
MainMenu.SetCurrentPage(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (GUILayout.Button("Reflection Inspect", new GUILayoutOption[] { GUILayout.Width(150) }))
|
||||||
|
{
|
||||||
|
WindowManager.InspectObject(Target, out _, true);
|
||||||
|
}
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
|
@ -86,23 +86,38 @@ namespace Explorer
|
|||||||
|
|
||||||
// ========= Public Helpers =========
|
// ========= 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;
|
createdNew = false;
|
||||||
|
|
||||||
UnityEngine.Object uObj = null;
|
if (Input.GetKey(KeyCode.LeftShift))
|
||||||
if (obj is UnityEngine.Object)
|
|
||||||
{
|
{
|
||||||
uObj = obj as UnityEngine.Object;
|
forceReflection = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Il2CppSystem.Object iObj = null;
|
||||||
|
if (obj is Il2CppSystem.Object isObj)
|
||||||
|
{
|
||||||
|
iObj = isObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!forceReflection)
|
||||||
|
{
|
||||||
foreach (var window in Windows)
|
foreach (var window in Windows)
|
||||||
{
|
{
|
||||||
bool equals = ReferenceEquals(obj, window.Target);
|
bool equals = ReferenceEquals(obj, window.Target);
|
||||||
|
|
||||||
if (!equals && uObj != null && window.Target is UnityEngine.Object uTarget)
|
if (!equals && iObj is Il2CppSystem.Object iCurrent && window.Target is Il2CppSystem.Object iTarget)
|
||||||
{
|
{
|
||||||
equals = uObj.m_CachedPtr == uTarget.m_CachedPtr;
|
if (iCurrent.GetIl2CppType() != iTarget.GetIl2CppType())
|
||||||
|
{
|
||||||
|
if (iCurrent is Transform transform)
|
||||||
|
{
|
||||||
|
iCurrent = transform.gameObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
equals = iCurrent.Pointer == iTarget.Pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (equals)
|
if (equals)
|
||||||
@ -111,9 +126,10 @@ namespace Explorer
|
|||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
createdNew = true;
|
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);
|
return InspectGameObject(obj as GameObject ?? (obj as Transform).gameObject);
|
||||||
}
|
}
|
||||||
@ -144,7 +160,7 @@ namespace Explorer
|
|||||||
return new_window;
|
return new_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UIWindow InspectReflection(object obj)
|
private static UIWindow InspectReflection(object obj)
|
||||||
{
|
{
|
||||||
var new_window = UIWindow.CreateWindow<ReflectionWindow>(obj);
|
var new_window = UIWindow.CreateWindow<ReflectionWindow>(obj);
|
||||||
FocusWindow(new_window);
|
FocusWindow(new_window);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user