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

Commit cfa4b12

Browse files
committed
3.0.4
see release notes
1 parent c7ccdf3 commit cfa4b12

File tree

12 files changed

+270
-92
lines changed

12 files changed

+270
-92
lines changed

src/ExplorerCore.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
using System;
2+
using System.IO;
3+
using UnityEngine;
4+
using UnityEngine.SceneManagement;
25
using UnityExplorer.Config;
36
using UnityExplorer.Input;
7+
using UnityExplorer.Inspectors;
48
using UnityExplorer.UI;
59
using UnityExplorer.UI.Modules;
6-
using UnityEngine;
7-
using UnityExplorer.Inspectors;
8-
using System.IO;
9-
using UnityExplorer.Unstrip;
10-
using UnityEngine.SceneManagement;
10+
#if CPP
1111
using UnityExplorer.Helpers;
12+
#endif
1213

1314
namespace UnityExplorer
1415
{
1516
public class ExplorerCore
1617
{
1718
public const string NAME = "UnityExplorer";
18-
public const string VERSION = "3.0.3";
19+
public const string VERSION = "3.0.4";
1920
public const string AUTHOR = "Sinai";
2021
public const string GUID = "com.sinai.unityexplorer";
2122
public const string EXPLORER_FOLDER = @"Mods\UnityExplorer";

src/Helpers/Texture2DHelpers.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ private static MethodInfo GetEncodeToPNGMethod()
3535
}
3636
#endif
3737

38-
3938
public static bool IsReadable(this Texture2D tex)
4039
{
4140
try
@@ -68,6 +67,10 @@ public static Texture2D Copy(Texture2D orig, Rect rect) //, bool isDTXnmNormal =
6867
return _newTex;
6968
}
7069

70+
#if CPP
71+
internal delegate void d_Blit2(IntPtr source, IntPtr dest);
72+
#endif
73+
7174
public static Texture2D ForceReadTexture(Texture2D tex)
7275
{
7376
try
@@ -78,7 +81,13 @@ public static Texture2D ForceReadTexture(Texture2D tex)
7881
var rt = RenderTexture.GetTemporary(tex.width, tex.height, 0, RenderTextureFormat.ARGB32);
7982
rt.filterMode = FilterMode.Point;
8083
RenderTexture.active = rt;
84+
85+
#if MONO
8186
Graphics.Blit(tex, rt);
87+
#else
88+
var iCall = ICallHelper.GetICall<d_Blit2>("UnityEngine.Graphics::Blit2");
89+
iCall.Invoke(tex.Pointer, rt.Pointer);
90+
#endif
8291

8392
var _newTex = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false);
8493

src/Inspectors/InspectorManager.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,23 +231,34 @@ private static void ConstructToolbar(GameObject topRowObj)
231231
invisGroup.spacing = 10;
232232

233233
// inspect under mouse button
234+
AddMouseInspectButton(topRowObj, MouseInspector.MouseInspectMode.UI);
235+
AddMouseInspectButton(topRowObj, MouseInspector.MouseInspectMode.World);
236+
}
234237

238+
private static void AddMouseInspectButton(GameObject topRowObj, MouseInspector.MouseInspectMode mode)
239+
{
235240
var inspectObj = UIFactory.CreateButton(topRowObj);
236241
var inspectLayout = inspectObj.AddComponent<LayoutElement>();
237242
inspectLayout.minWidth = 120;
238243
inspectLayout.flexibleWidth = 0;
244+
245+
var inspectText = inspectObj.GetComponentInChildren<Text>();
246+
inspectText.text = "Mouse Inspect";
247+
inspectText.fontSize = 13;
248+
249+
if (mode == MouseInspector.MouseInspectMode.UI)
250+
inspectText.text += " (UI)";
251+
239252
var inspectBtn = inspectObj.GetComponent<Button>();
240253
var inspectColors = inspectBtn.colors;
241254
inspectColors.normalColor = new Color(0.2f, 0.2f, 0.2f);
242255
inspectBtn.colors = inspectColors;
243-
var inspectText = inspectObj.GetComponentInChildren<Text>();
244-
inspectText.text = "Mouse Inspect";
245-
inspectText.fontSize = 13;
246256

247257
inspectBtn.onClick.AddListener(OnInspectMouseClicked);
248258

249259
void OnInspectMouseClicked()
250260
{
261+
MouseInspector.Mode = mode;
251262
MouseInspector.StartInspect();
252263
}
253264
}

src/Inspectors/MouseInspector.cs

Lines changed: 123 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@
33
using System.Linq;
44
using System.Text;
55
using UnityEngine;
6+
using UnityEngine.EventSystems;
67
using UnityEngine.UI;
78
using UnityExplorer.Helpers;
89
using UnityExplorer.Input;
910
using UnityExplorer.UI;
11+
using UnityExplorer.Unstrip;
1012

1113
namespace UnityExplorer.Inspectors
1214
{
1315
public class MouseInspector
1416
{
17+
public enum MouseInspectMode
18+
{
19+
World,
20+
UI
21+
}
22+
1523
public static bool Enabled { get; set; }
1624

17-
//internal static Text s_objUnderMouseName;
25+
public static MouseInspectMode Mode { get; set; }
26+
1827
internal static Text s_objNameLabel;
1928
internal static Text s_objPathLabel;
2029
internal static Text s_mousePosLabel;
@@ -29,6 +38,18 @@ public static void StartInspect()
2938
Enabled = true;
3039
MainMenu.Instance.MainPanel.SetActive(false);
3140
s_UIContent.SetActive(true);
41+
42+
// recache Graphic Raycasters each time we start
43+
var casters = ResourcesUnstrip.FindObjectsOfTypeAll(typeof(GraphicRaycaster));
44+
m_gCasters = new GraphicRaycaster[casters.Length];
45+
for (int i = 0; i < casters.Length; i++)
46+
{
47+
#if CPP
48+
m_gCasters[i] = casters[i].TryCast<GraphicRaycaster>();
49+
#else
50+
m_gCasters[i] = casters[i] as GraphicRaycaster;
51+
#endif
52+
}
3253
}
3354

3455
public static void StopInspect()
@@ -40,49 +61,68 @@ public static void StopInspect()
4061
ClearHitData();
4162
}
4263

64+
internal static GraphicRaycaster[] m_gCasters;
65+
4366
public static void UpdateInspect()
4467
{
4568
if (InputManager.GetKeyDown(KeyCode.Escape))
4669
{
4770
StopInspect();
71+
return;
4872
}
4973

5074
var mousePos = InputManager.MousePosition;
5175

5276
if (mousePos != s_lastMousePos)
53-
{
54-
s_lastMousePos = mousePos;
77+
UpdatePosition(mousePos);
5578

56-
var inversePos = UIManager.CanvasRoot.transform.InverseTransformPoint(mousePos);
79+
if (!UnityHelpers.MainCamera)
80+
return;
5781

58-
s_mousePosLabel.text = $"<color=grey>Mouse Position:</color> {((Vector2)InputManager.MousePosition).ToString()}";
82+
// actual inspect raycast
5983

60-
float yFix = mousePos.y < 120 ? 80 : -80;
84+
switch (Mode)
85+
{
86+
case MouseInspectMode.UI:
87+
RaycastUI(mousePos); break;
88+
case MouseInspectMode.World:
89+
RaycastWorld(mousePos); break;
90+
}
91+
}
6192

62-
s_UIContent.transform.localPosition = new Vector3(inversePos.x, inversePos.y + yFix, 0);
93+
internal static void OnHitGameObject(GameObject obj)
94+
{
95+
if (obj != s_lastHit)
96+
{
97+
s_lastHit = obj;
98+
s_objNameLabel.text = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
99+
s_objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
63100
}
64101

65-
if (!UnityHelpers.MainCamera)
66-
return;
102+
if (InputManager.GetMouseButtonDown(0))
103+
{
104+
StopInspect();
105+
InspectorManager.Instance.Inspect(obj);
106+
}
107+
}
67108

68-
// actual inspect raycast
109+
internal static void RaycastWorld(Vector2 mousePos)
110+
{
69111
var ray = UnityHelpers.MainCamera.ScreenPointToRay(mousePos);
112+
var casts = Physics.RaycastAll(ray, 1000f);
70113

71-
if (Physics.Raycast(ray, out RaycastHit hit, 1000f))
114+
if (casts.Length > 0)
72115
{
73-
var obj = hit.transform.gameObject;
74-
75-
if (obj != s_lastHit)
116+
foreach (var cast in casts)
76117
{
77-
s_lastHit = obj;
78-
s_objNameLabel.text = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
79-
s_objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
80-
}
118+
if (cast.transform)
119+
{
120+
var obj = cast.transform.gameObject;
81121

82-
if (InputManager.GetMouseButtonDown(0))
83-
{
84-
StopInspect();
85-
InspectorManager.Instance.Inspect(obj);
122+
OnHitGameObject(obj);
123+
124+
break;
125+
}
86126
}
87127
}
88128
else
@@ -92,14 +132,64 @@ public static void UpdateInspect()
92132
}
93133
}
94134

135+
internal static void RaycastUI(Vector2 mousePos)
136+
{
137+
var ped = new PointerEventData(null)
138+
{
139+
position = mousePos
140+
};
141+
142+
#if MONO
143+
var list = new List<RaycastResult>();
144+
#else
145+
var list = new Il2CppSystem.Collections.Generic.List<RaycastResult>();
146+
#endif
147+
foreach (var gr in m_gCasters)
148+
{
149+
gr.Raycast(ped, list);
150+
151+
if (list.Count > 0)
152+
{
153+
foreach (var hit in list)
154+
{
155+
if (hit.gameObject)
156+
{
157+
var obj = hit.gameObject;
158+
159+
OnHitGameObject(obj);
160+
161+
break;
162+
}
163+
}
164+
}
165+
else
166+
{
167+
if (s_lastHit)
168+
ClearHitData();
169+
}
170+
}
171+
}
172+
173+
internal static void UpdatePosition(Vector2 mousePos)
174+
{
175+
s_lastMousePos = mousePos;
176+
177+
var inversePos = UIManager.CanvasRoot.transform.InverseTransformPoint(mousePos);
178+
179+
s_mousePosLabel.text = $"<color=grey>Mouse Position:</color> {mousePos.ToString()}";
180+
181+
float yFix = mousePos.y < 120 ? 80 : -80;
182+
s_UIContent.transform.localPosition = new Vector3(inversePos.x, inversePos.y + yFix, 0);
183+
}
184+
95185
internal static void ClearHitData()
96186
{
97187
s_lastHit = null;
98188
s_objNameLabel.text = "No hits...";
99189
s_objPathLabel.text = "";
100190
}
101191

102-
#region UI Construction
192+
#region UI Construction
103193

104194
internal static void ConstructUI()
105195
{
@@ -112,7 +202,10 @@ internal static void ConstructUI()
112202
baseRect.anchorMin = half;
113203
baseRect.anchorMax = half;
114204
baseRect.pivot = half;
115-
baseRect.sizeDelta = new Vector2(700, 100);
205+
baseRect.sizeDelta = new Vector2(700, 150);
206+
207+
var group = content.GetComponent<VerticalLayoutGroup>();
208+
group.childForceExpandHeight = true;
116209

117210
// Title text
118211

@@ -131,13 +224,16 @@ internal static void ConstructUI()
131224

132225
var pathLabelObj = UIFactory.CreateLabel(content, TextAnchor.MiddleLeft);
133226
s_objPathLabel = pathLabelObj.GetComponent<Text>();
134-
s_objPathLabel.color = Color.grey;
135227
s_objPathLabel.fontStyle = FontStyle.Italic;
136-
s_objPathLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
228+
s_objPathLabel.horizontalOverflow = HorizontalWrapMode.Wrap;
229+
230+
var pathLayout = pathLabelObj.AddComponent<LayoutElement>();
231+
pathLayout.minHeight = 75;
232+
pathLayout.flexibleHeight = 0;
137233

138234
s_UIContent.SetActive(false);
139235
}
140236

141-
#endregion
237+
#endregion
142238
}
143239
}

src/Inspectors/Reflection/InteractiveValue/InteractiveEnum.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,7 @@ internal void GetNames()
3737

3838
if (m_subContentConstructed)
3939
{
40-
// changing types, destroy subcontent
41-
for (int i = 0; i < m_subContentParent.transform.childCount; i++)
42-
{
43-
var child = m_subContentParent.transform.GetChild(i);
44-
GameObject.Destroy(child.gameObject);
45-
}
46-
47-
m_subContentConstructed = false;
40+
DestroySubContent();
4841
}
4942

5043
if (!s_enumNamesCache.ContainsKey(type))

0 commit comments

Comments
 (0)