diff --git a/src/Config/ConfigManager.cs b/src/Config/ConfigManager.cs index c7b898f..ecbc1e7 100644 --- a/src/Config/ConfigManager.cs +++ b/src/Config/ConfigManager.cs @@ -32,6 +32,8 @@ namespace UnityExplorer.Config public static ConfigElement Hide_On_Startup; public static ConfigElement Startup_Delay_Time; public static ConfigElement Reflection_Signature_Blacklist; + public static ConfigElement World_MouseInspect_Keybind; + public static ConfigElement UI_MouseInspect_Keybind; // internal configs internal static InternalConfigHandler InternalHandler { get; private set; } @@ -93,13 +95,18 @@ namespace UnityExplorer.Config "Should UnityExplorer be hidden on startup?", false); + World_MouseInspect_Keybind = new("World Mouse-Inspect Keybind", + "Optional keybind to being a World-mode Mouse Inspect.", + KeyCode.None); + + UI_MouseInspect_Keybind = new("UI Mouse-Inspect Keybind", + "Optional keybind to begin a UI_mode Mouse Inspect.", + KeyCode.None); + Force_Unlock_Mouse = new ConfigElement("Force Unlock Mouse", "Force the Cursor to be unlocked (visible) when the UnityExplorer menu is open.", true); - Force_Unlock_Mouse.OnValueChanged += (bool value) => - { - UniverseLib.Config.ConfigManager.Force_Unlock_Mouse = value; - }; + Force_Unlock_Mouse.OnValueChanged += (bool value) => UniverseLib.Config.ConfigManager.Force_Unlock_Mouse = value; Force_Unlock_Toggle = new ConfigElement("Force Unlock Toggle Key", "The keybind to toggle the 'Force Unlock Mouse' setting. Only usable when UnityExplorer is open.", @@ -108,10 +115,7 @@ namespace UnityExplorer.Config Disable_EventSystem_Override = new ConfigElement("Disable EventSystem override", "If enabled, UnityExplorer will not override the EventSystem from the game.\nMay require restart to take effect.", false); - Disable_EventSystem_Override.OnValueChanged += (bool value) => - { - UniverseLib.Config.ConfigManager.Disable_EventSystem_Override = value; - }; + Disable_EventSystem_Override.OnValueChanged += (bool value) => UniverseLib.Config.ConfigManager.Disable_EventSystem_Override = value; Log_Unity_Debug = new ConfigElement("Log Unity Debug", "Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?", diff --git a/src/Inspectors/InspectUnderMouse.cs b/src/Inspectors/MouseInspector.cs similarity index 89% rename from src/Inspectors/InspectUnderMouse.cs rename to src/Inspectors/MouseInspector.cs index 618ae38..5eacd46 100644 --- a/src/Inspectors/InspectUnderMouse.cs +++ b/src/Inspectors/MouseInspector.cs @@ -13,6 +13,7 @@ using UnityExplorer.UI.Panels; using UniverseLib; using UniverseLib.UI; using UniverseLib.Utility; +using UnityExplorer.Config; namespace UnityExplorer.Inspectors { @@ -22,9 +23,9 @@ namespace UnityExplorer.Inspectors UI } - public class InspectUnderMouse : UIPanel + public class MouseInspector : UIPanel { - public static InspectUnderMouse Instance { get; private set; } + public static MouseInspector Instance { get; private set; } private readonly WorldInspector worldInspector; private readonly UiInspector uiInspector; @@ -58,7 +59,7 @@ namespace UnityExplorer.Inspectors internal Text objPathLabel; internal Text mousePosLabel; - public InspectUnderMouse() + public MouseInspector() { Instance = this; worldInspector = new WorldInspector(); @@ -116,6 +117,26 @@ namespace UnityExplorer.Inspectors private static float timeOfLastRaycast; + public bool TryUpdate() + { + if (ConfigManager.World_MouseInspect_Keybind.Value != KeyCode.None) + { + if (InputManager.GetKeyDown(ConfigManager.World_MouseInspect_Keybind.Value)) + Instance.StartInspect(MouseInspectMode.World); + } + + if (ConfigManager.World_MouseInspect_Keybind.Value != KeyCode.None) + { + if (InputManager.GetKeyDown(ConfigManager.World_MouseInspect_Keybind.Value)) + Instance.StartInspect(MouseInspectMode.World); + } + + if (Inspecting) + UpdateInspect(); + + return Inspecting; + } + public void UpdateInspect() { if (InputManager.GetKeyDown(KeyCode.Escape)) diff --git a/src/Inspectors/MouseInspectors/UiInspector.cs b/src/Inspectors/MouseInspectors/UiInspector.cs index 4e9dfb0..305add2 100644 --- a/src/Inspectors/MouseInspectors/UiInspector.cs +++ b/src/Inspectors/MouseInspectors/UiInspector.cs @@ -26,7 +26,7 @@ namespace UnityExplorer.Inspectors.MouseInspectors public override void OnBeginMouseInspect() { SetupUIRaycast(); - InspectUnderMouse.Instance.objPathLabel.text = ""; + MouseInspector.Instance.objPathLabel.text = ""; } public override void ClearHitData() @@ -70,9 +70,9 @@ namespace UnityExplorer.Inspectors.MouseInspectors } if (currentHitObjects.Any()) - InspectUnderMouse.Instance.objNameLabel.text = $"Click to view UI Objects under mouse: {currentHitObjects.Count}"; + MouseInspector.Instance.objNameLabel.text = $"Click to view UI Objects under mouse: {currentHitObjects.Count}"; else - InspectUnderMouse.Instance.objNameLabel.text = $"No UI objects under mouse."; + MouseInspector.Instance.objNameLabel.text = $"No UI objects under mouse."; } private static void SetupUIRaycast() diff --git a/src/Inspectors/MouseInspectors/WorldInspector.cs b/src/Inspectors/MouseInspectors/WorldInspector.cs index c8fa533..339d48c 100644 --- a/src/Inspectors/MouseInspectors/WorldInspector.cs +++ b/src/Inspectors/MouseInspectors/WorldInspector.cs @@ -41,7 +41,7 @@ namespace UnityExplorer.Inspectors.MouseInspectors if (!MainCamera) { ExplorerCore.LogWarning("No Main Camera was found, unable to inspect world!"); - InspectUnderMouse.Instance.StopInspect(); + MouseInspector.Instance.StopInspect(); return; } @@ -51,7 +51,7 @@ namespace UnityExplorer.Inspectors.MouseInspectors if (hit.transform) OnHitGameObject(hit.transform.gameObject); else if (lastHitObject) - InspectUnderMouse.Instance.ClearHitData(); + MouseInspector.Instance.ClearHitData(); } internal void OnHitGameObject(GameObject obj) @@ -59,8 +59,8 @@ namespace UnityExplorer.Inspectors.MouseInspectors if (obj != lastHitObject) { lastHitObject = obj; - InspectUnderMouse.Instance.objNameLabel.text = $"Click to Inspect: {obj.name}"; - InspectUnderMouse.Instance.objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}"; + MouseInspector.Instance.objNameLabel.text = $"Click to Inspect: {obj.name}"; + MouseInspector.Instance.objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}"; } } diff --git a/src/UI/Panels/InspectorPanel.cs b/src/UI/Panels/InspectorPanel.cs index 46f6db5..cac4965 100644 --- a/src/UI/Panels/InspectorPanel.cs +++ b/src/UI/Panels/InspectorPanel.cs @@ -59,7 +59,7 @@ namespace UnityExplorer.UI.Panels // Inspect under mouse dropdown on title bar var mouseDropdown = UIFactory.CreateDropdown(closeHolder, "MouseInspectDropdown", out MouseInspectDropdown, "Mouse Inspect", 14, - InspectUnderMouse.OnDropdownSelect); + MouseInspector.OnDropdownSelect); UIFactory.SetLayoutElement(mouseDropdown, minHeight: 25, minWidth: 140); MouseInspectDropdown.options.Add(new Dropdown.OptionData("Mouse Inspect")); MouseInspectDropdown.options.Add(new Dropdown.OptionData("World")); diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index 7a171cf..7081d12 100644 --- a/src/UI/UIManager.cs +++ b/src/UI/UIManager.cs @@ -73,7 +73,7 @@ namespace UnityExplorer.UI return; UniversalUI.SetUIActive(ExplorerCore.GUID, value); - UniversalUI.SetUIActive(InspectUnderMouse.UIBaseGUID, value); + UniversalUI.SetUIActive(MouseInspector.UIBaseGUID, value); } } @@ -106,7 +106,7 @@ namespace UnityExplorer.UI UIPanels.Add(Panels.ConsoleLog, new LogPanel()); UIPanels.Add(Panels.Options, new OptionsPanel()); UIPanels.Add(Panels.UIInspectorResults, new UiInspectorResultsPanel()); - UIPanels.Add(Panels.MouseInspector, new InspectUnderMouse()); + UIPanels.Add(Panels.MouseInspector, new MouseInspector()); foreach (var panel in UIPanels.Values) panel.ConstructUI(); @@ -135,12 +135,9 @@ namespace UnityExplorer.UI if (!UIRoot) return; - // if doing Mouse Inspect, update that and return. - if (InspectUnderMouse.Inspecting) - { - InspectUnderMouse.Instance.UpdateInspect(); + // If we are doing a Mouse Inspect, we don't need to update anything else. + if (MouseInspector.Instance.TryUpdate()) return; - } // Update Notification modal Notification.Update(); diff --git a/src/UnityExplorer.csproj b/src/UnityExplorer.csproj index 93814c8..1814bd1 100644 --- a/src/UnityExplorer.csproj +++ b/src/UnityExplorer.csproj @@ -246,7 +246,7 @@ - +