private void Awake()
 {
     m_transform   = (GetComponent(typeof(Transform)) as Transform);
     m_textMeshPro = (GetComponent(typeof(TextMeshPro)) as TextMeshPro);
     if (m_rect.width == 0f || m_rect.height == 0f)
     {
         if (m_textMeshPro != null && m_textMeshPro.lineLength != 72f)
         {
             Debug.LogWarning("Converting from using anchor and lineLength properties to Text Container.", this);
             m_isDefaultHeight = true;
             int num = (int)(m_anchorPosition = (TextContainerAnchors)m_textMeshPro.anchor);
             m_pivot      = GetPivot(m_anchorPosition);
             m_rect.width = m_textMeshPro.lineLength;
         }
         else
         {
             m_isDefaultWidth  = true;
             m_isDefaultHeight = true;
             m_pivot           = GetPivot(m_anchorPosition);
             m_rect.width      = 0f;
             m_rect.height     = 0f;
         }
         m_margins = new Vector4(0f, 0f, 0f, 0f);
         UpdateCorners();
     }
 }
Esempio n. 2
0
 private void Awake()
 {
     this.m_transform   = (base.GetComponent(typeof(Transform)) as Transform);
     this.m_textMeshPro = (base.GetComponent(typeof(TextMeshPro)) as TextMeshPro);
     if (this.m_rect.width == 0f || this.m_rect.height == 0f)
     {
         if (this.m_textMeshPro != null && this.m_textMeshPro.lineLength != 72f)
         {
             Debug.LogWarning("Converting from using anchor and lineLength properties to Text Container.");
             this.m_isDefaultHeight = true;
             int anchor = (int)this.m_textMeshPro.anchor;
             this.m_anchorPosition = (TextContainerAnchors)anchor;
             this.m_pivot          = this.GetPivot(this.m_anchorPosition);
             this.m_rect.width     = this.m_textMeshPro.lineLength;
         }
         else
         {
             this.m_isDefaultWidth  = true;
             this.m_isDefaultHeight = true;
             this.m_pivot           = this.GetPivot(this.m_anchorPosition);
             this.m_rect.width      = 0f;
             this.m_rect.height     = 0f;
         }
         this.m_margins = new Vector4(0f, 0f, 0f, 0f);
         this.UpdateCorners();
     }
 }
Esempio n. 3
0
        static Vector2f GetTextMeshProPivot(TextContainerAnchors anchor)
        {
            switch (anchor)
            {
            case TextContainerAnchors.TopLeft:
                return(new Vector2f(0, 1));

            case TextContainerAnchors.Top:
                return(new Vector2f(0.5f, 1));

            case TextContainerAnchors.TopRight:
                return(new Vector2f(1, 1));

            case TextContainerAnchors.Left:
                return(new Vector2f(0, 0.5f));

            case TextContainerAnchors.Middle:
                return(new Vector2f(0.5f, 0.5f));

            case TextContainerAnchors.Right:
                return(new Vector2f(1, 0.5f));

            case TextContainerAnchors.BottomLeft:
                return(new Vector2f(0, 0));

            case TextContainerAnchors.Bottom:
                return(new Vector2f(0.5f, 0));

            case TextContainerAnchors.BottomRight:
                return(new Vector2f(1, 0));
            }
            return(Vector2f.Zero);
        }
Esempio n. 4
0
        private Vector2 GetPivot(TextContainerAnchors anchor)
        {
            Vector2 zero = Vector2.zero;

            switch (anchor)
            {
            case TextContainerAnchors.TopLeft:
                return(new Vector2(0f, 1f));

            case TextContainerAnchors.Top:
                return(new Vector2(0.5f, 1f));

            case TextContainerAnchors.TopRight:
                return(new Vector2(1f, 1f));

            case TextContainerAnchors.Left:
                return(new Vector2(0f, 0.5f));

            case TextContainerAnchors.Middle:
                return(new Vector2(0.5f, 0.5f));

            case TextContainerAnchors.Right:
                return(new Vector2(1f, 0.5f));

            case TextContainerAnchors.BottomLeft:
                return(new Vector2(0f, 0f));

            case TextContainerAnchors.Bottom:
                return(new Vector2(0.5f, 0f));

            case TextContainerAnchors.BottomRight:
                return(new Vector2(1f, 0f));
            }
            return(zero);
        }
Esempio n. 5
0
        Vector2 GetPivot(TextContainerAnchors anchor)
        {
            Vector2 pivot = Vector2.zero;

            switch (anchor)
            {
                case TextContainerAnchors.TopLeft:
                    pivot = new Vector2(0, 1);
                    break;
                case TextContainerAnchors.Top:
                    pivot = new Vector2(0.5f, 1);
                    break;
                case TextContainerAnchors.TopRight:
                    pivot = new Vector2(1, 1);
                    break;
                case TextContainerAnchors.Left:
                    pivot = new Vector2(0, 0.5f);
                    break;
                case TextContainerAnchors.Middle:
                    pivot = new Vector2(0.5f, 0.5f);
                    break;
                case TextContainerAnchors.Right:
                    pivot = new Vector2(1, 0.5f);
                    break;
                case TextContainerAnchors.BottomLeft:
                    pivot = new Vector2(0, 0);
                    break;
                case TextContainerAnchors.Bottom:
                    pivot = new Vector2(0.5f, 0);
                    break;
                case TextContainerAnchors.BottomRight:
                    pivot = new Vector2(1, 0);
                    break;
            }

            return pivot;
        }
