Skip to content

Instantly share code, notes, and snippets.

@szethh
Created September 3, 2019 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szethh/328520e0bc1684115b4dc65d1663ab99 to your computer and use it in GitHub Desktop.
Save szethh/328520e0bc1684115b4dc65d1663ab99 to your computer and use it in GitHub Desktop.
RectTransformExtensions #unity #ui
public static class RectTransformExtensions
{
public static void SetLeft(this RectTransform rt, float left)
{
rt.offsetMin = new Vector2(left, rt.offsetMin.y);
}
public static void SetRight(this RectTransform rt, float right)
{
rt.offsetMax = new Vector2(-right, rt.offsetMax.y);
}
public static void SetTop(this RectTransform rt, float top)
{
rt.offsetMax = new Vector2(rt.offsetMax.x, -top);
}
public static void SetBottom(this RectTransform rt, float bottom)
{
rt.offsetMin = new Vector2(rt.offsetMin.x, bottom);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment