Esempio n. 1
0
        private void _SetSpriteVertex_FillMethod_Horizontal(VertexHelper toFill, SpriteTag spriteTag, Sprite sprite)
        {
            UIVertex v           = UIVertex.simpleVert;
            var      vertexIndex = spriteTag.GetVertexStartIndex() * 4;
            var      fetchIndex  = vertexIndex + 3;

            if (fetchIndex >= toFill.currentIndexCount)
            {
                return;
            }
            if (m_SupportVertexCache)
            {
                UIVertexCache vertexCache = CacheManager.Instance.GetVertexCache(_parseOutputText.GetHashCode());
                if (vertexCache != null)
                {
                    List <UIVertex> vertexs = vertexCache.GetParams();
                    v = vertexs[fetchIndex];
                }
            }
            else
            {
                toFill.PopulateUIVertex(ref v, fetchIndex);
            }

            Vector3 textPos = v.position;
            var     tagSize = spriteTag.GetSize();
            float   xOffset = spriteTag.GetOffset() * tagSize.x;

            var texture          = sprite.texture;
            var textureWidthInv  = 1.0f / texture.width;
            var textureHeightInv = 1.0f / texture.height;
            var uvRect           = sprite.textureRect;

            uvRect = new Rect(uvRect.x * textureWidthInv, uvRect.y * textureHeightInv, uvRect.width * textureWidthInv, uvRect.height * textureHeightInv);

            //pos = (0,0)
            var position = new Vector3(xOffset, 0, 0) + textPos;
            var uv0      = new Vector2(uvRect.x, uvRect.y);

            _SetSpriteVertex(toFill, vertexIndex, position, uv0);

            var fillAmount = spriteTag.GetFillAmount();

            //pos = (1,0)
            position = new Vector3(xOffset + tagSize.x * fillAmount, 0, 0) + textPos;
            uv0      = new Vector2(uvRect.x + uvRect.width * fillAmount, uvRect.y);
            _SetSpriteVertex(toFill, ++vertexIndex, position, uv0);

            //pos = (1,1)
            position = new Vector3(xOffset + tagSize.x * fillAmount, tagSize.y, 0) + textPos;
            uv0      = new Vector2(uvRect.x + uvRect.width * fillAmount, uvRect.y + uvRect.height);
            _SetSpriteVertex(toFill, ++vertexIndex, position, uv0);

            //pos = (0,1)
            position = new Vector3(xOffset, tagSize.y, 0) + textPos;
            uv0      = new Vector2(uvRect.x, uvRect.y + uvRect.height);
            _SetSpriteVertex(toFill, ++vertexIndex, position, uv0);
        }
Esempio n. 2
0
 public void RemoveVertexCache(int key)
 {
     if (_vertexMap.ContainsKey(key))
     {
         UIVertexCache vertexCache = _vertexMap[key] as UIVertexCache;
         vertexCache.Dispose();
         _vertexMap.Remove(key);
     }
 }
Esempio n. 3
0
 public UIVertexCache AddVertexCache(int source)
 {
     if (!_vertexMap.ContainsKey(source))
     {
         _vertexMap[source] = new UIVertexCache();
         return(_vertexMap[source]);
     }
     return(_vertexMap[source]);
 }
Esempio n. 4
0
        private void GetBounds(VertexHelper toFill, List <LinkTag> m_HrefInfos)
        {
            SetNativeSize();

            DrawLineRect.Clear();
            //处理超链接包围框

            foreach (var hrefInfo in m_HrefInfos)
            {
                hrefInfo.Boxes.Clear();
                if (hrefInfo.GetStartIndex() >= toFill.currentVertCount)
                {
                    continue;
                }
                var pos = verts[hrefInfo.GetStartIndex()].position;

                List <BoxStruct> box = ConstructBox(hrefInfo.GetStartIndex(), hrefInfo.GetEndIndex());

                for (int i = 0; i < box.Count; ++i)
                {
                    BoxStruct boxStruct = box[i];
                    Rect      rect      = new Rect();

                    int startVer = boxStruct.start * 4 + 3;
                    int endVert  = boxStruct.end * 4 + 1;
                    if (endVert > toFill.currentVertCount)
                    {
                        endVert = toFill.currentVertCount - 2;
                    }
                    if (startVer >= toFill.currentVertCount)
                    {
                        break;
                    }
                    if (m_SupportVertexCache)
                    {
                        UIVertexCache vertexCache = CacheManager.Instance.GetVertexCache(_parseOutputText.GetHashCode());
                        if (vertexCache != null)
                        {
                            List <UIVertex> vertexs = new List <UIVertex>();
                            vertStart3 = verts[startVer];
                            vertEnd1   = vertexs[endVert];
                        }
                    }
                    else
                    {
                        toFill.PopulateUIVertex(ref vertStart3, startVer);
                        toFill.PopulateUIVertex(ref vertEnd1, endVert);
                    }

                    rect.Set(vertStart3.position.x, vertStart3.position.y, Mathf.Abs(vertEnd1.position.x - vertStart3.position.x), m_Lines[boxStruct.line].height);
                    hrefInfo.Boxes.Add(rect);
                    DrawLineRect.Add(rect);
                }
            }
        }
