Ejemplo n.º 1
0
    private string GetFormatedText(UnityEngine.UI.Text textComp, string msg)
    {
        if (string.IsNullOrEmpty(msg))
        {
            return(string.Empty);
        }
        Rect  rect       = this.rectTransform.get_rect();
        float width      = ((Rect) ref rect).get_width();
        float spaceWidth = this.GetSpaceWidth(textComp);

        textComp.set_horizontalOverflow((HorizontalWrapMode)1);
        StringBuilder stringBuilder = new StringBuilder();
        int           num1          = 0;
        float         num2          = 0.0f;
        string        str           = "\n";
        bool          flag1         = HyphenationJpn.CHECK_HYP_BACK(msg[0]);
        bool          flag2         = false;

        foreach (string word in this.GetWordList(msg))
        {
            float num3 = this.GetTextWidth(textComp, word);
            num2 += num3;
            if (word == str)
            {
                num2 = 0.0f + spaceWidth * 2f;
                ++num1;
            }
            else
            {
                if (word == " ")
                {
                    num2 += spaceWidth;
                }
                if (flag1)
                {
                    if (!flag2)
                    {
                        flag2 = this.IsLineCountOver(textComp, num1 + 1);
                    }
                    if (flag2)
                    {
                        num3 = 0.0f;
                    }
                    if ((double)num2 > (double)width - (double)num3)
                    {
                        stringBuilder.Append(str);
                        stringBuilder.Append(" ");
                        num2 = this.GetTextWidth(textComp, word) + spaceWidth * 2f;
                        ++num1;
                    }
                }
                else if ((double)num2 > (double)width)
                {
                    stringBuilder.Append(str);
                    num2 = this.GetTextWidth(textComp, word);
                    ++num1;
                }
            }
            stringBuilder.Append(word);
        }
        return(stringBuilder.ToString());
    }