Exemple #1
0
        /// <summary>
        /// The center of the rectangle the two anchors represent, which is the origin that a RectTransform's anchoredPosition is an offset of.
        /// </summary>
        /// <returns>The center of the rectangle the two anchors represent.</returns>
        public static Vector2 AnchorOrigin(MinMax01 anchor)
        {
            float x = anchor.min.x + (anchor.max.x - anchor.min.x) / 2;
            float y = anchor.min.y + (anchor.max.y - anchor.min.y) / 2;

            return(new Vector2(x, y));
        }
Exemple #2
0
 /// <summary>
 /// Sets the normalized position in the parent RectTransform that the corners is anchored to.
 /// </summary>
 public static void SetAnchors(this RectTransform rt, MinMax01 anchors)
 {
     rt.anchorMin = anchors.min;
     rt.anchorMax = anchors.max;
 }
Exemple #3
0
        /// <summary>
        /// Moves the RectTransform relative to an arbitrary anchor point.  This is effectively like setting the anchor, then moving, then setting it back, but does so without potentially getting in the way of anything else.
        /// </summary>
        /// <param name="rt"></param>
        public static void MoveFrom(this RectTransform rt, MinMax01 anchor, float x, float y)
        {
            Vector2 origin = rt.AnchorToParentSpace(AnchorOrigin(anchor) - rt.AnchorOrigin());

            rt.anchoredPosition = new Vector2(origin.x + x, origin.y + y);
        }
Exemple #4
0
 /// <summary>
 /// Moves the RectTransform relative to an arbitrary anchor point.  This is effectively like setting the anchor, then moving, then setting it back, but does so without potentially getting in the way of anything else.
 /// </summary>
 public static void MoveFrom(this RectTransform rt, MinMax01 anchor, Vector2 point)
 {
     rt.MoveFrom(anchor, point.x, point.y);
 }
Exemple #5
0
        /// <summary>
        /// Repositions the requested edge relative to the passed anchor.
        /// </summary>
        /// <param name="anchor">The anchor to get the relative from.</param>
        /// <param name="distance">The distance to be moved to.</param>
        public static void SetBottomFrom(this RectTransform rt, MinMax01 anchor, float distance)
        {
            Vector2 origin = rt.AnchorToParentSpace(anchor.min - rt.anchorMin);

            rt.offsetMin = new Vector2(rt.offsetMin.x, origin.y + distance);
        }
Exemple #6
0
        /// <summary>
        /// Repositions the requested edge relative to the passed anchor.
        /// </summary>
        /// <param name="anchor">The anchor to get the relative from.</param>
        /// <param name="distance">The distance to be moved to.</param>
        public static void SetTopFrom(this RectTransform rt, MinMax01 anchor, float distance)
        {
            Vector2 origin = rt.AnchorToParentSpace(anchor.max - rt.anchorMax);

            rt.offsetMax = new Vector2(rt.offsetMax.x, origin.y + distance);
        }