Esempio n. 1
0
    private void RemoveSameAlignData(List <AlignData> alignDatas)
    {
        IList <UILineInfo> lines            = cachedTextGenerator.lines;
        List <AlignData>   removeAlignDatas = new List <AlignData>();

        for (int i = 0; i < alignDatas.Count; i++)
        {
            AlignData alignData = alignDatas[i];


            for (int j = 0; j < lines.Count; j++)
            {
                UILineInfo lInfo = lines[j];
                if (lInfo.startCharIdx <= alignData.startCharIndex)
                {
                    alignData.lineIndex          = j;
                    alignData.lineStartCharIndex = lInfo.startCharIdx;
                    if (j == lines.Count - 1)
                    {
                        if (alignData.startCharIndex > cachedTextGenerator.characterCountVisible)
                        {
                            removeAlignDatas.Add(alignData);
                        }
                        else
                        {
                            alignData.lineEndCharIndex = cachedTextGenerator.characterCountVisible;
                        }
                    }
                }
                else
                {
                    alignData.lineEndCharIndex = lInfo.startCharIdx - 1;
                    break;
                }
            }

            alignDatas[i] = alignData;
        }

        List <int> lineList = new List <int>();

        for (int i = 0; i < alignDatas.Count; i++)
        {
            AlignData alignData = alignDatas[i];
            //Debug.Log("alignData.lineIndex :" + alignData.lineIndex);
            if (lineList.Contains(alignData.lineIndex))
            {
                removeAlignDatas.Add(alignData);
                continue;
            }
            else
            {
                lineList.Add(alignData.lineIndex);
            }
        }
        for (int i = 0; i < removeAlignDatas.Count; i++)
        {
            alignDatas.Remove(removeAlignDatas[i]);
        }
    }
Esempio n. 2
0
 private void CurvedText(VertexHelper toFill)
 {
     if (!IsActive())    //处于未激活状态
     {
         return;
     }
     for (int i = 0; i < cachedTextGenerator.lines.Count; i++)      //遍历所有行
     {
         UILineInfo line = cachedTextGenerator.lines[i];            //当前行
         if (i + 1 < cachedTextGenerator.lines.Count)               //不是最后一行
         {
             UILineInfo line2   = cachedTextGenerator.lines[i + 1]; //下一行
             int        current = 0;                                //一行的第几个字
             //遍历一行所有文字 ,下一行起点为界限
             for (int j = line.startCharIdx; j < line2.startCharIdx - 1; j++)
             {
                 CurvedText(toFill, j, current++, i, line2.startCharIdx - 1 - line.startCharIdx);
             }
         }
         else if (i + 1 == cachedTextGenerator.lines.Count)  //最后一行
         {
             int current = 0;
             for (int j = line.startCharIdx; j < cachedTextGenerator.characterCountVisible; j++)  //总字数为界限
             {
                 int index = current;
                 CurvedText(toFill, j, current++, i, cachedTextGenerator.characterCountVisible - line.startCharIdx);
             }
         }
     }
 }
 public static void DebugUILineInfo(this UILineInfo uILineInfo, string prefixString)
 {
     DLog.Log($"{prefixString}.height: {uILineInfo.height}");
     DLog.Log($"{prefixString}.leading: {uILineInfo.leading}");
     DLog.Log($"{prefixString}.startCharIdx: {uILineInfo.startCharIdx}");
     DLog.Log($"{prefixString}.topY: {uILineInfo.topY}");
 }
Esempio n. 4
0
        void TextChanged()
        {
            var text = TextCom;

            text.text = textInfo.text;
            SetShowText();
            string str = textInfo.buffer.FilterString;

            Populate(text, str);
            var g = text.cachedTextGenerator;

            UIVertex[] vert = new UIVertex[g.verts.Count];
            for (int i = 0; i < vert.Length; i++)
            {
                vert[i] = g.verts[i];
            }
            textInfo.vertex = vert;
            UILineInfo[] us = new UILineInfo[g.lines.Count];
            for (int i = 0; i < us.Length; i++)
            {
                us[i] = g.lines[i];
            }
            textInfo.lines          = us;
            textInfo.characterCount = g.characterCount;
            textInfo.visibleCount   = g.characterCountVisible;
            ChangePoint(textInfo);
            InputCaret.ChangeCaret(textInfo);
        }
