diff --git a/src/UI/DisplayManager.cs b/src/UI/DisplayManager.cs index 989a179..a9cdc11 100644 --- a/src/UI/DisplayManager.cs +++ b/src/UI/DisplayManager.cs @@ -13,6 +13,11 @@ namespace UnityExplorer.UI public static int ActiveDisplayIndex { get; private set; } public static Display ActiveDisplay => Display.displays[ActiveDisplayIndex]; + public static int Width => ActiveDisplay.renderingWidth; + public static int Height => ActiveDisplay.renderingHeight; + + public static Vector3 MousePosition => Display.RelativeMouseAt(InputManager.MousePosition); + private static Camera canvasCamera; internal static void Init() @@ -21,8 +26,6 @@ namespace UnityExplorer.UI ConfigManager.Target_Display.OnValueChanged += SetDisplay; } - public static Vector3 MousePosition => Display.RelativeMouseAt(InputManager.MousePosition); - public static void SetDisplay(int display) { if (ActiveDisplayIndex == display) diff --git a/src/UI/Panels/PanelDragger.cs b/src/UI/Panels/PanelDragger.cs index de3c7d9..0ce5700 100644 --- a/src/UI/Panels/PanelDragger.cs +++ b/src/UI/Panels/PanelDragger.cs @@ -260,7 +260,7 @@ namespace UnityExplorer.UI.Panels #region RESIZE - private readonly Dictionary m_resizeMask = new Dictionary + private readonly Dictionary m_resizeMask = new() { { ResizeTypes.Top, default }, { ResizeTypes.Left, default }, @@ -413,13 +413,13 @@ namespace UnityExplorer.UI.Panels if ((Vector2)mousePos == lastResizePos) return; - if (mousePos.x < 0 || mousePos.y < 0 || mousePos.x > Screen.width || mousePos.y > Screen.height) + if (mousePos.x < 0 || mousePos.y < 0 || mousePos.x > DisplayManager.Width || mousePos.y > DisplayManager.Height) return; lastResizePos = mousePos; - float diffX = (float)((decimal)diff.x / Screen.width); - float diffY = (float)((decimal)diff.y / Screen.height); + float diffX = (float)((decimal)diff.x / DisplayManager.Width); + float diffY = (float)((decimal)diff.y / DisplayManager.Height); Vector2 anchorMin = Panel.anchorMin; Vector2 anchorMax = Panel.anchorMax; diff --git a/src/UI/Panels/UIPanel.cs b/src/UI/Panels/UIPanel.cs index 592fae3..e9723f6 100644 --- a/src/UI/Panels/UIPanel.cs +++ b/src/UI/Panels/UIPanel.cs @@ -11,6 +11,7 @@ using UnityExplorer.UI.Widgets; using UniverseLib.UI.Models; using UniverseLib.UI; using UniverseLib; +using System.Collections; namespace UnityExplorer.UI.Panels { @@ -150,8 +151,8 @@ namespace UnityExplorer.UI.Panels var pos = panel.localPosition; // Prevent panel going oustide screen bounds - var halfW = Screen.width * 0.5f; - var halfH = Screen.height * 0.5f; + var halfW = DisplayManager.Width * 0.5f; + var halfH = DisplayManager.Height * 0.5f; pos.x = Math.Max(-halfW - panel.rect.width + 50, Math.Min(pos.x, halfW - 50)); pos.y = Math.Max(-halfH + 50, Math.Min(pos.y, halfH)); @@ -309,14 +310,7 @@ namespace UnityExplorer.UI.Panels SetTransformDefaults(); } - LayoutRebuilder.ForceRebuildLayoutImmediate(this.Rect); - - // ensure initialized position is valid - EnsureValidSize(); - EnsureValidPosition(this.Rect); - - // update dragger and save data - Dragger.OnEndResize(); + RuntimeProvider.Instance.StartCoroutine(LateSetupCoroutine()); // simple listener for saving enabled state this.OnToggleEnabled += (bool val) => @@ -327,6 +321,18 @@ namespace UnityExplorer.UI.Panels ApplyingSaveData = false; } + private IEnumerator LateSetupCoroutine() + { + yield return null; + + // ensure initialized position is valid + EnsureValidSize(); + EnsureValidPosition(this.Rect); + + // update dragger and save data + Dragger.OnEndResize(); + } + public override void ConstructUI(GameObject parent) => ConstructUI(); } @@ -381,7 +387,7 @@ namespace UnityExplorer.UI.Panels return string.Format(CultureInfo.InvariantCulture, "{0},{1}", new object[] { - rect.localPosition.x, rect.localPosition.y + rect.anchoredPosition.x, rect.anchoredPosition.y }); } @@ -399,10 +405,10 @@ namespace UnityExplorer.UI.Panels if (split.Length != 2) throw new Exception($"stringPosition split is unexpected length: {split.Length}"); - Vector3 vector = rect.localPosition; + Vector3 vector = rect.anchoredPosition; vector.x = float.Parse(split[0], CultureInfo.InvariantCulture); vector.y = float.Parse(split[1], CultureInfo.InvariantCulture); - rect.localPosition = vector; + rect.anchoredPosition = vector; } } diff --git a/src/UnityExplorer.csproj b/src/UnityExplorer.csproj index b396011..6a466c0 100644 --- a/src/UnityExplorer.csproj +++ b/src/UnityExplorer.csproj @@ -175,13 +175,13 @@ False - packages\UniverseLib.1.0.6\lib\net35\UniverseLib.Mono.dll + packages\UniverseLib.1.1.0\lib\net35\UniverseLib.Mono.dll - packages\UniverseLib.1.0.6\lib\net472\UniverseLib.IL2CPP.dll + packages\UniverseLib.1.1.0\lib\net472\UniverseLib.IL2CPP.dll ..\lib\Il2CppAssemblyUnhollower\UnhollowerBaseLib\bin\Release\net4.7.2\UnhollowerBaseLib.dll diff --git a/src/packages.config b/src/packages.config index 8f3c0b6..39ec38c 100644 --- a/src/packages.config +++ b/src/packages.config @@ -4,5 +4,5 @@ - + \ No newline at end of file