Ejemplo n.º 1
0
        /// <summary>
        /// 更新信息
        /// </summary>
        public void UpdateSpriteGroup()
        {
            if (_spriteAsset && _spriteAsset.TexSource && _spriteAsset.Row > 1 && _spriteAsset.Column > 1)
            {
                int count = _spriteAsset.IsStatic ? _spriteAsset.Row * _spriteAsset.Column : _spriteAsset.Row;
                if (_spriteAsset.ListSpriteGroup.Count != count)
                {
                    _spriteAsset.ListSpriteGroup.Clear();
                    //更新
                    //----------------------------------
                    Vector2 texSize = new Vector2(_spriteAsset.TexSource.width, _spriteAsset.TexSource.height);
                    Vector2 size    = new Vector2((_spriteAsset.TexSource.width / (float)_spriteAsset.Column)
                                                  , (_spriteAsset.TexSource.height / (float)_spriteAsset.Row));

                    if (_spriteAsset.IsStatic)
                    {
                        int index = -1;
                        for (int i = 0; i < _spriteAsset.Row; i++)
                        {
                            for (int j = 0; j < _spriteAsset.Column; j++)
                            {
                                index++;
                                SpriteInforGroup inforGroup = Pool <SpriteInforGroup> .Get();

                                SpriteInfor infor = GetSpriteInfo(index, i, j, size, texSize);

                                inforGroup.Tag = "emoji_" + infor.Id;
                                inforGroup.ListSpriteInfor.Add(infor);
                                _spriteAsset.ListSpriteGroup.Add(inforGroup);
                            }
                        }
                    }
                    else
                    {
                        int index = -1;
                        for (int i = 0; i < _spriteAsset.Row; i++)
                        {
                            SpriteInforGroup inforGroup = Pool <SpriteInforGroup> .Get();

                            inforGroup.Tag = "emoji_" + (index + 1);
                            for (int j = 0; j < _spriteAsset.Column; j++)
                            {
                                index++;

                                SpriteInfor infor = GetSpriteInfo(index, i, j, size, texSize);

                                inforGroup.ListSpriteInfor.Add(infor);
                            }
                            _spriteAsset.ListSpriteGroup.Add(inforGroup);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        //根据正则规则更新文本
        private string GetOutputText(string inputText)
        {
            //回收各种对象
            ReleaseSpriteTageInfo();
            ReleaseHrefInfos();

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

            _textBuilder.Remove(0, _textBuilder.Length);
            int    textIndex = 0;
            int    newIndex  = 0;
            string part      = "";

            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;
                //更新超链接
                if (tempId < 0)
                {
                    part = inputText.Substring(textIndex, match.Index - textIndex);
                    _textBuilder.Append(part);
                    _textBuilder.Append("<color=blue>");
                    int startIndex = _textBuilder.Length * 4;
                    _textBuilder.Append("[" + match.Groups[2].Value + "]");
                    int endIndex = _textBuilder.Length * 4 - 1;
                    _textBuilder.Append("</color>");
#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
                {
                    if (_inlineManager == null || !_inlineManager.IndexSpriteInfo.ContainsKey(tempId) ||
                        !_inlineManager.IndexSpriteInfo[tempId].ContainsKey(tempTag))
                    {
                        continue;
                    }

                    SpriteInforGroup tempGroup = _inlineManager.IndexSpriteInfo[tempId][tempTag];

                    part = inputText.Substring(textIndex, match.Index - textIndex);
                    _textBuilder.Append(part);
                    int tempIndex = _textBuilder.Length * 4;
#if UNITY_2019_1_OR_NEWER
                    newIndex += ReplaceRichText(part).Length * 4;
#endif
                    _textBuilder.Append(@"<quad size=" + tempGroup.Size + " width=" + tempGroup.Width + " />");

                    //清理标签
                    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;

                    //添加正则表达式的信息
                    _spriteInfo.Add(tempSpriteTag);
#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());
        }