Esempio n. 5
0
    static int _CreateUILineInfo(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 0);
        UILineInfo obj = new UILineInfo();

        LuaScriptMgr.PushValue(L, obj);
        return(1);
    }
Esempio n. 6
0
        public override void ModifyMesh(VertexHelper helper)
        {
            if (!IsActive())
            {
                return;
            }

            _text.rectTransform.pivot.Set(0.5f, 0.5f);

            _colSpacing  = _text.fontSize * _text.lineSpacing * colSpacingModifier;
            _charSpacing = _text.fontSize * charSpacingModifier;

            if (textDirection == VerticalTextDirection.RIGHT_LEFT)
            {
                // 从右往左
                _xOffsetFromPivot = _text.rectTransform.rect.width / 2 - _text.fontSize / 2;
                _yOffsetFromPivot = _text.rectTransform.rect.height / 2 - _text.fontSize / 2;
            }
            else
            {
                // 从左往右
                _xOffsetFromPivot = -_text.rectTransform.rect.width / 2 + _text.fontSize / 2;
                _yOffsetFromPivot = _text.rectTransform.rect.height / 2 - _text.fontSize / 2;
            }

            _textGenerator = _text.cachedTextGenerator;
            _lines.Clear();
            _textGenerator.GetLines(_lines);

            for (int i = 0; i < _lines.Count; i++)
            {
                // 遍历每一行文字
                UILineInfo line = _lines[i];

                int rowIdx       = i;
                int rowCharIdx   = 0;
                int totalCharIdx = line.startCharIdx;

                if (i + 1 < _lines.Count)
                {
                    // 如果不是最后一行
                    UILineInfo nextLine = _lines[i + 1];

                    for (; totalCharIdx < nextLine.startCharIdx - 1; totalCharIdx++)
                    {
                        modifyText(helper, totalCharIdx, rowCharIdx++, rowIdx);
                    }
                }
                else if (i + 1 == _lines.Count)
                {
                    // 最后一行
                    for (; totalCharIdx < _textGenerator.characterCountVisible; totalCharIdx++)
                    {
                        modifyText(helper, totalCharIdx, rowCharIdx++, rowIdx);
                    }
                }
            }
        }
    public override void ModifyMesh(VertexHelper helper)
    {
        if (!IsActive())
        {
            return;
        }

        List <UIVertex> verts = new List <UIVertex>();

        helper.GetUIVertexStream(verts);

        Text text = GetComponent <Text>();

        TextGenerator tg = text.cachedTextGenerator;

        lineSpacing = text.fontSize * text.lineSpacing;
        textSpacing = text.fontSize * spacing;

        xOffset = text.rectTransform.sizeDelta.x / 2 - text.fontSize / 2;
        yOffset = text.rectTransform.sizeDelta.y / 2 - text.fontSize / 2;

        List <UILineInfo> lines = new List <UILineInfo>();

        tg.GetLines(lines);

        for (int i = 0; i < lines.Count; i++)
        {
            UILineInfo line = lines[i];

            int step = i;
            if (i + 1 < lines.Count)
            {
                UILineInfo line2 = lines[i + 1];

                int current = 0;

                for (int j = line.startCharIdx; j < line2.startCharIdx - 1; j++)
                {
                    modifyText(helper, j, current++, step);
                }
            }
            else if (i + 1 == lines.Count)
            {
                int current = 0;
                for (int j = line.startCharIdx; j < tg.characterCountVisible; j++)
                {
                    modifyText(helper, j, current++, step);
                }
            }
        }
    }
Esempio n. 8
0
        private float GetLineBottomY(int lineIndex)
        {
            UILineInfo line    = this.lines[lineIndex];
            var        bottomY = line.topY - (lineAlignToMiddle ? line.height * .5f : line.height) - lineOffset;

            // bottomY是原始大小下的信息,但文本在不同分辨率下会被进一步缩放处理,所以要将比例带入计算
            bottomY /= this.text.pixelsPerUnit;

            if (this.useAlign)
            {
                bottomY += lineIndex * this.lineSpace;
            }
            return(bottomY);
        }
