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

Commit 39d9585

Browse files
committed
2.0.4
* Added ability to see and change the layer of a gameobject from the GameObject inspector more easily, and shows you the actual layer name (where possible). * Fixed an issue related to the recently-added clickthrough prevention and resize drag * Fixed write-only properties in the inspector * A few other minor fixes
1 parent 2d414e5 commit 39d9585

File tree

15 files changed

+214
-116
lines changed

15 files changed

+214
-116
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ There is a simple Mod Config for the Explorer. You can access the settings via t
7878
* Whether or not to show the Bitwise Editing helper when inspecting integers
7979

8080
`Enable Tab View` (bool) | Default: `true`
81-
* Whether or not all inspector windows a grouped into a single window with tabs.
81+
* Whether or not all inspector windows a grouped into a single window with tabs.
82+
83+
`Default Output Path` (string) | Default: `Mods\Explorer`
84+
* Where output is generated to, by default (for Texture PNG saving, etc).
8285

8386
## Mouse Control
8487

src/CacheObject/CacheProperty.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,26 @@ public override void UpdateValue()
3535
try
3636
{
3737
var pi = MemInfo as PropertyInfo;
38-
var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance;
3938

40-
IValue.Value = pi.GetValue(target, ParseArguments());
39+
if (pi.CanRead)
40+
{
41+
var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance;
4142

42-
base.UpdateValue();
43+
IValue.Value = pi.GetValue(target, ParseArguments());
44+
45+
base.UpdateValue();
46+
}
47+
else // create a dummy value for Write-Only properties.
48+
{
49+
if (IValue.ValueType == typeof(string))
50+
{
51+
IValue.Value = "";
52+
}
53+
else
54+
{
55+
IValue.Value = Activator.CreateInstance(IValue.ValueType);
56+
}
57+
}
4358
}
4459
catch (Exception e)
4560
{

src/Explorer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@
262262
<Compile Include="UI\WindowBase.cs" />
263263
<Compile Include="UI\WindowManager.cs" />
264264
<Compile Include="Unstrip\ImageConversion\ImageConversionUnstrip.cs" />
265+
<Compile Include="Unstrip\LayerMask\LayerMaskUnstrip.cs" />
265266
<Compile Include="Unstrip\Scene\SceneUnstrip.cs" />
266267
<Compile Include="Unstrip\IMGUI\GUIUnstrip.cs" />
267268
<Compile Include="Unstrip\IMGUI\Internal_LayoutUtility.cs" />

src/ExplorerCore.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Explorer
1010
public class ExplorerCore
1111
{
1212
public const string NAME = "Explorer " + VERSION + " (" + PLATFORM + ", " + MODLOADER + ")";
13-
public const string VERSION = "2.0.3";
13+
public const string VERSION = "2.0.4";
1414
public const string AUTHOR = "Sinai";
1515
public const string GUID = "com.sinai.explorer";
1616

@@ -31,6 +31,12 @@ public class ExplorerCore
3131

3232
public ExplorerCore()
3333
{
34+
if (Instance != null)
35+
{
36+
Log("An instance of Explorer is already active!");
37+
return;
38+
}
39+
3440
Instance = this;
3541

3642
ModConfig.OnLoad();
@@ -87,7 +93,7 @@ public static void OnGUI()
8793
WindowManager.Instance.OnGUI();
8894
InspectUnderMouse.OnGUI();
8995

90-
if (WindowManager.IsMouseInWindow)
96+
if (!ResizeDrag.IsMouseInResizeArea && WindowManager.IsMouseInWindow)
9197
{
9298
InputManager.ResetInputAxes();
9399
}

src/Input/InputManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static void Init()
4444

4545
#if CPP
4646
internal delegate void d_ResetInputAxes();
47-
internal static d_ResetInputAxes ResetInputAxes_iCall =>
47+
internal static d_ResetInputAxes ResetInputAxes_iCall =
4848
IL2CPP.ResolveICall<d_ResetInputAxes>("UnityEngine.Input::ResetInputAxes");
4949

5050
public static void ResetInputAxes() => ResetInputAxes_iCall();

src/Tests/TestClass.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ namespace Explorer.Tests
1515
public static class StaticTestClass
1616
{
1717
public static int StaticProperty => 5;
18-
1918
public static int StaticField = 69;
20-
2119
public static List<string> StaticList = new List<string>
2220
{
2321
"one",
2422
"two",
2523
"three",
2624
};
27-
2825
public static void StaticMethod() { }
2926

3027
}
@@ -34,6 +31,14 @@ public class TestClass
3431
public static TestClass Instance => m_instance ?? (m_instance = new TestClass());
3532
private static TestClass m_instance;
3633

34+
public static bool ReadSetOnlyProperty => m_setOnlyProperty;
35+
36+
public static bool SetOnlyProperty
37+
{
38+
set => m_setOnlyProperty = value;
39+
}
40+
private static bool m_setOnlyProperty;
41+
3742
public Texture2D TestTexture = UIStyles.MakeTex(200, 200, Color.white);
3843
public static Sprite TestSprite;
3944

src/UI/ForceUnlockCursor.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,25 @@ public static bool Unlock
1717
}
1818
private static bool m_forceUnlock;
1919

20+
public static bool ShouldForceMouse => ExplorerCore.ShowMenu && Unlock;
21+
2022
private static CursorLockMode m_lastLockMode;
2123
private static bool m_lastVisibleState;
22-
private static bool m_currentlySettingCursor = false;
2324

24-
public static bool ShouldForceMouse => ExplorerCore.ShowMenu && Unlock;
25+
private static bool m_currentlySettingCursor = false;
2526

26-
private static Type CursorType => m_cursorType ?? (m_cursorType = ReflectionHelpers.GetTypeByName("UnityEngine.Cursor"));
27+
private static Type CursorType
28+
=> m_cursorType
29+
?? (m_cursorType = ReflectionHelpers.GetTypeByName("UnityEngine.Cursor"));
2730
private static Type m_cursorType;
2831

2932
public static void Init()
3033
{
3134
try
3235
{
33-
// Check if Cursor class is loaded
3436
if (CursorType == null)
3537
{
36-
ExplorerCore.Log("Trying to manually load Cursor module...");
37-
38-
if (ReflectionHelpers.LoadModule("UnityEngine.CoreModule") && CursorType != null)
39-
{
40-
ExplorerCore.Log("Ok!");
41-
}
42-
else
43-
{
44-
throw new Exception("Could not load UnityEngine.Cursor module!");
45-
}
38+
throw new Exception("Could not find Type 'UnityEngine.Cursor'!");
4639
}
4740

4841
// Get current cursor state and enable cursor
@@ -91,7 +84,8 @@ private static void TryPatch(string property, HarmonyMethod patch, bool setter)
9184
}
9285
catch (Exception e)
9386
{
94-
ExplorerCore.Log($"[NON-FATAL] Couldn't patch a method: {e.Message}");
87+
string s = setter ? "set_" : "get_" ;
88+
ExplorerCore.Log($"Unable to patch Cursor.{s}{property}: {e.Message}");
9589
}
9690
}
9791

src/UI/Inspectors/GameObjectInspector.cs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine;
44
using Explorer.UI.Shared;
55
using Explorer.UI.Main;
6+
using Explorer.Unstrip.LayerMasks;
67
#if CPP
78
using UnhollowerRuntimeLib;
89
#endif
@@ -17,6 +18,8 @@ public class GameObjectInspector : WindowBase
1718

1819
public GameObject TargetGO;
1920

21+
public bool pendingDestroy;
22+
2023
private static bool m_hideControls;
2124

2225
// gui element holders
@@ -43,6 +46,8 @@ public class GameObjectInspector : WindowBase
4346
private bool m_autoUpdateTransform;
4447
private bool m_localContext;
4548

49+
private int m_layer;
50+
4651
private readonly List<Component> m_cachedDestroyList = new List<Component>();
4752
private string m_addComponentInput = "";
4853

@@ -104,16 +109,16 @@ public override void Update()
104109
{
105110
try
106111
{
112+
if (pendingDestroy) return;
113+
107114
if (Target == null)
108115
{
109-
ExplorerCore.Log("Target is null!");
110-
DestroyWindow();
116+
DestroyOnException(new Exception("Target was destroyed."));
111117
return;
112118
}
113119
if (!TargetGO && !GetObjectAsGameObject())
114120
{
115-
ExplorerCore.Log("Target was destroyed!");
116-
DestroyWindow();
121+
DestroyOnException(new Exception("Target was destroyed."));
117122
return;
118123
}
119124

@@ -132,6 +137,8 @@ public override void Update()
132137
TargetGO.transform.localScale = m_frozenScale;
133138
}
134139

140+
m_layer = TargetGO.layer;
141+
135142
// update child objects
136143
var childList = new List<Transform>();
137144
for (int i = 0; i < TargetGO.transform.childCount; i++)
@@ -163,6 +170,7 @@ public override void Update()
163170
private void DestroyOnException(Exception e)
164171
{
165172
ExplorerCore.Log($"Exception drawing GameObject Window: {e.GetType()}, {e.Message}");
173+
pendingDestroy = true;
166174
DestroyWindow();
167175
}
168176

@@ -204,6 +212,8 @@ private void ReflectObject(object obj)
204212

205213
public override void WindowFunction(int windowID)
206214
{
215+
if (pendingDestroy) return;
216+
207217
try
208218
{
209219
var rect = WindowManager.TabView ? TabViewWindow.Instance.m_rect : this.m_rect;
@@ -250,6 +260,8 @@ public override void WindowFunction(int windowID)
250260
GUIUnstrip.TextArea(m_name, new GUILayoutOption[0]);
251261
GUILayout.EndHorizontal();
252262

263+
LayerControls();
264+
253265
// --- Horizontal Columns section ---
254266
GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]);
255267

@@ -280,6 +292,34 @@ public override void WindowFunction(int windowID)
280292
}
281293
}
282294

295+
private void LayerControls()
296+
{
297+
GUIUnstrip.BeginHorizontal();
298+
GUILayout.Label("Layer:", new GUILayoutOption[] { GUILayout.Width(50) });
299+
300+
if (GUILayout.Button("<", new GUILayoutOption[] { GUILayout.Width(30) }))
301+
{
302+
if (m_layer > 0)
303+
{
304+
m_layer--;
305+
if (TargetGO) TargetGO.layer = m_layer;
306+
}
307+
}
308+
if (GUILayout.Button(">", new GUILayoutOption[] { GUILayout.Width(30) }))
309+
{
310+
if (m_layer < 32)
311+
{
312+
m_layer++;
313+
if (TargetGO) TargetGO.layer = m_layer;
314+
}
315+
}
316+
317+
GUILayout.Label($"{m_layer} (<color=cyan>{LayerMaskUnstrip.LayerToName(m_layer)}</color>)",
318+
new GUILayoutOption[] { GUILayout.Width(200) });
319+
320+
GUILayout.EndHorizontal();
321+
}
322+
283323
private void TransformList(Rect m_rect)
284324
{
285325
GUIUnstrip.BeginVertical(GUIContent.none, GUI.skin.box, null);

src/UI/InteractiveValue/Struct/InteractivePrimitive.cs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ public override void DrawValue(Rect window, float width)
8080

8181
if (OwnerCacheObject.CanWrite)
8282
{
83-
b = GUILayout.Toggle(b, label, new GUILayoutOption[0]);
84-
if (b != (bool)Value)
85-
{
86-
Value = b;
87-
OwnerCacheObject.SetValue();
88-
}
83+
Value = GUILayout.Toggle(b, label, new GUILayoutOption[] { GUILayout.Width(60) });
84+
DrawApplyButton();
85+
//if (b != (bool)Value)
86+
//{
87+
// Value = b;
88+
// OwnerCacheObject.SetValue();
89+
//}
8990
}
9091
else
9192
{
@@ -104,13 +105,8 @@ public override void DrawValue(Rect window, float width)
104105
GUILayout.Label("<color=#2df7b2><i>" + ValueType.Name + "</i></color>", new GUILayoutOption[] { GUILayout.Width(50) });
105106

106107
m_valueToString = GUIUnstrip.TextArea(m_valueToString, new GUILayoutOption[] { GUILayout.ExpandWidth(true) });
107-
if (OwnerCacheObject.CanWrite)
108-
{
109-
if (GUILayout.Button("<color=#00FF00>Apply</color>", new GUILayoutOption[] { GUILayout.Width(60) }))
110-
{
111-
SetValueFromInput();
112-
}
113-
}
108+
109+
DrawApplyButton();
114110

115111
if (ModConfig.Instance.Bitwise_Support && m_canBitwiseOperate)
116112
{
@@ -129,6 +125,24 @@ public override void DrawValue(Rect window, float width)
129125
GUILayout.EndVertical();
130126
}
131127

128+
private void DrawApplyButton()
129+
{
130+
if (OwnerCacheObject.CanWrite)
131+
{
132+
if (GUILayout.Button("<color=#00FF00>Apply</color>", new GUILayoutOption[] { GUILayout.Width(60) }))
133+
{
134+
if (m_isBool)
135+
{
136+
OwnerCacheObject.SetValue();
137+
}
138+
else
139+
{
140+
SetValueFromInput();
141+
}
142+
}
143+
}
144+
}
145+
132146
private void DrawBitwise()
133147
{
134148
if (OwnerCacheObject.CanWrite)

src/UI/Main/OptionsPage.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,36 @@ public override void DrawWindow()
6363
toggleKeyInput.IValue.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f);
6464
GUILayout.EndHorizontal();
6565

66+
UIStyles.HorizontalLine(Color.black, true);
67+
6668
GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]);
6769
GUILayout.Label($"Default Window Size:", new GUILayoutOption[] { GUILayout.Width(215f) });
6870
defaultSizeInput.IValue.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f);
6971
GUILayout.EndHorizontal();
7072

73+
UIStyles.HorizontalLine(Color.black, true);
74+
7175
GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]);
7276
GUILayout.Label($"Default Items per Page:", new GUILayoutOption[] { GUILayout.Width(215f) });
7377
defaultPageLimitInput.IValue.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f);
7478
GUILayout.EndHorizontal();
7579

80+
UIStyles.HorizontalLine(Color.black, true);
81+
7682
GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]);
7783
GUILayout.Label($"Enable Bitwise Editing:", new GUILayoutOption[] { GUILayout.Width(215f) });
7884
bitwiseSupportInput.IValue.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f);
7985
GUILayout.EndHorizontal();
8086

87+
UIStyles.HorizontalLine(Color.black, true);
88+
8189
GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]);
8290
GUILayout.Label($"Enable Tab View:", new GUILayoutOption[] { GUILayout.Width(215f) });
8391
tabViewInput.IValue.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f);
8492
GUILayout.EndHorizontal();
8593

94+
UIStyles.HorizontalLine(Color.black, true);
95+
8696
GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]);
8797
GUILayout.Label($"Default Output Path:", new GUILayoutOption[] { GUILayout.Width(215f) });
8898
defaultOutputPathInput.IValue.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f);

0 commit comments

Comments
 (0)