예제 #1
0
        /// <summary>
        /// Sets the vertical anchor mode of this RectTransform.
        /// </summary>
        /// <param name="anchorMode">The vertical anchor mode</param>
        public static void SetVerticalAnchor(this RectTransform rectTransform, RectTransformVerticalAnchor anchorMode)
        {
            switch (anchorMode)
            {
            case RectTransformVerticalAnchor.Top:
                rectTransform.anchorMin = new Vector2(rectTransform.anchorMin.x, 1);
                rectTransform.anchorMax = new Vector2(rectTransform.anchorMax.x, 1);
                break;

            case RectTransformVerticalAnchor.Middle:
                rectTransform.anchorMin = new Vector2(rectTransform.anchorMin.x, 0.5f);
                rectTransform.anchorMax = new Vector2(rectTransform.anchorMax.x, 0.5f);
                break;

            case RectTransformVerticalAnchor.Bottom:
                rectTransform.anchorMin = new Vector2(rectTransform.anchorMin.x, 0);
                rectTransform.anchorMax = new Vector2(rectTransform.anchorMax.x, 0);
                break;

            case RectTransformVerticalAnchor.Stretch:
                rectTransform.anchorMin = new Vector2(rectTransform.anchorMin.x, 0);
                rectTransform.anchorMax = new Vector2(rectTransform.anchorMax.x, 1);
                break;
            }
        }
예제 #2
0
 /// <summary>
 /// Sets the vertical and horizontal anchor modes of this RectTransform.
 /// </summary>
 /// <param name="horizontalAnchor">The horizontal anchor mode</param>
 /// <param name="verticalAnchor">The vertical anchor mode</param>
 public static void SetAnchors(this RectTransform rectTransform, RectTransformHorizontalAnchor horizontalAnchor, RectTransformVerticalAnchor verticalAnchor)
 {
     rectTransform.SetHorizontalAnchor(horizontalAnchor);
     rectTransform.SetVerticalAnchor(verticalAnchor);
 }