Esempio n. 1
0
 //回收超链接的信息
 private void ReleaseHrefInfos()
 {
     for (int i = 0; i < _listHrefInfos.Count; i++)
     {
         Pool <HrefInfo> .Release(_listHrefInfos[i]);
     }
     _listHrefInfos.Clear();
 }
Esempio n. 2
0
 //回收SpriteTagInfo
 private void ReleaseSpriteTageInfo()
 {
     foreach (var vp in SpriteTagInfoDic)
     {
         var _spriteInfo = vp.Value;
         //记录之前的信息
         for (int i = 0; i < _spriteInfo.Count; i++)
         {
             //回收信息到对象池
             Pool <SpriteTagInfo> .Release(_spriteInfo[i]);
         }
         _spriteInfo.Clear();
     }
 }
Esempio n. 3
0
        //处理超链接的信息
        private void DealHrefInfo(VertexHelper toFill)
        {
            if (_listHrefInfos.Count > 0)
            {
#if UNITY_2019_1_OR_NEWER
                bool autoLF = AutoLF();
#endif
                // 处理超链接包围框
                for (int i = 0; i < _listHrefInfos.Count; i++)
                {
                    _listHrefInfos[i].Boxes.Clear();
#if UNITY_2019_1_OR_NEWER
                    int startIndex = autoLF ? _listHrefInfos[i].StartIndex : _listHrefInfos[i].NewStartIndex;
                    int endIndex   = autoLF ? _listHrefInfos[i].EndIndex : _listHrefInfos[i].NewEndIndex;
#else
                    int startIndex = _listHrefInfos[i].StartIndex + 1;
                    int endIndex   = _listHrefInfos[i].EndIndex + 1;
#endif
                    if (startIndex >= toFill.currentVertCount)
                    {
                        continue;
                    }

                    toFill.PopulateUIVertex(ref _tempVertex, startIndex);
                    // 将超链接里面的文本顶点索引坐标加入到包围框
                    var pos    = _tempVertex.position;
                    var bounds = new Bounds(pos, Vector3.zero);
                    for (int j = startIndex; j <= endIndex; j++)
                    {
                        if (j >= toFill.currentVertCount)
                        {
                            break;
                        }
                        toFill.PopulateUIVertex(ref _tempVertex, j);
                        pos = _tempVertex.position;
                        if (pos.x < bounds.min.x)
                        {
                            // 换行重新添加包围框
                            _listHrefInfos[i].Boxes.Add(new Rect(bounds.min, bounds.size));
                            bounds = new Bounds(pos, Vector3.zero);
                        }
                        else
                        {
                            bounds.Encapsulate(pos); // 扩展包围框
                        }
                    }
                    //添加包围盒
                    _listHrefInfos[i].Boxes.Add(new Rect(bounds.min, bounds.size));
                }

                //添加下划线
                Vector2       extents       = rectTransform.rect.size;
                var           settings      = GetGenerationSettings(extents);
                TextGenerator underlineText = Pool <TextGenerator> .Get();

                underlineText.Populate("_", settings);
                IList <UIVertex> tut = underlineText.verts;
                for (int m = 0; m < _listHrefInfos.Count; m++)
                {
                    for (int i = 0; i < _listHrefInfos[m].Boxes.Count; i++)
                    {
                        //计算下划线的位置
                        Vector3[] ulPos = new Vector3[4];
                        if (isVerticle)
                        {
                            ulPos[0] = _listHrefInfos[m].Boxes[i].position + new Vector2(-fontSize * 0.2f, 0);
                            ulPos[1] = ulPos[0] + new Vector3(0, _listHrefInfos[m].Boxes[i].height);
                            ulPos[2] = _listHrefInfos[m].Boxes[i].position + new Vector2(0, _listHrefInfos[m].Boxes[i].height);
                            ulPos[3] = _listHrefInfos[m].Boxes[i].position;
                        }
                        else
                        {
                            ulPos[0] = _listHrefInfos[m].Boxes[i].position + new Vector2(0.0f, -fontSize * 0.2f);
                            ulPos[1] = ulPos[0] + new Vector3(_listHrefInfos[m].Boxes[i].width, 0.0f);
                            ulPos[2] = _listHrefInfos[m].Boxes[i].position + new Vector2(_listHrefInfos[m].Boxes[i].width, 0.0f);
                            ulPos[3] = _listHrefInfos[m].Boxes[i].position;
                        }


                        //绘制下划线
                        for (int j = 0; j < 4; j++)
                        {
                            m_TempVerts[j]          = tut[j];
                            m_TempVerts[j].color    = Color.blue;
                            m_TempVerts[j].position = ulPos[j];

                            m_TempVerts[j].uv1 = -Vector2.one;
                            m_TempVerts[j].uv2 = Vector2.zero;
                            if (j == 3)
                            {
                                toFill.AddUIVertexQuad(m_TempVerts);
                            }
                        }
                    }
                }
                //回收下划线的对象
                Pool <TextGenerator> .Release(underlineText);
            }
        }