mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-01-04 00:23:29 +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
|
||||
public static ConfigElement<KeyCode> Master_Toggle;
|
||||
public static ConfigElement<int> Target_Display;
|
||||
public static ConfigElement<UIManager.VerticalAnchor> Main_Navbar_Anchor;
|
||||
public static ConfigElement<bool> Force_Unlock_Mouse;
|
||||
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.",
|
||||
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",
|
||||
"The vertical anchor of the main UnityExplorer Navbar, in case you want to move it.",
|
||||
UIManager.VerticalAnchor.Top);
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
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;
|
||||
_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()
|
||||
|
@ -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)
|
||||
|
@ -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--)
|
||||
|
@ -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<RectTransform>();
|
||||
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<Panels, UIPanel> 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<RectTransform>();
|
||||
UICanvas = UIRoot.GetComponent<Canvas>();
|
||||
|
||||
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)
|
||||
|
@ -107,13 +107,13 @@
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<!-- Non-MelonLoader (it includes Tomlet) -->
|
||||
<ItemGroup Condition="'$(IsMelonLoader)'=='false'">
|
||||
<Reference Include="Tomlet, Version=3.1.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Samboy063.Tomlet.3.1.3\lib\net35\Tomlet.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<!-- Non-MelonLoader (it includes Tomlet) -->
|
||||
<ItemGroup Condition="'$(IsMelonLoader)'=='false'">
|
||||
<Reference Include="Tomlet, Version=3.1.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Samboy063.Tomlet.3.1.3\lib\net35\Tomlet.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<!-- MelonLoader refs -->
|
||||
<ItemGroup Condition="'$(IsMelonLoader)'=='true'">
|
||||
<Reference Include="MelonLoader">
|
||||
@ -259,6 +259,7 @@
|
||||
<Compile Include="CacheObject\Views\CacheListEntryCell.cs" />
|
||||
<Compile Include="CacheObject\Views\CacheMemberCell.cs" />
|
||||
<Compile Include="CacheObject\Views\CacheObjectCell.cs" />
|
||||
<Compile Include="UI\DisplayManager.cs" />
|
||||
<Compile Include="UI\Notification.cs" />
|
||||
<Compile Include="UI\Panels\ClipboardPanel.cs" />
|
||||
<Compile Include="UI\Widgets\AutoComplete\EnumCompleter.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user