diff --git a/src/Config/ConfigManager.cs b/src/Config/ConfigManager.cs index 4c95aa4..115cdbd 100644 --- a/src/Config/ConfigManager.cs +++ b/src/Config/ConfigManager.cs @@ -21,6 +21,7 @@ namespace UnityExplorer.Config // Actual UE Settings public static ConfigElement Master_Toggle; + public static ConfigElement Target_Display; public static ConfigElement Main_Navbar_Anchor; public static ConfigElement Force_Unlock_Mouse; public static ConfigElement Force_Unlock_Toggle; @@ -79,6 +80,11 @@ namespace UnityExplorer.Config "The key to enable or disable UnityExplorer's menu and features.", KeyCode.F7); + Target_Display = new ConfigElement("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("Main Navbar Anchor", "The vertical anchor of the main UnityExplorer Navbar, in case you want to move it.", UIManager.VerticalAnchor.Top); diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index 44766aa..4497fcd 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -16,7 +16,7 @@ namespace UnityExplorer public static class ExplorerCore { 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 GUID = "com.sinai.unityexplorer"; diff --git a/src/Inspectors/InspectUnderMouse.cs b/src/Inspectors/InspectUnderMouse.cs index 859c0ac..c463014 100644 --- a/src/Inspectors/InspectUnderMouse.cs +++ b/src/Inspectors/InspectUnderMouse.cs @@ -31,24 +31,18 @@ namespace UnityExplorer.Inspectors public static bool Inspecting { get; set; } public static MouseInspectMode Mode { get; set; } + public MouseInspectorBase CurrentInspector => Mode switch + { + MouseInspectMode.UI => uiInspector, + MouseInspectMode.World => worldInspector, + _ => null, + }; + private static Vector3 lastMousePos; - public MouseInspectorBase CurrentInspector - { - get - { - switch (Mode) - { - case MouseInspectMode.UI: - return uiInspector; - case MouseInspectMode.World: - return worldInspector; - } - return null; - } - } - // UIPanel + private UIBase inspectorUIBase; + public override string Name => "Inspect Under Mouse"; public override UIManager.Panels PanelType => UIManager.Panels.MouseInspector; public override int MinWidth => -1; @@ -164,7 +158,7 @@ namespace UnityExplorer.Inspectors mousePos.y -= 10; // 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); } @@ -207,6 +201,12 @@ namespace UnityExplorer.Inspectors UIFactory.SetLayoutElement(objPathLabel.gameObject, minHeight: 75); 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); } } } diff --git a/src/UI/DisplayManager.cs b/src/UI/DisplayManager.cs new file mode 100644 index 0000000..989a179 --- /dev/null +++ b/src/UI/DisplayManager.cs @@ -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(); + GameObject.DontDestroyOnLoad(canvasCamera.gameObject); + canvasCamera.hideFlags = HideFlags.HideAndDontSave; + } + canvasCamera.targetDisplay = display; + } + } + } +} diff --git a/src/UI/Notification.cs b/src/UI/Notification.cs index 32bf929..554c8cc 100644 --- a/src/UI/Notification.cs +++ b/src/UI/Notification.cs @@ -27,7 +27,7 @@ namespace UnityExplorer.UI _currentNotification = message; _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() diff --git a/src/UI/Panels/PanelDragger.cs b/src/UI/Panels/PanelDragger.cs index c7e218a..de3c7d9 100644 --- a/src/UI/Panels/PanelDragger.cs +++ b/src/UI/Panels/PanelDragger.cs @@ -78,7 +78,7 @@ namespace UnityExplorer.UI.Panels else state = MouseState.NotPressed; - var mousePos = InputManager.MousePosition; + var mousePos = DisplayManager.MousePosition; handledInstanceThisFrame = false; foreach (var instance in Instances) @@ -234,12 +234,12 @@ namespace UnityExplorer.UI.Panels { wasAnyDragging = true; WasDragging = true; - lastDragPosition = InputManager.MousePosition; + lastDragPosition = DisplayManager.MousePosition; } public void OnDrag() { - var mousePos = InputManager.MousePosition; + var mousePos = DisplayManager.MousePosition; Vector2 diff = (Vector2)mousePos - lastDragPosition; lastDragPosition = mousePos; @@ -388,7 +388,7 @@ namespace UnityExplorer.UI.Panels // update the resize icon position to be above the mouse private void UpdateHoverImagePos() { - resizeCursorObj.transform.localPosition = UIManager.UIRootRect.InverseTransformPoint(InputManager.MousePosition); + resizeCursorObj.transform.localPosition = UIManager.UIRootRect.InverseTransformPoint(DisplayManager.MousePosition); } public void OnHoverResizeEnd() @@ -400,14 +400,14 @@ namespace UnityExplorer.UI.Panels public void OnBeginResize(ResizeTypes resizeType) { currentResizeType = resizeType; - lastResizePos = InputManager.MousePosition; + lastResizePos = DisplayManager.MousePosition; WasResizing = true; Resizing = true; } public void OnResize() { - Vector3 mousePos = InputManager.MousePosition; + Vector3 mousePos = DisplayManager.MousePosition; Vector2 diff = lastResizePos - (Vector2)mousePos; if ((Vector2)mousePos == lastResizePos) diff --git a/src/UI/Panels/UIPanel.cs b/src/UI/Panels/UIPanel.cs index 5384e58..592fae3 100644 --- a/src/UI/Panels/UIPanel.cs +++ b/src/UI/Panels/UIPanel.cs @@ -35,7 +35,7 @@ namespace UnityExplorer.UI.Panels if (InputManager.GetMouseButtonDown(0) || InputManager.GetMouseButtonDown(1)) { int count = UIManager.PanelHolder.transform.childCount; - var mousePos = InputManager.MousePosition; + var mousePos = DisplayManager.MousePosition; bool clickedInAny = false; for (int i = count - 1; i >= 0; i--) diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index 64cfa38..0fc7b39 100644 --- a/src/UI/UIManager.cs +++ b/src/UI/UIManager.cs @@ -1,19 +1,10 @@ -using HarmonyLib; -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; +using System.Collections.Generic; using UnityEngine; -using UnityEngine.EventSystems; using UnityEngine.UI; using UnityExplorer.Config; using UnityExplorer.CSConsole; using UnityExplorer.Inspectors; using UnityExplorer.UI.Panels; -using UnityExplorer.UI.Widgets; using UnityExplorer.UI.Widgets.AutoComplete; using UniverseLib; using UniverseLib.Input; @@ -48,10 +39,10 @@ namespace UnityExplorer.UI public static bool Initializing { get; internal set; } = true; - private static UIBase uiBase; - public static GameObject UIRoot => uiBase?.RootObject; - public static RectTransform UIRootRect => _uiRootRect ??= UIRoot.GetComponent(); - private static RectTransform _uiRootRect; + internal static UIBase UiBase { get; private set; } + public static GameObject UIRoot => UiBase?.RootObject; + public static RectTransform UIRootRect { get; private set; } + public static Canvas UICanvas { get; private set; } internal static GameObject PanelHolder { get; private set; } private static readonly Dictionary UIPanels = new(); @@ -71,10 +62,10 @@ namespace UnityExplorer.UI public static bool ShowMenu { - get => uiBase != null && uiBase.Enabled; + get => UiBase != null && UiBase.Enabled; set { - if (uiBase == null || !UIRoot || uiBase.Enabled == value) + if (UiBase == null || !UIRoot || UiBase.Enabled == value) return; UniversalUI.SetUIActive(ExplorerCore.GUID, value); @@ -85,11 +76,16 @@ namespace UnityExplorer.UI internal static void InitUI() { - uiBase = UniversalUI.RegisterUI(ExplorerCore.GUID, Update); + UiBase = UniversalUI.RegisterUI(ExplorerCore.GUID, Update); - lastScreenWidth = Screen.width; - lastScreenHeight = Screen.height; + UIRootRect = UIRoot.GetComponent(); + UICanvas = UIRoot.GetComponent(); + DisplayManager.Init(); + + var display = DisplayManager.ActiveDisplay; + lastScreenWidth = display.renderingWidth; + lastScreenHeight = display.renderingHeight; // Create UI. CreatePanelHolder(); @@ -169,7 +165,8 @@ namespace UnityExplorer.UI } // check screen dimension change - if (Screen.width != lastScreenWidth || Screen.height != lastScreenHeight) + var display = DisplayManager.ActiveDisplay; + if (display.renderingWidth != lastScreenWidth || display.renderingHeight != lastScreenHeight) OnScreenDimensionsChanged(); } @@ -233,8 +230,9 @@ namespace UnityExplorer.UI private static void OnScreenDimensionsChanged() { - lastScreenWidth = Screen.width; - lastScreenHeight = Screen.height; + var display = DisplayManager.ActiveDisplay; + lastScreenWidth = display.renderingWidth; + lastScreenHeight = display.renderingHeight; foreach (var panel in UIPanels) { @@ -254,6 +252,8 @@ namespace UnityExplorer.UI closeBtn.ButtonText.text = val.ToString(); } + // Time controls + private static void OnTimeInputEndEdit(string val) { if (pauseButtonPausing) diff --git a/src/UnityExplorer.csproj b/src/UnityExplorer.csproj index ec393cc..b396011 100644 --- a/src/UnityExplorer.csproj +++ b/src/UnityExplorer.csproj @@ -107,13 +107,13 @@ False - - - - packages\Samboy063.Tomlet.3.1.3\lib\net35\Tomlet.dll - False - - + + + + packages\Samboy063.Tomlet.3.1.3\lib\net35\Tomlet.dll + False + + @@ -259,6 +259,7 @@ +