참치김밥은 최고의 한식이다

[Unity] RectTransform left, right, top, bottom 값 수정 및 가져오기 본문

Unity

[Unity] RectTransform left, right, top, bottom 값 수정 및 가져오기

l__j__h 2023. 6. 15. 17:22

public static class RectTransformUtils
{
    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);
    }

    public static float GetLeft(this RectTransform rt)
    {
        return rt.offsetMin.x;
    }

    public static float GetBottom(this RectTransform rt)
    {
        return rt.offsetMin.y;
    }
}

728x90