Suggestion: make this program work properly for any or at least: resolutions of 1366 X 766 or more
This is a C# script for Unity engine called uGUI tools made by Senshi
It makes every unity interface UI piece including its childrens fully rescalable with any resolution. (use the first option Anchors to Corners)
I have tested it, it works.
I have configured it.
I do not know what program are you using but Im posting it in case that it might be useful to you.
If yes please read below:
using UnityEditor;
using UnityEngine;
public class uGUITools : MonoBehaviour {
[MenuItem("uGUI/Anchors to Corners %1")]
static void AnchorsToCorners()
{
foreach (Transform trans in Selection.transforms)
{
RectTransform t = trans as RectTransform;
RectTransform pt = trans.parent as RectTransform;
if(t == null || pt == null) return;
Vector2 newAnchorsMin = new Vector2(t.anchorMin.x + t.offsetMin.x / pt.rect.width,
t.anchorMin.y + t.offsetMin.y / pt.rect.height);
Vector2 newAnchorsMax = new Vector2(t.anchorMax.x + t.offsetMax.x / pt.rect.width,
t.anchorMax.y + t.offsetMax.y / pt.rect.height);
t.anchorMin = newAnchorsMin;
t.anchorMax = newAnchorsMax;
t.offsetMin = t.offsetMax = new Vector2(0, 0);
}
}
[MenuItem("uGUI/Corners to Anchors %]")]
static void CornersToAnchors(){
RectTransform t = Selection.activeTransform as RectTransform;
if(t == null) return;
t.offsetMin = t.offsetMax = new Vector2(0, 0);
}
}
this version needs Unity Editor, click on an UI piece and use Editor->AnchorsToCorners to make it work.
Here is a configured "function" version that can be applied to any UI piece created by script at runtime. :
void RuntimeAnchorsToCorners(GameObject InputGo)
{
Transform tempTransform = InputGo.transform;
RectTransform t = tempTransform as RectTransform;
RectTransform pt = tempTransform.parent as RectTransform;
if(t == null || pt == null) return;
Vector2 newAnchorsMin = new Vector2(t.anchorMin.x + t.offsetMin.x / pt.rect.width,
t.anchorMin.y + t.offsetMin.y / pt.rect.height);
Vector2 newAnchorsMax = new Vector2(t.anchorMax.x + t.offsetMax.x / pt.rect.width,
t.anchorMax.y + t.offsetMax.y / pt.rect.height);
t.anchorMin = newAnchorsMin;
t.anchorMax = newAnchorsMax;
t.offsetMin = t.offsetMax = new Vector2(0, 0);
}
an example calling this function:
GameObject /* or var */ aNewButtonCreatedFromScript = .... // code to create a new button or an UI piece;
RuntimeAnchorsToCorners (aNewButtonCreatedFromScript); // needed for every UI piece
Notes for converting it to another engine:
: Vector2 is basically an unity engine (float,float) "struct".
Anchors are points representing UI element positions in 2d screen.
I believe that RectTransform is roughly represented as Top,Left,Right,Bottom properties in 2D.
https://docs.unity3d.com/ScriptReference/RectTransform.htmlIf you think that this solution might be viable I might dig more data about how to convert it for Aurora C.