Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions DebugMod/Canvas/CanvasButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -109,7 +110,7 @@ public void SetPosition(Vector2 pos)
if (buttonObj != null)
{
Vector2 sz = buttonObj.GetComponent<RectTransform>().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<RectTransform>().anchorMin = position;
buttonObj.GetComponent<RectTransform>().anchorMax = position;
}
Expand Down Expand Up @@ -137,7 +138,7 @@ public Vector2 GetPosition()
Vector2 anchor = buttonObj.GetComponent<RectTransform>().anchorMin;
Vector2 sz = buttonObj.GetComponent<RectTransform>().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;
Expand Down
15 changes: 13 additions & 2 deletions DebugMod/Canvas/CanvasImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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<RectTransform>().anchorMin = position;
imageObj.GetComponent<RectTransform>().anchorMax = position;
}
Expand Down
7 changes: 4 additions & 3 deletions DebugMod/Canvas/CanvasText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -54,7 +55,7 @@ public void SetPosition(Vector2 pos)
{
RectTransform textTransform = textObj.GetComponent<RectTransform>();

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;
}
Expand All @@ -66,7 +67,7 @@ public Vector2 GetPosition()
{
Vector2 anchor = textObj.GetComponent<RectTransform>().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;
Expand Down
2 changes: 2 additions & 0 deletions DebugMod/GUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public void BuildMenus()
CanvasScaler scaler = canvas.AddComponent<CanvasScaler>();
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
scaler.referenceResolution = new Vector2(1920f, 1080f);
scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;
scaler.matchWidthOrHeight = 1f;
canvas.AddComponent<GraphicRaycaster>();

SaveStatesPanel.BuildMenu(canvas);
Expand Down
2 changes: 1 addition & 1 deletion DebugMod/KeyBindPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static List<string> FunctionsOnCurrentPage()
public const int ItemsPerPage = 11;

private static CanvasPanel panel;

public static KeyCode keyWarning = KeyCode.None;

// TODO: Refactor to allow rotating images
Expand Down