Ejemplo n.º 1
0
        /// <summary>
        /// <para>Set pivot position.</para>
        /// <para>Example : AnchorTo("left-top"); to anchor to the Top Left of the parent RectTransform.</para>
        /// <para>Another Example : AnchorTo("center-center"); to anchor to the Center of the parent RectTransform.</para>
        /// <para>X options : right,center and left.</para>
        /// <para>Y options : top,center and Bottom.</para>
        /// </summary>
        public static void PivotAround(this RectTransform ParamMe, string ParamPivot)
        {
            string[] pivot = ParamPivot.Split('-');

            if (pivot.Length != 2)
            {
                WispVisualComponent.LogError("Invalid pivoting parameters.");
                return;
            }

            float x = 0.5f;
            float y = 0.5f;

            if (pivot[0] == "right")
            {
                x = 1f;
            }
            else if (pivot[0] == "center")
            {
                x = 0.5f;
            }
            else if (pivot[0] == "left")
            {
                x = 0f;
            }
            else if (pivot[0] == "top")
            {
                y = 1f;
            }
            else if (pivot[0] == "center")
            {
                y = 0.5f;
            }
            else if (pivot[0] == "bottom")
            {
                y = 0f;
            }
            else
            {
                WispVisualComponent.LogError("Invalid pivoting parameters.");
                return;
            }

            if (pivot[1] == "top")
            {
                y = 1f;
            }
            else if (pivot[1] == "center")
            {
                y = 0.5f;
            }
            else if (pivot[1] == "bottom")
            {
                y = 0f;
            }
            else if (pivot[1] == "right")
            {
                x = 1f;
            }
            else if (pivot[1] == "center")
            {
                x = 0.5f;
            }
            else if (pivot[1] == "left")
            {
                x = 0f;
            }
            else
            {
                WispVisualComponent.LogError("Invalid pivoting parameters.");
                return;
            }

            ParamMe.pivot = new Vector2(x, y);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <para>Set anchor position.</para>
        /// <para>Example : AnchorTo("left-top"); to anchor to the Top Left of the parent RectTransform.</para>
        /// <para>Another Example : AnchorTo("center-center"); to anchor to the Center of the parent RectTransform.</para>
        /// <para>X options : right,center and left.</para>
        /// <para>Y options : top,center and Bottom.</para>
        /// </summary>
        public static void AnchorTo(this RectTransform ParamMe, string ParamAnchor)
        {
            string[] anchors = ParamAnchor.Split('-');

            if (anchors.Length != 2)
            {
                WispVisualComponent.LogError("Invalid anchoring parameters.");
                return;
            }

            float x = 0.5f;
            float y = 0.5f;

            if (anchors[0] == "right")
            {
                x = 1f;
            }
            else if (anchors[0] == "center")
            {
                x = 0.5f;
            }
            else if (anchors[0] == "left")
            {
                x = 0f;
            }
            else if (anchors[0] == "top")
            {
                y = 1f;
            }
            else if (anchors[0] == "center")
            {
                y = 0.5f;
            }
            else if (anchors[0] == "bottom")
            {
                y = 0f;
            }
            else
            {
                WispVisualComponent.LogError("Invalid anchoring parameters.");
                return;
            }

            if (anchors[1] == "top")
            {
                y = 1f;
            }
            else if (anchors[1] == "center")
            {
                y = 0.5f;
            }
            else if (anchors[1] == "bottom")
            {
                y = 0f;
            }
            else if (anchors[1] == "right")
            {
                x = 1f;
            }
            else if (anchors[1] == "center")
            {
                x = 0.5f;
            }
            else if (anchors[1] == "left")
            {
                x = 0f;
            }
            else
            {
                WispVisualComponent.LogError("Invalid anchoring parameters.");
                return;
            }

            ParamMe.anchorMin = new Vector2(x, y);
            ParamMe.anchorMax = new Vector2(x, y);
        }