Esempio n. 5
0
        protected override void OnPopulateMesh(VertexHelper toFill)
        {
            if (null == font)
            {
                return;
            }

            //来自官方Text源码
            //we don't care if we the font Texture changes while we are doing our Update
            //The end result of cachedTextGenerator will be valid for this instance.
            //Otherwise we can get issuse like Case 619238.
            m_DisableFontTextureRebuiltCallback = true;

            Vector2 extents = rectTransform.rect.size;

            var setting = GetGenerationSettings(extents);

            cachedTextGenerator.Populate(_parseOutputText, setting);
            if (m_SupportVertexCache)
            {
                UIVertexCache vertexCache = CacheManager.Instance.GetVertexCache(_parseOutputText.GetHashCode());
                if (vertexCache != null)
                {
                    toFill.Clear();
                    List <UIVertex> vertexs = vertexCache.GetParams();
                    for (int i = 0; i < vertexs.Count; ++i)
                    {
                        int tempVerrsIndex = i & 3;
                        _tempVerts[tempVerrsIndex]           = vertexs[i];
                        _tempVerts[tempVerrsIndex].position *= vertexCache.GetUnitsPerPiexl();
                        _tempVerts[tempVerrsIndex].uv1       = new Vector2(1.0f, 0);
                        if (tempVerrsIndex == 3)
                        {
                            toFill.AddUIVertexQuad(_tempVerts);
                        }
                        //mVertextHelperRef = toFill;
                        //if(mDirty)
                        {
                            _HandleSpriteTag(toFill);
                            _HandleLinkTag(toFill, vertexs, setting);
                            //mDirty = false;
                        }

                        m_DisableFontTextureRebuiltCallback = false;
                        return;
                    }
                }

                //Apply the offset to the vertices
                IList <UIVertex> verts        = cachedTextGenerator.verts;
                float            unitsPerPixl = 1 / pixelsPerUnit;
                int vertCount = verts.Count;

                if (vertCount <= 0)
                {
                    toFill.Clear();
                    return;
                }
                Vector2 roundingOffset = new Vector2(verts[0].position.x, verts[0].position.y) * unitsPerPixl;
                roundingOffset = PixelAdjustPoint(roundingOffset) - roundingOffset;

                toFill.Clear();

                if (roundingOffset != Vector2.zero)
                {
                    for (int i = 0; i < vertCount; ++i)
                    {
                        int tempVertsIndex = i & 3;
                        _tempVerts[tempVertsIndex]             = verts[i];
                        _tempVerts[tempVertsIndex].position   *= unitsPerPixl;
                        _tempVerts[tempVertsIndex].position.x += roundingOffset.x;
                        _tempVerts[tempVertsIndex].position.y += roundingOffset.y;
                        _tempVerts[tempVertsIndex].uv1         = new Vector2(1.0f, 0);

                        if (tempVertsIndex == 3)
                        {
                            toFill.AddUIVertexQuad(_tempVerts);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < vertCount; i++)
                    {
                        int tempVertsIndex = i & 3;
                        _tempVerts[tempVertsIndex]           = verts[i];
                        _tempVerts[tempVertsIndex].position *= unitsPerPixl;
                        _tempVerts[tempVertsIndex].uv1       = new Vector2(1.0f, 0);
                        if (m_SupportVertexCache)
                        {
                            UIVertexCache vertexsCache = CacheManager.Instance.AddVertexCache(_parseOutputText.GetHashCode());
                            vertexsCache.AddParams(_tempVerts[tempVertsIndex]);
                            vertexsCache.SetUnitsPerPixel(unitsPerPixl);
                        }
                    }
                }

                //mVertexHelperRef= toFill;
                //if(mDirty)
                {
                    _HandleSpriteTag(toFill);
                    _HandleLinkTag(toFill, verts, setting);
                    //mDirty = false;
                }

                m_DisableFontTextureRebuiltCallback = false;
            }
        }