TypogenicText.BlitString C# (CSharp) Метод

BlitString() приватный Метод

private BlitString ( string str, float cursorX, float cursorY, List vertexPointers = null ) : float
str string
cursorX float
cursorY float
vertexPointers List
Результат float
    float BlitString(string str, float cursorX, float cursorY, List<int> vertexPointers = null)
    {
        TGlyph prevGlyph = null;
        Rect r;
        bool inControlCode = false;
        int requestedMaterial = 0;

        foreach (char c in str)
        {
            int charCode = (int)c;

            if (inControlCode)
            {
                inControlCode = false;

                if (charCode >= 48 && charCode <= 57) // 0-9
                {
                    requestedMaterial = charCode - 48;

                    if (requestedMaterial < _materialCount)
                    {
                        _currentMaterial = requestedMaterial;
                    }
                    else
                    {
                        Debug.LogWarning(string.Format(
                            "Requested material {0} out of range.", requestedMaterial
                        ));
                    }

                    if (EnableClickSupport)
                    {
                        AddPlaceholderGlyphBounds();
                    }

                    continue;
                }
            }
            else
            {
                if (charCode == 92) // Backslash
                {
                    inControlCode = true;
                    if (EnableClickSupport)
                    {
                        AddPlaceholderGlyphBounds();
                    }
                    continue;
                }
            }

            TGlyph glyph = Font.Glyphs.Get(charCode);

            if (glyph == null)
                continue;

            if (charCode == 32)
            {
                // Assuming here that spaces should not be clickable.
                if (EnableClickSupport)
                {
                    AddPlaceholderGlyphBounds();
                }
                cursorX += glyph.xAdvance * Size + Tracking;
                continue;
            }

            float kerning = 0f;

            if (prevGlyph != null)
                kerning = prevGlyph.GetKerning(charCode) * Size;

            if (vertexPointers != null)
                vertexPointers.Add(m_Vertices.Count);

            r = new Rect(
                cursorX + glyph.xOffset * Size + kerning,
                cursorY + glyph.yOffset * Size,
                glyph.rect.width * Size,
                glyph.rect.height * Size
            );

            BlitQuad(r, glyph);

            // Only need to store glyph bounds if click support is enabled.
            if (EnableClickSupport)
            {

                // Click bounds for glyphs are based on allocated space, not rendered space.
                // Otherwise we'll end up with unclickable dead zones between glyphs.
                r.width = glyph.xAdvance * Size;
                // And Y coordinates are just not handled the same at all.
                r.y = -cursorY - r.height - glyph.yOffset * Size;

                // Calculate relative world-space bounds for this glyph and store them.
                Bounds b = new Bounds(
                    new Vector3(r.x + r.width/2f, r.y + r.height/2f, 0f),
                    new Vector3(r.width, r.height, r.height)
                );

                if (Stationary)
                {
                    // Bake the rotation and position into the bounds so we
                    // don't have to recalculate them on the fly later.
                    b = TranslateBounds(b);
                }
                StoreGlyphBounds(b);
            }

            cursorX += glyph.xAdvance * Size + Tracking + kerning;
            prevGlyph = glyph;
        }

        if (cursorX > Width)
            Width = cursorX;

        return cursorX;
    }