Add keybinds for Mouse Inspect, small cleanup

This commit is contained in:
Sinai 2022-03-04 00:20:04 +11:00
parent a7165c849c
commit ad8c5293a0
7 changed files with 49 additions and 27 deletions

View File

@ -32,6 +32,8 @@ namespace UnityExplorer.Config
public static ConfigElement<bool> Hide_On_Startup;
public static ConfigElement<float> Startup_Delay_Time;
public static ConfigElement<string> Reflection_Signature_Blacklist;
public static ConfigElement<KeyCode> World_MouseInspect_Keybind;
public static ConfigElement<KeyCode> 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<bool>("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<KeyCode>("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<bool>("Disable EventSystem override",
"If enabled, UnityExplorer will not override the EventSystem from the game.\n<b>May require restart to take effect.</b>",
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<bool>("Log Unity Debug",
"Should UnityEngine.Debug.Log messages be printed to UnityExplorer's log?",

View File

@ -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))

View File

@ -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()

View File

@ -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 = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
InspectUnderMouse.Instance.objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
MouseInspector.Instance.objNameLabel.text = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
MouseInspector.Instance.objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
}
}

View File

@ -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"));

View File

@ -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();

View File

@ -246,7 +246,7 @@
<Compile Include="Inspectors\GameObjectWidgets\ComponentCell.cs" />
<Compile Include="Inspectors\GameObjectWidgets\ComponentList.cs" />
<Compile Include="Inspectors\GameObjectWidgets\GameObjectControls.cs" />
<Compile Include="Inspectors\InspectUnderMouse.cs" />
<Compile Include="Inspectors\MouseInspector.cs" />
<Compile Include="CSConsole\ConsoleController.cs" />
<Compile Include="CacheObject\CacheField.cs" />
<Compile Include="CacheObject\CacheKeyValuePair.cs" />