mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 22:27:45 +08:00
Implement DisplayManager, ability to use other monitors
This commit is contained in:
parent
d730fbe49c
commit
d67507ead2
@ -21,6 +21,7 @@ namespace UnityExplorer.Config
|
|||||||
|
|
||||||
// Actual UE Settings
|
// Actual UE Settings
|
||||||
public static ConfigElement<KeyCode> Master_Toggle;
|
public static ConfigElement<KeyCode> Master_Toggle;
|
||||||
|
public static ConfigElement<int> Target_Display;
|
||||||
public static ConfigElement<UIManager.VerticalAnchor> Main_Navbar_Anchor;
|
public static ConfigElement<UIManager.VerticalAnchor> Main_Navbar_Anchor;
|
||||||
public static ConfigElement<bool> Force_Unlock_Mouse;
|
public static ConfigElement<bool> Force_Unlock_Mouse;
|
||||||
public static ConfigElement<KeyCode> Force_Unlock_Toggle;
|
public static ConfigElement<KeyCode> Force_Unlock_Toggle;
|
||||||
@ -79,6 +80,11 @@ namespace UnityExplorer.Config
|
|||||||
"The key to enable or disable UnityExplorer's menu and features.",
|
"The key to enable or disable UnityExplorer's menu and features.",
|
||||||
KeyCode.F7);
|
KeyCode.F7);
|
||||||
|
|
||||||
|
Target_Display = new ConfigElement<int>("Target Display",
|
||||||
|
"The monitor index for UnityExplorer to use, if you have multiple. 0 is the default display, 1 is secondary, etc. " +
|
||||||
|
"A restart is required to deactivate extra windows.",
|
||||||
|
0);
|
||||||
|
|
||||||
Main_Navbar_Anchor = new ConfigElement<UIManager.VerticalAnchor>("Main Navbar Anchor",
|
Main_Navbar_Anchor = new ConfigElement<UIManager.VerticalAnchor>("Main Navbar Anchor",
|
||||||
"The vertical anchor of the main UnityExplorer Navbar, in case you want to move it.",
|
"The vertical anchor of the main UnityExplorer Navbar, in case you want to move it.",
|
||||||
UIManager.VerticalAnchor.Top);
|
UIManager.VerticalAnchor.Top);
|
||||||
|
@ -16,7 +16,7 @@ namespace UnityExplorer
|
|||||||
public static class ExplorerCore
|
public static class ExplorerCore
|
||||||
{
|
{
|
||||||
public const string NAME = "UnityExplorer";
|
public const string NAME = "UnityExplorer";
|
||||||
public const string VERSION = "4.5.0";
|
public const string VERSION = "4.5.1";
|
||||||
public const string AUTHOR = "Sinai";
|
public const string AUTHOR = "Sinai";
|
||||||
public const string GUID = "com.sinai.unityexplorer";
|
public const string GUID = "com.sinai.unityexplorer";
|
||||||
|
|
||||||
|
@ -31,24 +31,18 @@ namespace UnityExplorer.Inspectors
|
|||||||
public static bool Inspecting { get; set; }
|
public static bool Inspecting { get; set; }
|
||||||
public static MouseInspectMode Mode { get; set; }
|
public static MouseInspectMode Mode { get; set; }
|
||||||
|
|
||||||
|
public MouseInspectorBase CurrentInspector => Mode switch
|
||||||
|
{
|
||||||
|
MouseInspectMode.UI => uiInspector,
|
||||||
|
MouseInspectMode.World => worldInspector,
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
|
||||||
private static Vector3 lastMousePos;
|
private static Vector3 lastMousePos;
|
||||||
|
|
||||||
public MouseInspectorBase CurrentInspector
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
switch (Mode)
|
|
||||||
{
|
|
||||||
case MouseInspectMode.UI:
|
|
||||||
return uiInspector;
|
|
||||||
case MouseInspectMode.World:
|
|
||||||
return worldInspector;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// UIPanel
|
// UIPanel
|
||||||
|
private UIBase inspectorUIBase;
|
||||||
|
|
||||||
public override string Name => "Inspect Under Mouse";
|
public override string Name => "Inspect Under Mouse";
|
||||||
public override UIManager.Panels PanelType => UIManager.Panels.MouseInspector;
|
public override UIManager.Panels PanelType => UIManager.Panels.MouseInspector;
|
||||||
public override int MinWidth => -1;
|
public override int MinWidth => -1;
|
||||||
@ -164,7 +158,7 @@ namespace UnityExplorer.Inspectors
|
|||||||
mousePos.y -= 10;
|
mousePos.y -= 10;
|
||||||
|
|
||||||
// calculate and set our UI position
|
// calculate and set our UI position
|
||||||
var inversePos = UIManager.UIRoot.transform.InverseTransformPoint(mousePos);
|
var inversePos = inspectorUIBase.RootObject.transform.InverseTransformPoint(mousePos);
|
||||||
UIRoot.transform.localPosition = new Vector3(inversePos.x, inversePos.y, 0);
|
UIRoot.transform.localPosition = new Vector3(inversePos.x, inversePos.y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,6 +201,12 @@ namespace UnityExplorer.Inspectors
|
|||||||
UIFactory.SetLayoutElement(objPathLabel.gameObject, minHeight: 75);
|
UIFactory.SetLayoutElement(objPathLabel.gameObject, minHeight: 75);
|
||||||
|
|
||||||
UIRoot.SetActive(false);
|
UIRoot.SetActive(false);
|
||||||
|
|
||||||
|
// Create a new canvas for this panel to live on.
|
||||||
|
// It needs to always be shown on the main display, other panels can move displays.
|
||||||
|
|
||||||
|
inspectorUIBase = UniversalUI.RegisterUI($"{ExplorerCore.GUID}.MouseInspector", null);
|
||||||
|
UIRoot.transform.SetParent(inspectorUIBase.RootObject.transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
59
src/UI/DisplayManager.cs
Normal file
59
src/UI/DisplayManager.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityExplorer.Config;
|
||||||
|
using UniverseLib.Input;
|
||||||
|
|
||||||
|
namespace UnityExplorer.UI
|
||||||
|
{
|
||||||
|
public static class DisplayManager
|
||||||
|
{
|
||||||
|
public static int ActiveDisplayIndex { get; private set; }
|
||||||
|
public static Display ActiveDisplay => Display.displays[ActiveDisplayIndex];
|
||||||
|
|
||||||
|
private static Camera canvasCamera;
|
||||||
|
|
||||||
|
internal static void Init()
|
||||||
|
{
|
||||||
|
SetDisplay(ConfigManager.Target_Display.Value);
|
||||||
|
ConfigManager.Target_Display.OnValueChanged += SetDisplay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 MousePosition => Display.RelativeMouseAt(InputManager.MousePosition);
|
||||||
|
|
||||||
|
public static void SetDisplay(int display)
|
||||||
|
{
|
||||||
|
if (ActiveDisplayIndex == display)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Display.displays.Length <= display)
|
||||||
|
{
|
||||||
|
ExplorerCore.LogWarning($"Cannot set display index to {display} as there are not enough monitors connected!");
|
||||||
|
|
||||||
|
if (ConfigManager.Target_Display.Value == display)
|
||||||
|
ConfigManager.Target_Display.Value = 0;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ActiveDisplayIndex = display;
|
||||||
|
ActiveDisplay.Activate();
|
||||||
|
|
||||||
|
UIManager.UICanvas.targetDisplay = display;
|
||||||
|
|
||||||
|
// ensure a camera is targeting the display
|
||||||
|
if (!Camera.main || Camera.main.targetDisplay != display)
|
||||||
|
{
|
||||||
|
if (!canvasCamera)
|
||||||
|
{
|
||||||
|
canvasCamera = new GameObject("UnityExplorer_CanvasCamera").AddComponent<Camera>();
|
||||||
|
GameObject.DontDestroyOnLoad(canvasCamera.gameObject);
|
||||||
|
canvasCamera.hideFlags = HideFlags.HideAndDontSave;
|
||||||
|
}
|
||||||
|
canvasCamera.targetDisplay = display;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -27,7 +27,7 @@ namespace UnityExplorer.UI
|
|||||||
_currentNotification = message;
|
_currentNotification = message;
|
||||||
_timeOfLastNotification = Time.realtimeSinceStartup;
|
_timeOfLastNotification = Time.realtimeSinceStartup;
|
||||||
|
|
||||||
popupLabel.transform.localPosition = UIManager.UIRootRect.InverseTransformPoint(InputManager.MousePosition) + (Vector3.up * 25);
|
popupLabel.transform.localPosition = UIManager.UIRootRect.InverseTransformPoint(DisplayManager.MousePosition) + (Vector3.up * 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Update()
|
public static void Update()
|
||||||
|
@ -78,7 +78,7 @@ namespace UnityExplorer.UI.Panels
|
|||||||
else
|
else
|
||||||
state = MouseState.NotPressed;
|
state = MouseState.NotPressed;
|
||||||
|
|
||||||
var mousePos = InputManager.MousePosition;
|
var mousePos = DisplayManager.MousePosition;
|
||||||
|
|
||||||
handledInstanceThisFrame = false;
|
handledInstanceThisFrame = false;
|
||||||
foreach (var instance in Instances)
|
foreach (var instance in Instances)
|
||||||
@ -234,12 +234,12 @@ namespace UnityExplorer.UI.Panels
|
|||||||
{
|
{
|
||||||
wasAnyDragging = true;
|
wasAnyDragging = true;
|
||||||
WasDragging = true;
|
WasDragging = true;
|
||||||
lastDragPosition = InputManager.MousePosition;
|
lastDragPosition = DisplayManager.MousePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnDrag()
|
public void OnDrag()
|
||||||
{
|
{
|
||||||
var mousePos = InputManager.MousePosition;
|
var mousePos = DisplayManager.MousePosition;
|
||||||
|
|
||||||
Vector2 diff = (Vector2)mousePos - lastDragPosition;
|
Vector2 diff = (Vector2)mousePos - lastDragPosition;
|
||||||
lastDragPosition = mousePos;
|
lastDragPosition = mousePos;
|
||||||
@ -388,7 +388,7 @@ namespace UnityExplorer.UI.Panels
|
|||||||
// update the resize icon position to be above the mouse
|
// update the resize icon position to be above the mouse
|
||||||
private void UpdateHoverImagePos()
|
private void UpdateHoverImagePos()
|
||||||
{
|
{
|
||||||
resizeCursorObj.transform.localPosition = UIManager.UIRootRect.InverseTransformPoint(InputManager.MousePosition);
|
resizeCursorObj.transform.localPosition = UIManager.UIRootRect.InverseTransformPoint(DisplayManager.MousePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnHoverResizeEnd()
|
public void OnHoverResizeEnd()
|
||||||
@ -400,14 +400,14 @@ namespace UnityExplorer.UI.Panels
|
|||||||
public void OnBeginResize(ResizeTypes resizeType)
|
public void OnBeginResize(ResizeTypes resizeType)
|
||||||
{
|
{
|
||||||
currentResizeType = resizeType;
|
currentResizeType = resizeType;
|
||||||
lastResizePos = InputManager.MousePosition;
|
lastResizePos = DisplayManager.MousePosition;
|
||||||
WasResizing = true;
|
WasResizing = true;
|
||||||
Resizing = true;
|
Resizing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnResize()
|
public void OnResize()
|
||||||
{
|
{
|
||||||
Vector3 mousePos = InputManager.MousePosition;
|
Vector3 mousePos = DisplayManager.MousePosition;
|
||||||
Vector2 diff = lastResizePos - (Vector2)mousePos;
|
Vector2 diff = lastResizePos - (Vector2)mousePos;
|
||||||
|
|
||||||
if ((Vector2)mousePos == lastResizePos)
|
if ((Vector2)mousePos == lastResizePos)
|
||||||
|
@ -35,7 +35,7 @@ namespace UnityExplorer.UI.Panels
|
|||||||
if (InputManager.GetMouseButtonDown(0) || InputManager.GetMouseButtonDown(1))
|
if (InputManager.GetMouseButtonDown(0) || InputManager.GetMouseButtonDown(1))
|
||||||
{
|
{
|
||||||
int count = UIManager.PanelHolder.transform.childCount;
|
int count = UIManager.PanelHolder.transform.childCount;
|
||||||
var mousePos = InputManager.MousePosition;
|
var mousePos = DisplayManager.MousePosition;
|
||||||
bool clickedInAny = false;
|
bool clickedInAny = false;
|
||||||
|
|
||||||
for (int i = count - 1; i >= 0; i--)
|
for (int i = count - 1; i >= 0; i--)
|
||||||
|
@ -1,19 +1,10 @@
|
|||||||
using HarmonyLib;
|
using System.Collections.Generic;
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using UnityExplorer.Config;
|
using UnityExplorer.Config;
|
||||||
using UnityExplorer.CSConsole;
|
using UnityExplorer.CSConsole;
|
||||||
using UnityExplorer.Inspectors;
|
using UnityExplorer.Inspectors;
|
||||||
using UnityExplorer.UI.Panels;
|
using UnityExplorer.UI.Panels;
|
||||||
using UnityExplorer.UI.Widgets;
|
|
||||||
using UnityExplorer.UI.Widgets.AutoComplete;
|
using UnityExplorer.UI.Widgets.AutoComplete;
|
||||||
using UniverseLib;
|
using UniverseLib;
|
||||||
using UniverseLib.Input;
|
using UniverseLib.Input;
|
||||||
@ -48,10 +39,10 @@ namespace UnityExplorer.UI
|
|||||||
|
|
||||||
public static bool Initializing { get; internal set; } = true;
|
public static bool Initializing { get; internal set; } = true;
|
||||||
|
|
||||||
private static UIBase uiBase;
|
internal static UIBase UiBase { get; private set; }
|
||||||
public static GameObject UIRoot => uiBase?.RootObject;
|
public static GameObject UIRoot => UiBase?.RootObject;
|
||||||
public static RectTransform UIRootRect => _uiRootRect ??= UIRoot.GetComponent<RectTransform>();
|
public static RectTransform UIRootRect { get; private set; }
|
||||||
private static RectTransform _uiRootRect;
|
public static Canvas UICanvas { get; private set; }
|
||||||
|
|
||||||
internal static GameObject PanelHolder { get; private set; }
|
internal static GameObject PanelHolder { get; private set; }
|
||||||
private static readonly Dictionary<Panels, UIPanel> UIPanels = new();
|
private static readonly Dictionary<Panels, UIPanel> UIPanels = new();
|
||||||
@ -71,10 +62,10 @@ namespace UnityExplorer.UI
|
|||||||
|
|
||||||
public static bool ShowMenu
|
public static bool ShowMenu
|
||||||
{
|
{
|
||||||
get => uiBase != null && uiBase.Enabled;
|
get => UiBase != null && UiBase.Enabled;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (uiBase == null || !UIRoot || uiBase.Enabled == value)
|
if (UiBase == null || !UIRoot || UiBase.Enabled == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
UniversalUI.SetUIActive(ExplorerCore.GUID, value);
|
UniversalUI.SetUIActive(ExplorerCore.GUID, value);
|
||||||
@ -85,11 +76,16 @@ namespace UnityExplorer.UI
|
|||||||
|
|
||||||
internal static void InitUI()
|
internal static void InitUI()
|
||||||
{
|
{
|
||||||
uiBase = UniversalUI.RegisterUI(ExplorerCore.GUID, Update);
|
UiBase = UniversalUI.RegisterUI(ExplorerCore.GUID, Update);
|
||||||
|
|
||||||
lastScreenWidth = Screen.width;
|
UIRootRect = UIRoot.GetComponent<RectTransform>();
|
||||||
lastScreenHeight = Screen.height;
|
UICanvas = UIRoot.GetComponent<Canvas>();
|
||||||
|
|
||||||
|
DisplayManager.Init();
|
||||||
|
|
||||||
|
var display = DisplayManager.ActiveDisplay;
|
||||||
|
lastScreenWidth = display.renderingWidth;
|
||||||
|
lastScreenHeight = display.renderingHeight;
|
||||||
|
|
||||||
// Create UI.
|
// Create UI.
|
||||||
CreatePanelHolder();
|
CreatePanelHolder();
|
||||||
@ -169,7 +165,8 @@ namespace UnityExplorer.UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check screen dimension change
|
// check screen dimension change
|
||||||
if (Screen.width != lastScreenWidth || Screen.height != lastScreenHeight)
|
var display = DisplayManager.ActiveDisplay;
|
||||||
|
if (display.renderingWidth != lastScreenWidth || display.renderingHeight != lastScreenHeight)
|
||||||
OnScreenDimensionsChanged();
|
OnScreenDimensionsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,8 +230,9 @@ namespace UnityExplorer.UI
|
|||||||
|
|
||||||
private static void OnScreenDimensionsChanged()
|
private static void OnScreenDimensionsChanged()
|
||||||
{
|
{
|
||||||
lastScreenWidth = Screen.width;
|
var display = DisplayManager.ActiveDisplay;
|
||||||
lastScreenHeight = Screen.height;
|
lastScreenWidth = display.renderingWidth;
|
||||||
|
lastScreenHeight = display.renderingHeight;
|
||||||
|
|
||||||
foreach (var panel in UIPanels)
|
foreach (var panel in UIPanels)
|
||||||
{
|
{
|
||||||
@ -254,6 +252,8 @@ namespace UnityExplorer.UI
|
|||||||
closeBtn.ButtonText.text = val.ToString();
|
closeBtn.ButtonText.text = val.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Time controls
|
||||||
|
|
||||||
private static void OnTimeInputEndEdit(string val)
|
private static void OnTimeInputEndEdit(string val)
|
||||||
{
|
{
|
||||||
if (pauseButtonPausing)
|
if (pauseButtonPausing)
|
||||||
|
@ -107,13 +107,13 @@
|
|||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<!-- Non-MelonLoader (it includes Tomlet) -->
|
<!-- Non-MelonLoader (it includes Tomlet) -->
|
||||||
<ItemGroup Condition="'$(IsMelonLoader)'=='false'">
|
<ItemGroup Condition="'$(IsMelonLoader)'=='false'">
|
||||||
<Reference Include="Tomlet, Version=3.1.3.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="Tomlet, Version=3.1.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>packages\Samboy063.Tomlet.3.1.3\lib\net35\Tomlet.dll</HintPath>
|
<HintPath>packages\Samboy063.Tomlet.3.1.3\lib\net35\Tomlet.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<!-- MelonLoader refs -->
|
<!-- MelonLoader refs -->
|
||||||
<ItemGroup Condition="'$(IsMelonLoader)'=='true'">
|
<ItemGroup Condition="'$(IsMelonLoader)'=='true'">
|
||||||
<Reference Include="MelonLoader">
|
<Reference Include="MelonLoader">
|
||||||
@ -259,6 +259,7 @@
|
|||||||
<Compile Include="CacheObject\Views\CacheListEntryCell.cs" />
|
<Compile Include="CacheObject\Views\CacheListEntryCell.cs" />
|
||||||
<Compile Include="CacheObject\Views\CacheMemberCell.cs" />
|
<Compile Include="CacheObject\Views\CacheMemberCell.cs" />
|
||||||
<Compile Include="CacheObject\Views\CacheObjectCell.cs" />
|
<Compile Include="CacheObject\Views\CacheObjectCell.cs" />
|
||||||
|
<Compile Include="UI\DisplayManager.cs" />
|
||||||
<Compile Include="UI\Notification.cs" />
|
<Compile Include="UI\Notification.cs" />
|
||||||
<Compile Include="UI\Panels\ClipboardPanel.cs" />
|
<Compile Include="UI\Panels\ClipboardPanel.cs" />
|
||||||
<Compile Include="UI\Widgets\AutoComplete\EnumCompleter.cs" />
|
<Compile Include="UI\Widgets\AutoComplete\EnumCompleter.cs" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user