Example #1
0
        //表情绘制
        private void UpdateDrawSprite(bool visable)
        {
            foreach (var vp in SpriteTagInfoDic)
            {
                var         index       = vp.Key;
                SpriteEmoji spriteEmoji = GetSpriteEmoji(index);
                spriteEmoji.m_spriteAsset        = SpriteAssetManager.Instance.GetSpriteAsset(index);
                spriteEmoji.material.mainTexture = SpriteAssetManager.Instance.GetSpriteTexture(index);
                var _spriteInfo = vp.Value;
                spriteEmoji.ClearEmojiVert();
                for (int i = 0; i < _spriteInfo.Count; i++)
                {
                    var info = _spriteInfo[i];
                    // toFill.PopulateUIVertex(ref _tempVertex1, index);
                    for (int j = 0; j < 4; j++)
                    {
                        UIVertex vertex = Pool <UIVertex> .Get();

                        //清理多余的乱码uv
                        vertex.uv0      = Vector2.zero;
                        vertex.uv1      = info.UVs[j];
                        vertex.uv2      = new Vector2(info.Id, 0);
                        vertex.position = info.Pos[j];
                        //  spriteEmoji.AddEmojiVert(vertex);
                    }
                }
            }
        }
Example #2
0
 private void LateUpdate()
 {
     if (updateSubs)
     {
         foreach (var vp in SpriteTagInfoDic)
         {
             var         index       = vp.Key;
             SpriteEmoji spriteEmoji = GetSpriteEmoji(index);
             spriteEmoji.SetAllDirty();
             updateSubs = false;
         }
     }
 }
Example #3
0
        //处理表情信息
        private void DealSpriteTagInfo(VertexHelper toFill)
        {
            int index = -1;

#if UNITY_2019_1_OR_NEWER
            bool autoLF = AutoLF();
#endif
            //emoji
            foreach (var vp in SpriteTagInfoDic)
            {
                var         _spriteInfo = vp.Value;
                var         emojiId     = vp.Key;
                SpriteEmoji spriteEmoji = GetSpriteEmoji(emojiId);
                spriteEmoji.m_spriteAsset        = SpriteAssetManager.Instance.GetSpriteAsset(emojiId);
                spriteEmoji.material.mainTexture = SpriteAssetManager.Instance.GetSpriteTexture(emojiId);
                spriteEmoji.ClearEmojiVert();
                for (int i = 0; i < _spriteInfo.Count; i++)
                {
                    var info = _spriteInfo[i];

#if UNITY_2019_1_OR_NEWER
                    index = autoLF ? _spriteInfo[i].Index : _spriteInfo[i].NewIndex;
#else
                    index = info.Index;
#endif
                    float num1 = 1f / this.pixelsPerUnit;

                    if ((index + 4) <= toFill.currentVertCount)
                    {
                        // toFill.PopulateUIVertex(ref _tempVertex1, index);
                        for (int j = index; j < index + 4; j++)
                        {
                            toFill.PopulateUIVertex(ref _tempVertex, j);
                            //清理多余的乱码uv
                            _tempVertex.uv0 = Vector2.zero;
                            _tempVertex.uv1 = _spriteInfo[i].UVs[j - index];
                            _tempVertex.uv2 = new Vector2(info.Id, 0);
                            //获取quad的位置 --> 转为世界坐标
                            info.Pos[j - index] = Utility.TransformPoint2World(transform, _tempVertex.position);
                            toFill.SetUIVertex(_tempVertex, j);
                            _tempVertex.position = info.Pos[j - index];
                            spriteEmoji.AddEmojiVert(_tempVertex);
                        }
                    }
                }
            }
        }