Esempio n. 9
0
        protected override void OnPopulateMesh(VertexHelper toFill)
        {
            if (!isActiveAndEnabled)
            {
                return;
            }

            lineSpace = fontSize * lineSpacing;

            textSpace = fontSize * lineSpacing;

            xOffset = rectTransform.sizeDelta.x * 0.5f - fontSize * 0.5f;

            yOffset = rectTransform.sizeDelta.y * 0.5f - fontSize * 0.5f;

            base.OnPopulateMesh(toFill);

            int count = cachedTextGenerator.lines.Count;

            int last = count - 1;

            for (int i = 0; i < count; i++)
            {
                UILineInfo line = cachedTextGenerator.lines[i];

                if (i == last)
                {
                    int current = 0;

                    for (int j = line.startCharIdx; j < cachedTextGenerator.characterCountVisible; j++)
                    {
                        modifyText(toFill, j, current++, i);
                    }
                }
                else
                {
                    UILineInfo next = cachedTextGenerator.lines[i + 1];

                    int current = 0;

                    for (int j = line.startCharIdx; j < next.startCharIdx - 1; j++)
                    {
                        modifyText(toFill, j, current++, i);
                    }
                }
            }
        }
Esempio n. 10
0
    public static int constructor(IntPtr l)
    {
        int result;

        try
        {
            UILineInfo uilineInfo = default(UILineInfo);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, uilineInfo);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Esempio n. 11
0
    public IEnumerable <string> BreakMessageIntoLines(string message)
    {
        generator.Populate(message, console.GetGenerationSettings(console.rectTransform.sizeDelta));
        UILineInfo previousLine = new UILineInfo();
        bool       first        = true;

        foreach (UILineInfo line in generator.lines)
        {
            if (!first)
            {
                int length = line.startCharIdx - previousLine.startCharIdx;
                yield return(message.Substring(previousLine.startCharIdx, length));
            }
            previousLine = line;
            first        = false;
        }

        yield return(message.Substring(previousLine.startCharIdx));
    }
Esempio n. 12
0
 public void FixTextForUI()
 {
     if (!string.IsNullOrEmpty(Text))
     {
         string text = ArabicFixer.Fix(Text, ShowTashkeel, UseHinduNumbers);
         text = text.Replace("\r", string.Empty);
         string   text2 = string.Empty;
         string[] array = text.Split('\n');
         txt.text = string.Empty;
         for (int i = 0; i < array.Length; i++)
         {
             string[] array2 = array[i].Split(' ');
             Array.Reverse(array2);
             txt.text = string.Join(" ", array2);
             Canvas.ForceUpdateCanvases();
             for (int j = 0; j < txt.cachedTextGenerator.lines.Count; j++)
             {
                 UILineInfo uILineInfo   = txt.cachedTextGenerator.lines[j];
                 int        startCharIdx = uILineInfo.startCharIdx;
                 int        num;
                 if (j == txt.cachedTextGenerator.lines.Count - 1)
                 {
                     num = txt.text.Length;
                 }
                 else
                 {
                     UILineInfo uILineInfo2 = txt.cachedTextGenerator.lines[j + 1];
                     num = uILineInfo2.startCharIdx;
                 }
                 int      num2   = num;
                 int      length = num2 - startCharIdx;
                 string[] array3 = txt.text.Substring(startCharIdx, length).Split(' ');
                 Array.Reverse(array3);
                 text2 = text2 + string.Join(" ", array3).Trim() + "\n";
             }
         }
         txt.text = text2.TrimEnd('\n');
     }
     else
     {
         txt.text = string.Empty;
     }
 }
Esempio n. 13
0
        private void VirticalText(VertexHelper toFill)
        {
            if (!IsActive())
            {
                return;
            }

            lineSpace = fontSize * lineSpacing;
            textSpace = fontSize * lineSpacing;

            //xOffset = rectTransform.sizeDelta.x / 2 - fontSize / 2;
            //yOffset = rectTransform.sizeDelta.y / 2 - fontSize / 2;

            xOffset = fontSize / 2;
            yOffset = fontSize / 2;

            for (int i = 0; i < cachedTextGenerator.lines.Count; i++)
            {
                UILineInfo line = cachedTextGenerator.lines[i];

                int step = i;
                if (i + 1 < cachedTextGenerator.lines.Count)
                {
                    UILineInfo line2 = cachedTextGenerator.lines[i + 1];

                    int current = 0;

                    for (int j = line.startCharIdx; j < line2.startCharIdx - 1; j++)
                    {
                        modifyText(toFill, j, current++, step);
                    }
                }
                else if (i + 1 == cachedTextGenerator.lines.Count)
                {
                    int current = 0;
                    for (int j = line.startCharIdx; j < cachedTextGenerator.characterCountVisible; j++)
                    {
                        modifyText(toFill, j, current++, step);
                    }
                }
            }
        }
Esempio n. 14
0
        public static void CropContents()
        {
            instance.text.text = contents;
            List <UILineInfo> list = new List <UILineInfo>();

            for (float preferredHeight = instance.text.preferredHeight; preferredHeight > instance.text.rectTransform.rect.height; preferredHeight = instance.text.preferredHeight)
            {
                instance.text.cachedTextGeneratorForLayout.GetLines(list);
                if (list.Count == 0)
                {
                    break;
                }
                if (list.Count == 1)
                {
                    contents = string.Empty;
                }
                else
                {
                    UILineInfo uILineInfo = list[1];
                    if (uILineInfo.startCharIdx > 0)
                    {
                        string     obj         = contents;
                        UILineInfo uILineInfo2 = list[1];
                        contents = obj.Substring(uILineInfo2.startCharIdx);
                    }
                    else
                    {
                        int num = contents.IndexOf('\n', 0);
                        if (num >= 0)
                        {
                            contents = contents.Substring(num + 1);
                        }
                        else
                        {
                            contents = string.Empty;
                        }
                    }
                }
                instance.text.text = contents;
            }
        }
Esempio n. 15
0
        private void Curved(VertexHelper toFill)
        {
            if (!IsActive())
            {
                return;
            }

            //遍历所有行
            int charIndex = 0;

            //TODO 文本框size不够自动换行的情况没处理
            string[] arrStrLine = text.Split('\n');

            for (int i = 0; i < cachedTextGenerator.lines.Count; i++)
            {
                UILineInfo lineInfo = cachedTextGenerator.lines[i];
                if (i + 1 < cachedTextGenerator.lines.Count)
                {
                    //不是最后一行
                    UILineInfo lineNext     = cachedTextGenerator.lines[i + 1];
                    int        curCharIndex = 0;                                            //一行的第几个字
                    for (int j = lineInfo.startCharIdx; j < lineNext.startCharIdx - 1; j++) //遍历一行所有文字 ,下一行起点为界限
                    {
                        // Curved(toFill, j, curCharIndex++, i, lineNext.startCharIdx - 1 - lineInfo.startCharIdx);
                        Curved(toFill, ref charIndex, curCharIndex++, i, lineNext.startCharIdx - 1 - lineInfo.startCharIdx, arrStrLine[i]);
                    }
                }
                else
                {
                    int curCharIndex = 0;//一行的第几个字
                    for (int j = lineInfo.startCharIdx; j < cachedTextGenerator.characterCountVisible; j++)
                    {
                        // Curved(toFill, j, curCharIndex++, i, cachedTextGenerator.characterCountVisible - lineInfo.startCharIdx);
                        Curved(toFill, ref charIndex, curCharIndex++, i, cachedTextGenerator.characterCountVisible - lineInfo.startCharIdx, arrStrLine[i]);
                    }
                }
            }
        }
Esempio n. 16
0
    static int get_height(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name height");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index height on a nil value");
            }
        }

        UILineInfo obj = (UILineInfo)o;

        LuaScriptMgr.Push(L, obj.height);
        return(1);
    }
