When working with GUI elements I most often find myself setting the anchors (the white arrows pointing inwards) to the corners of the element (the blue dots, not the edge of the screen) so that it scales with screen size. I’ve seen the shortcuts for a bunch of other anchor settings in the RectTransform so I was wondering, is there a shortcut to do this?
@cjdev go here
uGUITools, search for uGUITools, Anchors to corners is the very first function plus there are meny more…
Bit of an old thread but i have added Stretch To Parent too (as found i was doing this often) - and contains a shortcut to basically resetting the object to stretch to parent.
[MenuItem("uGUI/Stretch To Parent %,")]
static void StretchToParent()
{
foreach (Transform transform in Selection.transforms)
{
RectTransform t = transform as RectTransform;
if (t == null) return;
t.anchorMin = new Vector2(0, 0);
t.anchorMax = new Vector2(1, 1);
t.offsetMin = t.offsetMax = new Vector2(0, 0);
}
}
Gwoms answer is great. I created an editor script out of it that also has a default shortcut of Shift+Q.
using UnityEditor;
using UnityEngine;
public class EditorStretchToParent : Editor
{
[MenuItem("uGUI/Stretch To Parent #q")]
static void StretchToParent()
{
foreach (Transform transform in Selection.transforms)
{
RectTransform t = transform as RectTransform;
if (t == null) return;
t.anchorMin = new Vector2(0, 0);
t.anchorMax = new Vector2(1, 1);
t.offsetMin = t.offsetMax = new Vector2(0, 0);
}
}
}
You can change the default shortcut by changing the “'#q” in the MenuItem string.