diff --git a/src/Core/Config/ExplorerConfig.cs b/src/Core/Config/ExplorerConfig.cs index d8b87df..386cf87 100644 --- a/src/Core/Config/ExplorerConfig.cs +++ b/src/Core/Config/ExplorerConfig.cs @@ -135,13 +135,11 @@ namespace UnityExplorer.Core.Config ret.y = float.Parse(split[1], _enCulture); ret.z = float.Parse(split[2], _enCulture); ret.w = float.Parse(split[3], _enCulture); - return ret; } catch { - Window_Anchors = DEFAULT_WINDOW_ANCHORS; - return new Vector4(0.25f, 0.1f, 0.78f, 0.95f); + return DefaultWindowAnchors(); } } @@ -153,7 +151,7 @@ namespace UnityExplorer.Core.Config return string.Format(_enCulture, "{0},{1},{2},{3}", new object[] { rect.anchorMin.x, - rect.anchorMax.y, + rect.anchorMin.y, rect.anchorMax.x, rect.anchorMax.y }); @@ -163,5 +161,11 @@ namespace UnityExplorer.Core.Config return DEFAULT_WINDOW_ANCHORS; } } + + internal static Vector4 DefaultWindowAnchors() + { + Instance.Window_Anchors = DEFAULT_WINDOW_ANCHORS; + return new Vector4(0.25f, 0.1f, 0.78f, 0.95f); + } } } diff --git a/src/UI/Main/MainMenu.cs b/src/UI/Main/MainMenu.cs index 598150e..316df82 100644 --- a/src/UI/Main/MainMenu.cs +++ b/src/UI/Main/MainMenu.cs @@ -151,11 +151,14 @@ namespace UnityExplorer.UI.Main MainPanel = UIFactory.CreatePanel(UIManager.CanvasRoot, "MainMenu", out GameObject content); RectTransform panelRect = MainPanel.GetComponent(); - //panelRect.anchorMin = new Vector2(0.25f, 0.1f); - //panelRect.anchorMax = new Vector2(0.78f, 0.95f); var anchors = ExplorerConfig.Instance.GetWindowAnchorsVector(); - panelRect.anchorMin = new Vector2(anchors.x, anchors.y); - panelRect.anchorMax = new Vector2(anchors.z, anchors.w); + SetPanelAnchors(panelRect, anchors); + + if (panelRect.rect.width < 400 || panelRect.rect.height < 400) + { + anchors = ExplorerConfig.DefaultWindowAnchors(); + SetPanelAnchors(panelRect, anchors); + } MainPanel.AddComponent(); @@ -168,6 +171,12 @@ namespace UnityExplorer.UI.Main new DebugConsole(content); } + private void SetPanelAnchors(RectTransform panelRect, Vector4 anchors) + { + panelRect.anchorMin = new Vector2(anchors.x, anchors.y); + panelRect.anchorMax = new Vector2(anchors.z, anchors.w); + } + private void ConstructTitleBar(GameObject content) { // Core title bar holder