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

Commit ad8c529

Browse files
committed
Add keybinds for Mouse Inspect, small cleanup
1 parent a7165c8 commit ad8c529

File tree

7 files changed

+49
-27
lines changed

7 files changed

+49
-27
lines changed

src/Config/ConfigManager.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public static class ConfigManager
3232
public static ConfigElement<bool> Hide_On_Startup;
3333
public static ConfigElement<float> Startup_Delay_Time;
3434
public static ConfigElement<string> Reflection_Signature_Blacklist;
35+
public static ConfigElement<KeyCode> World_MouseInspect_Keybind;
36+
public static ConfigElement<KeyCode> UI_MouseInspect_Keybind;
3537

3638
// internal configs
3739
internal static InternalConfigHandler InternalHandler { get; private set; }
@@ -93,13 +95,18 @@ private static void CreateConfigElements()
9395
"Should UnityExplorer be hidden on startup?",
9496
false);
9597

98+
World_MouseInspect_Keybind = new("World Mouse-Inspect Keybind",
99+
"Optional keybind to being a World-mode Mouse Inspect.",
100+
KeyCode.None);
101+
102+
UI_MouseInspect_Keybind = new("UI Mouse-Inspect Keybind",
103+
"Optional keybind to begin a UI_mode Mouse Inspect.",
104+
KeyCode.None);
105+
96106
Force_Unlock_Mouse = new ConfigElement<bool>("Force Unlock Mouse",
97107
"Force the Cursor to be unlocked (visible) when the UnityExplorer menu is open.",
98108
true);
99-
Force_Unlock_Mouse.OnValueChanged += (bool value) =>
100-
{
101-
UniverseLib.Config.ConfigManager.Force_Unlock_Mouse = value;
102-
};
109+
Force_Unlock_Mouse.OnValueChanged += (bool value) => UniverseLib.Config.ConfigManager.Force_Unlock_Mouse = value;
103110

