void AddQuad(VertexHelper vertexHelper, UIEmotionTextModel model)
        {
            int startIndex = vertexHelper.currentVertCount;

            vertexHelper.AddVert(new Vector3(model.PosMin.x, model.PosMin.y, 0), color, new Vector2(model.X, model.Y + model.Size));
            vertexHelper.AddVert(new Vector3(model.PosMax.x, model.PosMin.y, 0), color, new Vector2(model.X + model.Size, model.Y + model.Size));
            vertexHelper.AddVert(new Vector3(model.PosMax.x, model.PosMax.y, 0), color, new Vector2(model.X + model.Size, model.Y));
            vertexHelper.AddVert(new Vector3(model.PosMin.x, model.PosMax.y, 0), color, new Vector2(model.X, model.Y));

            vertexHelper.AddTriangle(startIndex, startIndex + 1, startIndex + 2);
            vertexHelper.AddTriangle(startIndex + 2, startIndex + 3, startIndex);
        }
Esempio n. 2
0
        protected override void OnPopulateMesh(VertexHelper toFill)
        {
            m_Text = buildText;
            base.OnPopulateMesh(toFill);
            int i, j, startIndex;

            for (i = 0; i < _GraphicItemModels.Count; i++)
            {
                UIEmotionTextModel model = _GraphicItemModels[i];
                startIndex = model.TextIndex * 4;
                for (j = 0; j < 4; j++)
                {
                    var indics = startIndex + j;
                    if (indics >= toFill.currentVertCount)
                    {
                        break;
                    }

                    toFill.PopulateUIVertex(ref vert, indics);
                    vert.uv0       = vert.uv1 = Vector2.zero;
                    vert.position += new Vector3(GraphicOffset.x, GraphicOffset.y * 0.5f, GraphicOffset.z);

                    toFill.SetUIVertex(vert, indics);

                    if (j == 0)
                    {
                        model.PosMin = vert.position + new Vector3(0, (GraphicScale - 1) / 2 * fontSize, 0);
                    }
                    if (j == 2)
                    {
                        model.PosMax = vert.position + new Vector3(0, -(GraphicScale - 1) / 2 * fontSize, 0);
                    }
                }
            }

            if (_GraphicBoard != null)
            {
                _GraphicBoard.SetVertexData(_GraphicItemModels);
            }

            for (i = 0; i < _TextLinkModels.Count; i++)
            {
                UILinkTextModel linkModel = _TextLinkModels[i];
                startIndex = linkModel.StartIndex * 4;
                int endIndex = linkModel.EndIndex * 4 + 3;
                if (startIndex >= toFill.currentVertCount)
                {
                    continue;
                }
                toFill.PopulateUIVertex(ref vert, startIndex);
                Vector3 pos       = vert.position;
                Vector3 last_char = pos;
                Bounds  bounds    = new Bounds(pos, Vector3.zero);
                for (j = startIndex + 2; j < endIndex; j += 2)
                {
                    if (j >= toFill.currentVertCount)
                    {
                        break;
                    }
                    toFill.PopulateUIVertex(ref vert, j);
                    pos = vert.position;
                    if (j % 4 == 0)
                    {
                        if (pos.x < last_char.x)
                        {
                            if (bounds.size.x > 0)
                            {
                                linkModel.AddRect(new Rect(bounds.min, bounds.size));
                            }
                            bounds = new Bounds(pos, Vector3.zero);
                        }
                        else
                        {
                            bounds.Encapsulate(pos);
                        }
                        last_char = pos;
                    }
                    else
                    {
                        bounds.Encapsulate(pos);
                    }
                }

                if (bounds.size.x > 0)
                {
                    linkModel.AddRect(new Rect(bounds.min, bounds.size));
                }
            }
            m_Text = originText;
        }
Esempio n. 3
0
        public override void SetVerticesDirty()
        {
            originText = m_Text;
            MatchCollection collections = TextRegex.Matches(originText);

            _GraphicItemModels.Clear();
            _TextLinkModels.Clear();
            int last_index = 0;

            if (stringBuilder == null)
            {
                stringBuilder = new StringBuilder();
            }
            stringBuilder.Length = 0;

            for (var i = 0; i < collections.Count; i++)
            {
                Match  match       = collections[i];
                int    match_index = match.Index;
                string type        = match.Groups[1].Value;
                if (type == EMOTIONTAG)
                {
                    stringBuilder.Append(originText.Substring(last_index, match_index - last_index));
                    var    start_index = stringBuilder.Length;
                    string quad        = StringUtility.Format(TEXTQUAD, match.Groups[2].Value, (int)(fontSize), (GraphicScale));
                    stringBuilder.Append(quad);
                    UIEmotionTextModel model = new UIEmotionTextModel
                    {
                        TextIndex  = start_index,
                        SpriteName = match.Groups[2].Value
                    };
                    EmojiInfo emojiInfo = EmojiInfos[model.SpriteName];
                    model.X    = emojiInfo.x;
                    model.Y    = emojiInfo.y;
                    model.Size = emojiInfo.size;
                    _GraphicItemModels.Add(model);
                }
                else if (type == LINKTAG)
                {
                    string seg = originText.Substring(last_index, match_index - last_index);
                    stringBuilder.Append(seg);
                    UILinkTextModel linkModel = new UILinkTextModel();
                    string          inner_txt;
                    string          color_text;
                    MatchCollection collections_con = LinkRegex.Matches(match.Groups[2].Value);
                    if (collections_con.Count == 1 && collections_con[0].Groups.Count == 3)
                    {
                        color_text = collections_con[0].Groups[1].Value;
                        inner_txt  = collections_con[0].Groups[2].Value;
                    }
                    else
                    {
                        color_text = "#0066cc";
                        inner_txt  = match.Groups[2].Value;
                    }

                    stringBuilder.AppendFormat("<color={0}>", color_text);
                    linkModel.StartIndex = stringBuilder.Length;
                    stringBuilder.AppendFormat(inner_txt);
                    linkModel.EndIndex = stringBuilder.Length - 1;
                    stringBuilder.Append("</color>");
                    _TextLinkModels.Add(linkModel);
                }
                last_index = match_index + match.Value.Length;
            }
            stringBuilder.Append(originText.Substring(last_index, originText.Length - last_index));
            buildText = stringBuilder.ToString();
            base.SetVerticesDirty();
        }