Example #4
0
        private string GetOutputText(string inputText)
        {
            //回收各种对象
            ReleaseSpriteTageInfo();
            ReleaseHrefInfos();

            if (string.IsNullOrEmpty(inputText))
            {
                return("");
            }

            _textBuilder.Clear();
            int    textIndex = 0;
            int    newIndex  = 0;
            string part      = "";
            int    tempIndex = 0;
            int    vertSum   = 0;

            if (tagParser == null)
            {
                tagParser = new TagParser.TagParser();
            }
            tagParser.Reset();
            tagParser.ParseText(inputText);


            tagBegin = 0;
            _textBuilder.Append(inputText);
            for (int i = 0; i < tagParser.Tags.Count; i++)
            {
                var tag = tagParser.Tags[i];
                // _textBuilder.AppendFormat(g.TextWithNoTags.Substring(tagBegin, tag.startIndex - tagBegin));
                // tagBegin += tag.endIndex - tag.startIndex;
                switch (tag.Name)
                {
                case "sprite":
                {
                    int    spriteSub = 0;
                    string spriteTag = "";
                    for (int j = 0; j < tag.Properties.Count; j++)
                    {
                        var tempId  = tag.Properties[j].key;
                        var tempTag = tag.Properties[j].value;

                        if (tempId == "id")
                        {
                            spriteSub = int.Parse(tempTag);
                        }
                        if (tempId == "tag")
                        {
                            spriteTag = tempTag;
                        }
                    }
                    SpriteInfoGroup tempGroup = SpriteAssetManager.Instance.GetSpriteGroup(spriteSub, spriteTag);
                    if (tempGroup == null)
                    {
                        continue;
                    }
                    //清理标签
                    SpriteTagInfo tempSpriteTag = Pool <SpriteTagInfo> .Get();

                    tempSpriteTag.Index = (tag.endIndex - tag.lineIndex) * 4;

                    var s = fontSize / tempGroup.Size;
                    // _textBuilder.AppendFormat("<quad size={0} width={1}/>", tempGroup.Size * s, tempGroup.Width);

                    _textBuilder.Replace(string.Format("<{0}></sprite>", tag.content),
                                         string.Format("<quad size={0} width={1}/>", tempGroup.Size * s, tempGroup.Width));

                    tempSpriteTag.Id   = spriteSub;
                    tempSpriteTag.Tag  = spriteTag;
                    tempSpriteTag.Size = new Vector2(tempGroup.Size * tempGroup.Width, tempGroup.Size);
                    tempSpriteTag.UVs  = tempGroup.ListSpriteInfor[0].Uv;

                    //添加正则表达式的信息
                    SpriteTagInfoDic.TryGetValue(tempSpriteTag.Id, out var list);
                    if (list == null)
                    {
                        if (SpriteTagInfoDic.ContainsKey(tempSpriteTag.Id))
                        {
                            SpriteTagInfoDic.Remove(tempSpriteTag.Id);
                        }
                        list = new List <SpriteTagInfo>();
                        SpriteTagInfoDic.Add(tempSpriteTag.Id, list);
                    }
                    list.Add(tempSpriteTag);
                    SpriteEmoji spriteEmoji = GetSpriteEmoji(spriteSub);
                    spriteEmoji.m_spriteAsset        = SpriteAssetManager.Instance.GetSpriteAsset(spriteSub);
                    spriteEmoji.material.mainTexture = SpriteAssetManager.Instance.GetSpriteTexture(spriteSub);
                    spriteEmoji.ClearEmojiVert();
                    spriteEmoji.SetAllDirty();
                    break;
                }

                case "herf":
                {
                    int herfid = 0;

                    for (int j = 0; j < tag.Properties.Count; j++)
                    {
                        var tempId  = tag.Properties[j].key;
                        var tempTag = tag.Properties[j].value;
                        if (tempId == "id")
                        {
                            herfid = int.Parse(tempTag);
                        }
                    }
                    _textBuilder.Replace(string.Format("<{0}>{1}</herf>", tag.content, tag.Value),
                                         string.Format("<color=blue>{0}</color>", tag.Value));

                    var hrefInfo = Pool <HrefInfo> .Get();

                    hrefInfo.Id         = Mathf.Abs(herfid);
                    hrefInfo.StartIndex = (tag.startIndex - tag.lineIndex) * 4;; // 超链接里的文本起始顶点索引
                    hrefInfo.EndIndex   = (tag.endIndex - tag.lineIndex) * 4;;
#if UNITY_2019_1_OR_NEWER
                    hrefInfo.NewStartIndex = newStartIndex;
                    hrefInfo.NewEndIndex   = newIndex - 1;
#endif
                    hrefInfo.Name      = tag.Name;
                    hrefInfo.HrefValue = tag.Value;
                    _listHrefInfos.Add(hrefInfo);


                    break;
                }
                }
            }

/*
 *          _textBuilder.Clear();
 *
 *          foreach (Match match in _inputTagRegex.Matches(inputText))
 *          {
 *              int tempId = 0;
 *              if (!string.IsNullOrEmpty(match.Groups[1].Value) && !match.Groups[1].Value.Equals("-"))
 *                  tempId = int.Parse(match.Groups[1].Value);
 *              string tempTag = match.Groups[2].Value;
 *              var tagLength = tempTag.Length;
 *              //更新超链接
 *              if (tempId < 0)
 *              {
 *                  part = inputText.Substring(textIndex, match.Index - textIndex);
 *                  _textBuilder.Append(part);
 *
 *                  var lastLength = ReplaceRichText(_textBuilder.ToString()).Length;
 *                  int startIndex = (lastLength- vertSum)*4;;
 *                  _textBuilder.AppendFormat("<color=blue>{0}</color>", match.Groups[2].Value);
 *
 *                  vertSum += ReplaceRichText(_textBuilder.ToString()).Length - lastLength-tagLength;
 *                  int endIndex = startIndex + tagLength*4 ;
 *
 #if UNITY_2019_1_OR_NEWER
 *                  newIndex += ReplaceRichText(part).Length * 4;
 *                  int newStartIndex = newIndex;
 *                  newIndex += match.Groups[2].Value.Length * 4 + 8;
 #endif
 *
 *                  var hrefInfo = Pool<HrefInfo>.Get();
 *                  hrefInfo.Id = Mathf.Abs(tempId);
 *                  hrefInfo.StartIndex = startIndex;// 超链接里的文本起始顶点索引
 *                  hrefInfo.EndIndex = endIndex;
 #if UNITY_2019_1_OR_NEWER
 *                  hrefInfo.NewStartIndex = newStartIndex;
 *                  hrefInfo.NewEndIndex = newIndex - 1;
 #endif
 *                  hrefInfo.Name = match.Groups[2].Value;
 *                  hrefInfo.HrefValue = match.Groups[3].Value;
 *                  _listHrefInfos.Add(hrefInfo);
 *              }
 *              //更新表情
 *              else
 *              {
 *                  SpriteInfoGroup tempGroup = SpriteAssetManager.Instance.GetSpriteGroup(tempId, tempTag);
 *                  if (tempGroup == null)
 *                      continue;
 *                  part = inputText.Substring(textIndex, match.Index - textIndex);
 *                  _textBuilder.Append(part);
 *
 *
 *                  var lastLength = ReplaceRichText(_textBuilder.ToString()).Length;
 *
 #if UNITY_2019_1_OR_NEWER
 *                  newIndex += ReplaceRichText(part).Length * 4;
 #endif
 *                  tempIndex = (lastLength- vertSum)*4;
 *                  var s= fontSize/tempGroup.Size;
 *                  _textBuilder.AppendFormat("<quad size={0} width={1}/>", tempGroup.Size * s, tempGroup.Width);
 *                  vertSum += ReplaceRichText(_textBuilder.ToString()).Length - lastLength-1;
 *
 *                  //清理标签
 *                  SpriteTagInfo tempSpriteTag = Pool<SpriteTagInfo>.Get();
 *                  tempSpriteTag.Index = tempIndex;
 *
 #if UNITY_2019_1_OR_NEWER
 *                  tempSpriteTag.NewIndex = newIndex;
 #endif
 *
 *                  tempSpriteTag.Id = tempId;
 *                  tempSpriteTag.Tag = tempTag;
 *                  tempSpriteTag.Size = new Vector2(tempGroup.Size * tempGroup.Width, tempGroup.Size);
 *                  tempSpriteTag.UVs = tempGroup.ListSpriteInfor[0].Uv;
 *
 *                  //添加正则表达式的信息
 *                  SpriteTagInfoDic.TryGetValue(tempSpriteTag.Id, out var list);
 *                  if (list == null)
 *                  {
 *                      if (SpriteTagInfoDic.ContainsKey(tempSpriteTag.Id))
 *                      {
 *                          SpriteTagInfoDic.Remove(tempSpriteTag.Id);
 *                      }
 *
 *                      list = new List<SpriteTagInfo>();
 *                      SpriteTagInfoDic.Add(tempSpriteTag.Id,list);
 *                  }
 *                  list.Add(tempSpriteTag);
 *                  SpriteEmoji spriteEmoji = GetSpriteEmoji(tempId);
 *                  spriteEmoji.m_spriteAsset =SpriteAssetManager.Instance.GetSpriteAsset(tempId);
 *                  spriteEmoji.material.mainTexture = SpriteAssetManager.Instance.GetSpriteTexture(tempId);
 *                  spriteEmoji.ClearEmojiVert();
 *                  spriteEmoji.SetAllDirty();
 #if UNITY_2019_1_OR_NEWER
 *                  newIndex += 4;
 #endif
 *              }
 *
 *
 *              textIndex = match.Index + match.Length;
 *          }
 *
 *          _textBuilder.Append(inputText.Substring(textIndex, inputText.Length - textIndex));
 */
            return(_textBuilder.ToString());
        }