diff --git a/DebugMod/Canvas/CanvasButton.cs b/DebugMod/Canvas/CanvasButton.cs index 64f98f6..d0d1bdc 100644 --- a/DebugMod/Canvas/CanvasButton.cs +++ b/DebugMod/Canvas/CanvasButton.cs @@ -35,7 +35,8 @@ public CanvasButton(GameObject parent, string name, Texture2D tex, Vector2 pos, buttonTransform.SetScaleX(size.x / bgSubSection.width); buttonTransform.SetScaleY(size.y / bgSubSection.height); - Vector2 position = new Vector2((pos.x + ((size.x / bgSubSection.width) * bgSubSection.width) / 2f) / 1920f, (1080f - (pos.y + ((size.y / bgSubSection.height) * bgSubSection.height) / 2f)) / 1080f); + Vector2 position = new Vector2(pos.x / 1920f, (1080f - pos.y) / 1080f); + buttonTransform.pivot = new Vector2(0f, 1f); buttonTransform.anchorMin = position; buttonTransform.anchorMax = position; @@ -109,7 +110,7 @@ public void SetPosition(Vector2 pos) if (buttonObj != null) { Vector2 sz = buttonObj.GetComponent().sizeDelta; - Vector2 position = new Vector2((pos.x + sz.x / 2f) / 1920f, (1080f - (pos.y + sz.y / 2f)) / 1080f); + Vector2 position = new Vector2(pos.x / 1920f, (1080f - pos.y) / 1080f); buttonObj.GetComponent().anchorMin = position; buttonObj.GetComponent().anchorMax = position; } @@ -137,7 +138,7 @@ public Vector2 GetPosition() Vector2 anchor = buttonObj.GetComponent().anchorMin; Vector2 sz = buttonObj.GetComponent().sizeDelta; - return new Vector2(anchor.x * 1920f - sz.x / 2f, 1080f - anchor.y * 1080f - sz.y / 2f); + return new Vector2(anchor.x * 1920f - sz.x / 2f, 1080f - anchor.y * 1080f); } return Vector2.zero; diff --git a/DebugMod/Canvas/CanvasImage.cs b/DebugMod/Canvas/CanvasImage.cs index f0be601..9f21c4e 100644 --- a/DebugMod/Canvas/CanvasImage.cs +++ b/DebugMod/Canvas/CanvasImage.cs @@ -18,6 +18,8 @@ public CanvasImage(GameObject parent, Texture2D tex, Vector2 pos, Vector2 size, size = new Vector2(subSprite.width, subSprite.height); } + size = StretchSizeIfNecessary(size); + sz = size; sub = subSprite; @@ -33,7 +35,8 @@ public CanvasImage(GameObject parent, Texture2D tex, Vector2 pos, Vector2 size, imageObj.transform.SetParent(parent.transform, false); - Vector2 position = new Vector2((pos.x + ((size.x / subSprite.width) * subSprite.width) / 2f) / 1920f, (1080f - (pos.y + ((size.y / subSprite.height) * subSprite.height) / 2f)) / 1080f); + Vector2 position = new Vector2(pos.x / 1920f, (1080f - pos.y) / 1080f); + imageTransform.pivot = new Vector2(0f, 1f); imageTransform.anchorMin = position; imageTransform.anchorMax = position; imageTransform.SetScaleX(size.x / subSprite.width); @@ -44,6 +47,14 @@ public CanvasImage(GameObject parent, Texture2D tex, Vector2 pos, Vector2 size, active = true; } + private Vector2 StretchSizeIfNecessary(Vector2 size) + { + var standardAspectRatio = 1920f / 1080f; + var resolutionAspectRatio = (float)Screen.width / Screen.height; + var widthScalar = resolutionAspectRatio / standardAspectRatio; + return new Vector2(size.x * widthScalar, size.y); + } + public void UpdateImage(Texture2D tex, Rect subSection) { if (imageObj != null) @@ -74,7 +85,7 @@ public void SetPosition(Vector2 pos) { if (imageObj != null) { - Vector2 position = new Vector2((pos.x + ((sz.x / sub.width) * sub.width) / 2f) / 1920f, (1080f - (pos.y + ((sz.y / sub.height) * sub.height) / 2f)) / 1080f); + Vector2 position = new Vector2(pos.x / 1920f, (1080f - pos.y) / 1080f); imageObj.GetComponent().anchorMin = position; imageObj.GetComponent().anchorMax = position; } diff --git a/DebugMod/Canvas/CanvasText.cs b/DebugMod/Canvas/CanvasText.cs index a16359f..e3fd323 100644 --- a/DebugMod/Canvas/CanvasText.cs +++ b/DebugMod/Canvas/CanvasText.cs @@ -39,7 +39,8 @@ public CanvasText(GameObject parent, Vector2 pos, Vector2 sz, Font font, string textObj.transform.SetParent(parent.transform, false); - Vector2 position = new Vector2((pos.x + size.x / 2f) / 1920f, (1080f - (pos.y + size.y / 2f)) / 1080f); + Vector2 position = new Vector2(pos.x / 1920f, (1080f - pos.y) / 1080f); + textTransform.pivot = new Vector2(0f, 1f); textTransform.anchorMin = position; textTransform.anchorMax = position; @@ -54,7 +55,7 @@ public void SetPosition(Vector2 pos) { RectTransform textTransform = textObj.GetComponent(); - Vector2 position = new Vector2((pos.x + size.x / 2f) / 1920f, (1080f - (pos.y + size.y / 2f)) / 1080f); + Vector2 position = new Vector2(pos.x / 1920f, (1080f - pos.y) / 1080f); textTransform.anchorMin = position; textTransform.anchorMax = position; } @@ -66,7 +67,7 @@ public Vector2 GetPosition() { Vector2 anchor = textObj.GetComponent().anchorMin; - return new Vector2(anchor.x * 1920f - size.x / 2f, 1080f - anchor.y * 1080f - size.y / 2f); + return new Vector2(anchor.x * 1920f, 1080f - anchor.y * 1080f); } return Vector2.zero; diff --git a/DebugMod/GUIController.cs b/DebugMod/GUIController.cs index 56d14a4..173f4df 100644 --- a/DebugMod/GUIController.cs +++ b/DebugMod/GUIController.cs @@ -70,6 +70,8 @@ public void BuildMenus() CanvasScaler scaler = canvas.AddComponent(); scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; scaler.referenceResolution = new Vector2(1920f, 1080f); + scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight; + scaler.matchWidthOrHeight = 1f; canvas.AddComponent(); SaveStatesPanel.BuildMenu(canvas); diff --git a/DebugMod/KeyBindPanel.cs b/DebugMod/KeyBindPanel.cs index 817f556..7e17232 100644 --- a/DebugMod/KeyBindPanel.cs +++ b/DebugMod/KeyBindPanel.cs @@ -95,7 +95,7 @@ public static List FunctionsOnCurrentPage() public const int ItemsPerPage = 11; private static CanvasPanel panel; - + public static KeyCode keyWarning = KeyCode.None; // TODO: Refactor to allow rotating images