Created
February 7, 2022 11:55
-
-
Save ertanturan/26a9bb8bfc822d5dc4aa1064a0164a84 to your computer and use it in GitHub Desktop.
Unity UI Real-time anchoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public static class AnchorRealtime | |
{ | |
//------------Top------------------- | |
public static void TopLeft(RectTransform uitransform) | |
{ | |
uitransform.anchorMin = new Vector2(0, 1); | |
uitransform.anchorMax = new Vector2(0, 1); | |
uitransform.pivot = new Vector2(0, 1); | |
} | |
public static void TopMiddle(RectTransform uitransform ) | |
{ | |
uitransform.anchorMin = new Vector2(0.5f, 1); | |
uitransform.anchorMax = new Vector2(0.5f, 1); | |
uitransform.pivot = new Vector2(0.5f, 1); | |
} | |
public static void TopRight(RectTransform uitransform ) | |
{ | |
uitransform.anchorMin = new Vector2(1, 1); | |
uitransform.anchorMax = new Vector2(1, 1); | |
uitransform.pivot = new Vector2(1, 1); | |
} | |
//------------Middle------------------- | |
public static void MiddleLeft(RectTransform uitransform ) | |
{ | |
uitransform.anchorMin = new Vector2(0, 0.5f); | |
uitransform.anchorMax = new Vector2(0, 0.5f); | |
uitransform.pivot = new Vector2(0, 0.5f); | |
} | |
public static void Middle(RectTransform uitransform ) | |
{ | |
uitransform.anchorMin = new Vector2(0.5f, 0.5f); | |
uitransform.anchorMax = new Vector2(0.5f, 0.5f); | |
uitransform.pivot = new Vector2(0.5f, 0.5f); | |
} | |
public static void MiddleRight(RectTransform uitransform ) | |
{ | |
uitransform.anchorMin = new Vector2(1, 0.5f); | |
uitransform.anchorMax = new Vector2(1, 0.5f); | |
uitransform.pivot = new Vector2(1, 0.5f); | |
} | |
//------------Bottom------------------- | |
public static void BottomLeft(RectTransform uitransform ) | |
{ | |
uitransform.anchorMin = new Vector2(0, 0); | |
uitransform.anchorMax = new Vector2(0, 0); | |
uitransform.pivot = new Vector2(0, 0); | |
} | |
public static void BottomMiddle(RectTransform uitransform ) | |
{ | |
uitransform.anchorMin = new Vector2(0.5f, 0); | |
uitransform.anchorMax = new Vector2(0.5f, 0); | |
uitransform.pivot = new Vector2(0.5f, 0); | |
} | |
public static void BottomRight(RectTransform uitransform ) | |
{ | |
uitransform.anchorMin = new Vector2(1, 0); | |
uitransform.anchorMax = new Vector2(1, 0); | |
uitransform.pivot = new Vector2(1, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment