UnityEngine.UI.Text.GetTextAnchorPivot C# (CSharp) Method

GetTextAnchorPivot() public static method

Convenience function to determine the vector offset of the anchor.

public static GetTextAnchorPivot ( TextAnchor anchor ) : Vector2
anchor TextAnchor
return Vector2
        public static Vector2 GetTextAnchorPivot(TextAnchor anchor)
        {
            switch (anchor)
            {
                case TextAnchor.UpperLeft:
                    return new Vector2(0f, 1f);

                case TextAnchor.UpperCenter:
                    return new Vector2(0.5f, 1f);

                case TextAnchor.UpperRight:
                    return new Vector2(1f, 1f);

                case TextAnchor.MiddleLeft:
                    return new Vector2(0f, 0.5f);

                case TextAnchor.MiddleCenter:
                    return new Vector2(0.5f, 0.5f);

                case TextAnchor.MiddleRight:
                    return new Vector2(1f, 0.5f);

                case TextAnchor.LowerLeft:
                    return new Vector2(0f, 0f);

                case TextAnchor.LowerCenter:
                    return new Vector2(0.5f, 0f);

                case TextAnchor.LowerRight:
                    return new Vector2(1f, 0f);
            }
            return Vector2.zero;
        }

Usage Example

コード例 #1
0
        protected override void OnPopulateMesh(VertexHelper toFill)
        {
            if ((UnityEngine.Object) this.font == (UnityEngine.Object)null)
            {
                return;
            }
            this.m_DisableFontTextureRebuiltCallback = true;
            this.cachedTextGenerator.Populate(this.text, this.GetGenerationSettings(this.rectTransform.rect.size));
            Rect    rect            = this.rectTransform.rect;
            Vector2 textAnchorPivot = Text.GetTextAnchorPivot(this.m_FontData.alignment);
            Vector2 zero            = Vector2.zero;

            zero.x = Mathf.Lerp(rect.xMin, rect.xMax, textAnchorPivot.x);
            zero.y = Mathf.Lerp(rect.yMin, rect.yMax, textAnchorPivot.y);
            Vector2          vector2 = this.PixelAdjustPoint(zero) - zero;
            IList <UIVertex> verts   = this.cachedTextGenerator.verts;
            float            num1    = 1f / this.pixelsPerUnit;
            int num2 = verts.Count - 4;

            toFill.Clear();
            if (vector2 != Vector2.zero)
            {
                for (int index1 = 0; index1 < num2; ++index1)
                {
                    int index2 = index1 & 3;
                    this.m_TempVerts[index2]             = verts[index1];
                    this.m_TempVerts[index2].position   *= num1;
                    this.m_TempVerts[index2].position.x += vector2.x;
                    this.m_TempVerts[index2].position.y += vector2.y;
                    if (index2 == 3)
                    {
                        toFill.AddUIVertexQuad(this.m_TempVerts);
                    }
                }
            }
            else
            {
                for (int index1 = 0; index1 < num2; ++index1)
                {
                    int index2 = index1 & 3;
                    this.m_TempVerts[index2]           = verts[index1];
                    this.m_TempVerts[index2].position *= num1;
                    if (index2 == 3)
                    {
                        toFill.AddUIVertexQuad(this.m_TempVerts);
                    }
                }
            }
            this.m_DisableFontTextureRebuiltCallback = false;
        }
All Usage Examples Of UnityEngine.UI.Text::GetTextAnchorPivot