104111
Force_Unlock_Toggle = new ConfigElement<KeyCode>("Force Unlock Toggle Key",
105112
"The keybind to toggle the 'Force Unlock Mouse' setting. Only usable when UnityExplorer is open.",
@@ -108,10 +115,7 @@ private static void CreateConfigElements()
108115
Disable_EventSystem_Override = new ConfigElement<bool>("Disable EventSystem override",
109116
"If enabled, UnityExplorer will not override the EventSystem from the game.\n<b>May require restart to take effect.</b>",
110117
false);
111-
Disable_EventSystem_Override.OnValueChanged += (bool value) =>
112-
{
113-
UniverseLib.Config.ConfigManager.Disable_EventSystem_Override = value;
114-
};
118+
Disable_EventSystem_Override.OnValueChanged += (bool value) => UniverseLib.Config.ConfigManager.Disable_EventSystem_Override = value;
115119

116120
Log_Unity_Debug = new ConfigElement<bool>("Log Unity Debug",
117121
"Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?",

src/Inspectors/InspectUnderMouse.cs renamed to src/Inspectors/MouseInspector.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using UniverseLib;
1414
using UniverseLib.UI;
1515
using UniverseLib.Utility;
16+
using UnityExplorer.Config;
1617

1718
namespace UnityExplorer.Inspectors
1819
{
@@ -22,9 +23,9 @@ public enum MouseInspectMode
2223
UI
2324
}
2425

25-
public class InspectUnderMouse : UIPanel
26+
public class MouseInspector : UIPanel
2627
{
27-
public static InspectUnderMouse Instance { get; private set; }
28+
public static MouseInspector Instance { get; private set; }
2829

2930
private readonly WorldInspector worldInspector;
3031
private readonly UiInspector uiInspector;
@@ -58,7 +59,7 @@ public class InspectUnderMouse : UIPanel
5859
internal Text objPathLabel;
5960
internal Text mousePosLabel;
6061

61-
public InspectUnderMouse()
62+
public MouseInspector()
6263
{
6364
Instance = this;
6465
worldInspector = new WorldInspector();
@@ -116,6 +117,26 @@ public void StopInspect()
116117

117118
private static float timeOfLastRaycast;
118119

120+
public bool TryUpdate()
121+
{
122+
if (ConfigManager.World_MouseInspect_Keybind.Value != KeyCode.None)
123+
{
124+
if (InputManager.GetKeyDown(ConfigManager.World_MouseInspect_Keybind.Value))
125+
Instance.StartInspect(MouseInspectMode.World);
126+
}
127+
128+
if (ConfigManager.World_MouseInspect_Keybind.Value != KeyCode.None)
129+
{
130+
if (InputManager.GetKeyDown(ConfigManager.World_MouseInspect_Keybind.Value))
131+
Instance.StartInspect(MouseInspectMode.World);
132+
}
133+
134+
if (Inspecting)
135+
UpdateInspect();
136+
137+
return Inspecting;
138+
}
139+
119140
public void UpdateInspect()
120141
{
121142
if (InputManager.GetKeyDown(KeyCode.Escape))

src/Inspectors/MouseInspectors/UiInspector.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class UiInspector : MouseInspectorBase
2626
public override void OnBeginMouseInspect()
2727
{
2828
SetupUIRaycast();
29-
InspectUnderMouse.Instance.objPathLabel.text = "";
29+
MouseInspector.Instance.objPathLabel.text = "";
3030
}
3131

3232
public override void ClearHitData()
@@ -70,9 +70,9 @@ public override void UpdateMouseInspect(Vector2 mousePos)
7070
}
7171

7272
if (currentHitObjects.Any())
73-
InspectUnderMouse.Instance.objNameLabel.text = $"Click to view UI Objects under mouse: {currentHitObjects.Count}";
73+
MouseInspector.Instance.objNameLabel.text = $"Click to view UI Objects under mouse: {currentHitObjects.Count}";
7474
else
75-
InspectUnderMouse.Instance.objNameLabel.text = $"No UI objects under mouse.";
75+
MouseInspector.Instance.objNameLabel.text = $"No UI objects under mouse.";
7676
}
7777

7878
private static void SetupUIRaycast()

src/Inspectors/MouseInspectors/WorldInspector.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public override void UpdateMouseInspect(Vector2 mousePos)
4141
if (!MainCamera)
4242
{
4343
ExplorerCore.LogWarning("No Main Camera was found, unable to inspect world!");
44-
InspectUnderMouse.Instance.StopInspect();
44+
MouseInspector.Instance.StopInspect();
4545
return;
4646
}
4747

@@ -51,16 +51,16 @@ public override void UpdateMouseInspect(Vector2 mousePos)
5151
if (hit.transform)
5252
OnHitGameObject(hit.transform.gameObject);
5353
else if (lastHitObject)
54-
InspectUnderMouse.Instance.ClearHitData();
54+
MouseInspector.Instance.ClearHitData();
5555
}
5656

5757
internal void OnHitGameObject(GameObject obj)
5858
{
5959
if (obj != lastHitObject)
6060
{
6161
lastHitObject = obj;
62-
InspectUnderMouse.Instance.objNameLabel.text = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
63-
InspectUnderMouse.Instance.objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
62+
MouseInspector.Instance.objNameLabel.text = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
63+
MouseInspector.Instance.objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
6464
}
6565
}
6666

src/UI/Panels/InspectorPanel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public override void ConstructPanelContent()
5959
// Inspect under mouse dropdown on title bar
6060

6161
var mouseDropdown = UIFactory.CreateDropdown(closeHolder, "MouseInspectDropdown", out MouseInspectDropdown, "Mouse Inspect", 14,
62-
InspectUnderMouse.OnDropdownSelect);
62+
MouseInspector.OnDropdownSelect);
6363
UIFactory.SetLayoutElement(mouseDropdown, minHeight: 25, minWidth: 140);
6464
MouseInspectDropdown.options.Add(new Dropdown.OptionData("Mouse Inspect"));
6565
MouseInspectDropdown.options.Add(new Dropdown.OptionData("World"));

src/UI/UIManager.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static bool ShowMenu
7373
return;
7474

7575
UniversalUI.SetUIActive(ExplorerCore.GUID, value);
76-
UniversalUI.SetUIActive(InspectUnderMouse.UIBaseGUID, value);
76+
UniversalUI.SetUIActive(MouseInspector.UIBaseGUID, value);
7777
}
7878
}
7979

@@ -106,7 +106,7 @@ internal static void InitUI()
106106
UIPanels.Add(Panels.ConsoleLog, new LogPanel());
107107
UIPanels.Add(Panels.Options, new OptionsPanel());
108108
UIPanels.Add(Panels.UIInspectorResults, new UiInspectorResultsPanel());
109-
UIPanels.Add(Panels.MouseInspector, new InspectUnderMouse());
109+
UIPanels.Add(Panels.MouseInspector, new MouseInspector());
110110

111111
foreach (var panel in UIPanels.Values)
112112
panel.ConstructUI();
@@ -135,12 +135,9 @@ public static void Update()
135135
if (!UIRoot)
136136
return;
137137

138-
// if doing Mouse Inspect, update that and return.
139-
if (InspectUnderMouse.Inspecting)
140-
{
141-
InspectUnderMouse.Instance.UpdateInspect();
138+
// If we are doing a Mouse Inspect, we don't need to update anything else.
139+
if (MouseInspector.Instance.TryUpdate())
142140
return;
143-
}
144141

145142
// Update Notification modal
146143
Notification.Update();

src/UnityExplorer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
<Compile Include="Inspectors\GameObjectWidgets\ComponentCell.cs" />
247247
<Compile Include="Inspectors\GameObjectWidgets\ComponentList.cs" />
248248
<Compile Include="Inspectors\GameObjectWidgets\GameObjectControls.cs" />
249-
<Compile Include="Inspectors\InspectUnderMouse.cs" />
249+
<Compile Include="Inspectors\MouseInspector.cs" />
250250
<Compile Include="CSConsole\ConsoleController.cs" />
251251
<Compile Include="CacheObject\CacheField.cs" />
252252
<Compile Include="CacheObject\CacheKeyValuePair.cs" />

0 commit comments

Comments
 (0)