Esempio n. 17
0
        private string[] GetLines()
        {
            IList <UILineInfo> lineInfos = text.cachedTextGenerator.lines;

            string[] lines = new string[lineInfos.Count];

            for (int i = 0; i < lineInfos.Count; i++)
            {
                if (i < (lineInfos.Count - 1))
                {
                    UILineInfo nextLine  = lineInfos[i + 1];
                    int        lineStart = lineInfos[i].startCharIdx;
                    int        length    = (nextLine.startCharIdx - 1) - lineStart;

                    lines[i] = this.text.text.Substring(lineInfos[i].startCharIdx, length);
                }
                else
                {
                    lines[i] = this.text.text.Substring(lineInfos[i].startCharIdx);
                }
            }

            return(lines);
        }
Esempio n. 18
0
    static int set_startCharIdx(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name startCharIdx");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index startCharIdx on a nil value");
            }
        }

        UILineInfo obj = (UILineInfo)o;

        obj.startCharIdx = (int)LuaScriptMgr.GetNumber(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
Esempio n. 19
0
 public override void ModifyVertices(List <UIVertex> verts)
 {
     if (this.IsActive())
     {
         Text          component = base.GetComponent <Text>();
         List <string> list      = new List <string>();
         for (int i = 0; i < component.cachedTextGenerator.lineCount; i++)
         {
             UILineInfo info         = component.cachedTextGenerator.lines[i];
             int        startCharIdx = info.startCharIdx;
             int        num3         = (i >= (component.cachedTextGenerator.lineCount - 1)) ? component.text.Length : component.cachedTextGenerator.lines[i + 1].startCharIdx;
             list.Add(component.text.Substring(startCharIdx, num3 - startCharIdx));
         }
         float       num4       = (this.offset * component.fontSize) / 100f;
         float       num5       = 0f;
         IEnumerator enumerator = null;
         Match       current    = null;
         if (((component.alignment == TextAnchor.LowerLeft) || (component.alignment == TextAnchor.MiddleLeft)) || (component.alignment == TextAnchor.UpperLeft))
         {
             num5 = 0f;
         }
         else if (((component.alignment == TextAnchor.LowerCenter) || (component.alignment == TextAnchor.MiddleCenter)) || (component.alignment == TextAnchor.UpperCenter))
         {
             num5 = 0.5f;
         }
         else if (((component.alignment == TextAnchor.LowerRight) || (component.alignment == TextAnchor.MiddleRight)) || (component.alignment == TextAnchor.UpperRight))
         {
             num5 = 1f;
         }
         bool flag = true;
         int  num6 = 0;
         for (int j = 0; (j < list.Count) && flag; j++)
         {
             string text   = list[j];
             int    length = text.Length;
             if (length > (component.cachedTextGenerator.characterCountVisible - num6))
             {
                 length = component.cachedTextGenerator.characterCountVisible - num6;
                 text   = text.Substring(0, length) + " ";
                 length++;
             }
             if (component.supportRichText)
             {
                 enumerator = this.GetRegexMatchedTags(text, out length).GetEnumerator();
                 current    = null;
                 if (enumerator.MoveNext())
                 {
                     current = (Match)enumerator.Current;
                 }
             }
             bool  flag2 = (list[j].Length > 0) && ((list[j][list[j].Length - 1] == ' ') || (list[j][list[j].Length - 1] == '\n'));
             float num9  = (-((length - 1) - (!flag2 ? 0 : 1)) * num4) * num5;
             float num10 = 0f;
             for (int k = 0; (k < text.Length) && flag; k++)
             {
                 if ((component.supportRichText && (current != null)) && (current.Index == k))
                 {
                     k    += current.Length - 1;
                     num6 += current.Length - 1;
                     num10--;
                     current = null;
                     if (enumerator.MoveNext())
                     {
                         current = (Match)enumerator.Current;
                     }
                 }
                 if (((num6 * 4) + 4) >= verts.Count)
                 {
                     flag = false;
                     break;
                 }
                 for (int m = 0; m < 4; m++)
                 {
                     UIVertex vertex = verts[(num6 * 4) + m];
                     vertex.position      += (Vector3)(Vector3.right * ((num4 * num10) + num9));
                     verts[(num6 * 4) + m] = vertex;
                 }
                 num6++;
                 num10++;
             }
         }
     }
 }
Esempio n. 20
0
    private void RichTextAlignDataSupport(VertexHelper toFill)
    {
        if (!supportRichText)
        {
            base.OnPopulateMesh(toFill);
            return;
        }

        string changedText = "";
        var    orignText   = m_Text;

        m_Text      = DealWithTextContent(m_Text);
        changedText = m_Text;
        base.OnPopulateMesh(toFill);
        m_Text = orignText;

        IList <UILineInfo> lines      = cachedTextGenerator.lines;
        IList <UICharInfo> characters = cachedTextGenerator.characters;
        Rect rectExtents = cachedTextGenerator.rectExtents;
        //Debug.Log("cachedTextGenerator.characterCountVisible :"+cachedTextGenerator.characterCountVisible);
        List <UIVertex> stream = new List <UIVertex>();

        toFill.GetUIVertexStream(stream);

        List <AlignData> removeAlignDatas = new List <AlignData>();

        for (int i = 0; i < alignDatas.Count; i++)
        {
            AlignData alignData = alignDatas[i];


            for (int j = 0; j < lines.Count; j++)
            {
                UILineInfo lInfo = lines[j];
                if (lInfo.startCharIdx <= alignData.startCharIndex)
                {
                    alignData.lineIndex          = j;
                    alignData.lineStartCharIndex = lInfo.startCharIdx;
                    if (j == lines.Count - 1)
                    {
                        if (alignData.startCharIndex > cachedTextGenerator.characterCountVisible)
                        {
                            removeAlignDatas.Add(alignData);
                        }
                        else
                        {
                            alignData.lineEndCharIndex = cachedTextGenerator.characterCountVisible;
                        }
                    }
                }
                else
                {
                    alignData.lineEndCharIndex = lInfo.startCharIdx - 1;
                    break;
                }
            }

            alignDatas[i] = alignData;
        }
        List <int> lineList = new List <int>();

        for (int i = 0; i < alignDatas.Count; i++)
        {
            AlignData alignData = alignDatas[i];
            //Debug.Log("alignData.lineIndex :" + alignData.lineIndex);
            if (lineList.Contains(alignData.lineIndex))
            {
                removeAlignDatas.Add(alignData);
                continue;
            }
            else
            {
                lineList.Add(alignData.lineIndex);
            }
        }
        for (int i = 0; i < removeAlignDatas.Count; i++)
        {
            alignDatas.Remove(removeAlignDatas[i]);
        }
        //Debug.Log("alignDatas :" + alignDatas.Count);

        for (int i = 0; i < alignDatas.Count; i++)
        {
            AlignData alignData = alignDatas[i];
            //Debug.Log("characters.Count :" + characters.Count + "  stream.Count:" + stream.Count + "  alignData.lineEndCharIndex:" + alignData.lineEndCharIndex);
            if (alignData.lineEndCharIndex >= characters.Count)
            {
                continue;
            }
            if (alignData.lineStartCharIndex >= characters.Count)
            {
                continue;
            }
            if ((alignData.lineEndCharIndex * 6) > stream.Count)
            {
                continue;
            }
            if (alignData.lineStartCharIndex * 6 >= stream.Count)
            {
                continue;
            }
            if (alignData.alignType == AlignType.Right)
            {
                UICharInfo uiChar   = characters[alignData.lineEndCharIndex];
                float      detaMove = rectExtents.width / 2 - uiChar.cursorPos.x - uiChar.charWidth;

                for (int v = alignData.lineStartCharIndex * 6; v < alignData.lineEndCharIndex * 6; v++)
                {
                    UIVertex ver = stream[v];
                    ver.position += new Vector3(detaMove, 0, 0);
                    //ver.color = Color.red;
                    stream[v] = ver;
                }
            }
            else if (alignData.alignType == AlignType.Left)
            {
                UICharInfo uiChar   = characters[alignData.lineStartCharIndex];
                float      detaMove = (-rectExtents.width / 2) - uiChar.cursorPos.x;
                //Debug.Log("LLeft alignData.lineStartCharIndex:" + alignData.lineStartCharIndex + "  alignData.lineEndCharIndex:" + alignData.lineEndCharIndex);
                for (int v = alignData.lineStartCharIndex * 6; v < alignData.lineEndCharIndex * 6; v++)
                {
                    UIVertex ver = stream[v];
                    ver.position += new Vector3(detaMove, 0, 0);
                    //ver.color = Color.green;
                    stream[v] = ver;
                }
            }
            else if (alignData.alignType == AlignType.Center)
            {
                float lineCharLenth = 0;
                for (int j = alignData.lineStartCharIndex; j < alignData.lineEndCharIndex; j++)
                {
                    lineCharLenth += characters[j].charWidth;
                }


                float detaMove = -lineCharLenth / 2 - characters[alignData.lineStartCharIndex].cursorPos.x;

                for (int v = alignData.lineStartCharIndex * 6; v < alignData.lineEndCharIndex * 6; v++)
                {
                    UIVertex ver = stream[v];
                    ver.position += new Vector3(detaMove, 0, 0);
                    //ver.color = Color.blue;
                    stream[v] = ver;
                }
            }
        }
        toFill.AddUIVertexTriangleStream(stream);
    }
Esempio n. 21
0
        public void ModifyVertices(List <UIVertex> verts)
        {
            if (!IsActive())
            {
                return;
            }
            Text               component = GetComponent <Text>();
            string             text      = component.text;
            IList <UILineInfo> lines     = component.cachedTextGenerator.lines;

            for (int num = lines.Count - 1; num > 0; num--)
            {
                string     text2      = text;
                UILineInfo uILineInfo = lines[num];
                text = text2.Insert(uILineInfo.startCharIdx, "\n");
                string     text3       = text;
                UILineInfo uILineInfo2 = lines[num];
                text = text3.Remove(uILineInfo2.startCharIdx - 1, 1);
            }
            string[] array = text.Split('\n');
            if (component == null)
            {
                UnityEngine.Debug.LogWarning("LetterSpacing: Missing Text component");
                return;
            }
            float       num2       = spacing * (float)component.fontSize / 100f;
            float       num3       = 0f;
            int         num4       = 0;
            bool        flag       = useRichText && component.supportRichText;
            IEnumerator enumerator = null;
            Match       match      = null;

            switch (component.alignment)
            {
            case TextAnchor.UpperLeft:
            case TextAnchor.MiddleLeft:
            case TextAnchor.LowerLeft:
                num3 = 0f;
                break;

            case TextAnchor.UpperCenter:
            case TextAnchor.MiddleCenter:
            case TextAnchor.LowerCenter:
                num3 = 0.5f;
                break;

            case TextAnchor.UpperRight:
            case TextAnchor.MiddleRight:
            case TextAnchor.LowerRight:
                num3 = 1f;
                break;
            }
            foreach (string text4 in array)
            {
                int lineLengthWithoutTags = text4.Length;
                if (flag)
                {
                    enumerator = GetRegexMatchedTagCollection(text4, out lineLengthWithoutTags);
                    match      = null;
                    if (enumerator.MoveNext())
                    {
                        match = (Match)enumerator.Current;
                    }
                }
                float num5 = (float)(lineLengthWithoutTags - 1) * num2 * num3;
                int   num6 = 0;
                int   num7 = 0;
                while (num6 < text4.Length)
                {
                    if (flag && match != null && match.Index == num6)
                    {
                        num6 += match.Length - 1;
                        num7--;
                        num4 += match.Length;
                        match = null;
                        if (enumerator.MoveNext())
                        {
                            match = (Match)enumerator.Current;
                        }
                    }
                    else
                    {
                        int index  = num4 * 6;
                        int index2 = num4 * 6 + 1;
                        int index3 = num4 * 6 + 2;
                        int index4 = num4 * 6 + 3;
                        int index5 = num4 * 6 + 4;
                        int num8   = num4 * 6 + 5;
                        if (num8 > verts.Count - 1)
                        {
                            return;
                        }
                        UIVertex value  = verts[index];
                        UIVertex value2 = verts[index2];
                        UIVertex value3 = verts[index3];
                        UIVertex value4 = verts[index4];
                        UIVertex value5 = verts[index5];
                        UIVertex value6 = verts[num8];
                        Vector3  vector = Vector3.right * (num2 * (float)num7 - num5);
                        value.position  += vector;
                        value2.position += vector;
                        value3.position += vector;
                        value4.position += vector;
                        value5.position += vector;
                        value6.position += vector;
                        verts[index]     = value;
                        verts[index2]    = value2;
                        verts[index3]    = value3;
                        verts[index4]    = value4;
                        verts[index5]    = value5;
                        verts[num8]      = value6;
                        num4++;
                    }
                    num6++;
                    num7++;
                }
                num4++;
            }
        }
Esempio n. 22
0
        // Token: 0x06002D4D RID: 11597 RVA: 0x0048FD48 File Offset: 0x0048DF48
        private void AdjuestArabicVBOHeight(List <UIVertex> vbo)
        {
            IList <UILineInfo> lines = base.cachedTextGenerator.lines;

            if (lines.Count > 1)
            {
                IList <UICharInfo> characters = base.cachedTextGenerator.characters;
                int   num  = lines.Count - 1;
                int   num2 = 0;
                float num3 = 1f / base.pixelsPerUnit;
                while (num > -1 && num2 < lines.Count)
                {
                    UILineInfo uilineInfo = lines[num];
                    int        num4       = lines[num2].startCharIdx;
                    int        num5       = (num2 < lines.Count - 1) ? lines[num2 + 1].startCharIdx : characters.Count;
                    int        num6       = uilineInfo.startCharIdx;
                    int        num7       = (num < lines.Count - 1) ? lines[num + 1].startCharIdx : characters.Count;
                    if (num4 < this.m_Text.Length && this.m_Text[num4] == '<')
                    {
                        if (num4 + 14 < num5 && this.m_Text[num4 + 14] == '>')
                        {
                            int i;
                            for (i = 0; i < this.CheckColorStr.Length; i++)
                            {
                                if (this.CheckColorStr[i] != this.m_Text[num4 + i + 1])
                                {
                                    break;
                                }
                            }
                            if (i == this.CheckColorStr.Length && num4 + 14 + 1 < num5)
                            {
                                num4 += 15;
                            }
                        }
                        else if (num4 + 16 < num5 && this.m_Text[num4 + 16] == '>')
                        {
                            int j;
                            for (j = 0; j < this.CheckColorStr.Length; j++)
                            {
                                if (this.CheckColorStr[j] != this.m_Text[num4 + j + 1])
                                {
                                    break;
                                }
                            }
                            if (j == this.CheckColorStr.Length && num4 + 16 + 1 < num5)
                            {
                                num4 += 17;
                            }
                        }
                    }
                    if (num6 < this.m_Text.Length && this.m_Text[num6] == '<')
                    {
                        if (num6 + 14 < num7 && this.m_Text[num6 + 14] == '>')
                        {
                            int k;
                            for (k = 0; k < this.CheckColorStr.Length; k++)
                            {
                                if (this.CheckColorStr[k] != this.m_Text[num6 + k + 1])
                                {
                                    break;
                                }
                            }
                            if (k == this.CheckColorStr.Length && num6 + 14 + 1 < num7)
                            {
                                num6 += 15;
                            }
                        }
                        else if (num6 + 16 < num7 && this.m_Text[num6 + 16] == '>')
                        {
                            int l;
                            for (l = 0; l < this.CheckColorStr.Length; l++)
                            {
                                if (this.CheckColorStr[l] != this.m_Text[num6 + l + 1])
                                {
                                    break;
                                }
                            }
                            if (l == this.CheckColorStr.Length && num6 + 16 + 1 < num7)
                            {
                                num6 += 17;
                            }
                        }
                    }
                    float num8 = characters[num4].cursorPos.y - characters[num6].cursorPos.y;
                    num8 *= num3;
                    for (int m = (num < lines.Count - 1) ? (lines[num + 1].startCharIdx - 1) : ((vbo.Count >> 2) - 1); m >= uilineInfo.startCharIdx; m--)
                    {
                        for (int n = 0; n < 4; n++)
                        {
                            UIVertex value = vbo[(m << 2) + n];
                            value.position   += Vector3.up * num8;
                            vbo[(m << 2) + n] = value;
                        }
                    }
                    num--;
                    num2++;
                }
            }
        }