Esempio n. 1
0
        protected override void OnPopulateMesh(VertexHelper toFill)
        {
            TestSystem.startTimer("OnPopulateMesh Start");

            if (font == null)
            {
                return;
            }
            if (parser == null)
            {
                return;
            }
            //QuestionText.TestLog("OnPopulateMesh: parser: " + parser);
            //createParser().parse(m_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 issues like Case 619238.
            m_DisableFontTextureRebuiltCallback = true;

            Vector2 extents  = rectTransform.rect.size; extents.y = 99999;
            var     settings = GetGenerationSettings(extents);

            var resText = parser.processedText();

            TestSystem.catchTimer("Populate Start");

            cachedTextGenerator.Populate(resText, settings);

            TestSystem.catchTimer("Parse End");

            IList <UIVertex> verts = cachedTextGenerator.verts;

            TestSystem.startTimer("Parse Verts Start");

            verts = parser.parseVertices(enterHeight, verts);

            TestSystem.catchTimer("Parse Verts End");

            float unitsPerPixel = 1 / pixelsPerUnit;
            //Last 4 verts are always a new line... (\n)
            int vertCount = verts.Count;// - 4;

            // We have no verts to process just return (case 1037923)
            if (vertCount <= 0)
            {
                toFill.Clear();
                return;
            }

            Vector2 roundingOffset = new Vector2(verts[0].position.x, verts[0].position.y) * unitsPerPixel;

            roundingOffset = PixelAdjustPoint(roundingOffset) - roundingOffset;
            toFill.Clear();
            if (roundingOffset != Vector2.zero)
            {
                for (int i = 0; i < vertCount; ++i)
                {
                    int tempVertsIndex = i & 3;
                    m_TempVerts[tempVertsIndex]             = verts[i];
                    m_TempVerts[tempVertsIndex].position   *= unitsPerPixel;
                    m_TempVerts[tempVertsIndex].position.x += roundingOffset.x;
                    m_TempVerts[tempVertsIndex].position.y += roundingOffset.y;
                    if (tempVertsIndex == 3)
                    {
                        toFill.AddUIVertexQuad(m_TempVerts);
                    }
                }
            }
            else
            {
                for (int i = 0; i < vertCount; ++i)
                {
                    int tempVertsIndex = i & 3;
                    m_TempVerts[tempVertsIndex]           = verts[i];
                    m_TempVerts[tempVertsIndex].position *= unitsPerPixel;
                    if (tempVertsIndex == 3)
                    {
                        toFill.AddUIVertexQuad(m_TempVerts);
                    }
                }
            }

            /*
             * List<UIVertex> vertList = new List<UIVertex>();
             * toFill.GetUIVertexStream(vertList);
             *
             * var vcnt = vertList.Count;
             * QuestionText.TestLog("vcnt: " + vcnt);
             *
             * for (int i = 0; i < vcnt / 6; ++i) {
             *  //var c = meshText[i];
             *  //var cd = charData[i];
             *  var v1 = vertList[i * 6];
             *  var v2 = vertList[i * 6 + 1];
             *  var v3 = vertList[i * 6 + 2];
             *  var v4 = vertList[i * 6 + 3];
             *  var v5 = vertList[i * 6 + 4];
             *  var v6 = vertList[i * 6 + 5];
             *  //cd.setVertices(v1, v2, v3, v4);
             *  QuestionText.TestLog("GetUIVertexStream: " + i
             + "\nverts: " + v1.position + "," + v2.position
             + "," + v3.position + "," + v4.position
             + "," + v5.position + "," + v6.position);
             + }
             */
            m_DisableFontTextureRebuiltCallback = false;

            parser.clear();

            TestSystem.endTimer("OnPopulateMesh End");
        }