Esempio n. 6
0
        void Awake()
        {
            m_transform = GetComponent(typeof(Transform)) as Transform; 
            m_textMeshPro = GetComponent(typeof(TextMeshPro)) as TextMeshPro;
            //Debug.Log("TextContainer Awake() called.");
           
            if (m_rect.width == 0 || m_rect.height == 0)
            {
                // Handling of Legacy lineLength property
                if (m_textMeshPro != null && m_textMeshPro.lineLength != 72)
                {
                    Debug.LogWarning("Converting from using anchor and lineLength properties to Text Container.", this);
                    m_isDefaultHeight = true;
                    int anchor = (int)m_textMeshPro.anchor;
                    m_anchorPosition = (TextContainerAnchors)anchor;
                    m_pivot = GetPivot(m_anchorPosition);
                    m_rect.width = m_textMeshPro.lineLength;
                }
                else
                {
                    m_isDefaultWidth = true;
                    m_isDefaultHeight = true;
                    m_pivot = GetPivot(m_anchorPosition);
                    m_rect.width = 0;
                    m_rect.height = 0;
                }

                m_margins = new Vector4(0, 0, 0, 0);
                UpdateCorners();
            }           
        }
Esempio n. 7
0
        protected override void Awake()
        {
            //Debug.Log("TextContainer Awake() called.");

            m_rectTransform = this.rectTransform;
            if (m_rectTransform == null)
            {
                //m_isAddingRectTransform = true;
                m_rectTransform = gameObject.AddComponent<RectTransform>();
                //m_isAddingRectTransform = false;
            }


            m_textMeshPro = GetComponent(typeof(TextMeshPro)) as TextMeshPro;
            
           
            if (m_rect.width == 0 || m_rect.height == 0)
            {
                // Handling of Legacy lineLength property
                if (m_textMeshPro != null && m_textMeshPro.lineLength != 72)
                {
                    Debug.LogWarning("Converting from using anchor and lineLength properties to Text Container.", this);
                    m_isDefaultHeight = true;
                    int anchor = (int)m_textMeshPro.anchor;
                    m_anchorPosition = (TextContainerAnchors)anchor;
                    m_pivot = GetPivot(m_anchorPosition);
                    m_rect.width = m_textMeshPro.lineLength;
                }
                else // if (m_rectTransform.sizeDelta == new Vector2(100, 100))
                {
                    m_isDefaultWidth = true;
                    m_isDefaultHeight = true;
                    m_pivot = GetPivot(m_anchorPosition);
                    m_rect.width = 20;
                    m_rect.height = 5;
                    m_rectTransform.sizeDelta = this.size;
                }

                m_margins = new Vector4(0, 0, 0, 0);
                UpdateCorners();
            }           
        }
        protected override void Awake()
        {
            //Debug.Log("TextContainer Awake() called.");

            m_rectTransform = this.rectTransform;
            if (m_rectTransform == null)
            {
                Vector2 oldPivot = m_pivot;
                m_rectTransform = gameObject.AddComponent<RectTransform>();
                m_pivot = oldPivot;
            }

            m_textMeshPro = GetComponent(typeof(TextMeshPro)) as TextMeshPro;

            if (m_rect.width == 0 || m_rect.height == 0)
            {
                // Handling of Legacy lineLength property
                if (m_textMeshPro != null && m_textMeshPro.anchor != TMP_Compatibility.AnchorPositions.None)
                {
                    Debug.LogWarning("Converting from using anchor and lineLength properties to Text Container.", this);
                    m_isDefaultHeight = true;

                    int anchor = (int)m_textMeshPro.anchor;

                    // Special Handling if Baseline Anchor was used on the old object.
                    if (anchor == 9)
                    {
                        switch (m_textMeshPro.alignment)
                        {
                            case TextAlignmentOptions.TopLeft: // Left
                                m_textMeshPro.alignment = TextAlignmentOptions.BaselineLeft;
                                break;
                            case TextAlignmentOptions.Top: // Center
                                m_textMeshPro.alignment = TextAlignmentOptions.Baseline;
                                break;
                            case TextAlignmentOptions.TopRight: // Right
                                m_textMeshPro.alignment = TextAlignmentOptions.BaselineRight;
                                break;
                            case TextAlignmentOptions.TopJustified: // Left
                                m_textMeshPro.alignment = TextAlignmentOptions.BaselineJustified;
                                break;
                        }

                        anchor = 3; // left
                    }

                    m_anchorPosition = (TextContainerAnchors)anchor;
                    m_pivot = GetPivot(m_anchorPosition);

                    if (m_textMeshPro.lineLength == 72)
                    {
                        m_rect.size = m_textMeshPro.GetPreferredValues(m_textMeshPro.text);
                    }
                    else
                    {
                        m_rect.width = m_textMeshPro.lineLength;
                        m_rect.height = m_textMeshPro.GetPreferredValues(m_rect.width, Mathf.Infinity).y;
                    }
                }
                else // if (m_rectTransform.sizeDelta == new Vector2(100, 100))
                {
                    m_isDefaultWidth = true;
                    m_isDefaultHeight = true;
                    m_pivot = GetPivot(m_anchorPosition);
                    m_rect.width = 20;
                    m_rect.height = 5;
                    m_rectTransform.sizeDelta = this.size;
                }

                m_margins = new Vector4(0, 0, 0, 0);
                UpdateCorners();
            }           
        }