Example #1
0
    private void CalUV()
    {
        Rect    outer = new Rect(m_sprite.x, m_sprite.y, m_sprite.width, m_sprite.height);
        Texture tex   = atlas.spriteMaterial.mainTexture;

        m_outerUV = MikuSpriteData.ConvertToTexCoords(outer, tex.width, tex.height);
    }
Example #2
0
    void DrawText(List <Vector3> fontVertices, List <int> fontTriangles, List <Vector2> fontUV, List <Color> fontColorList, Color fontColor,
                  List <Vector3> picVertices, List <Vector2> picUV, List <int> picTriangles)
    {
        Vector3 pos      = Vector3.zero;
        int     index    = 0;
        int     picIndex = 0;

        for (int i = 0; i < str.Length;)
        {
            char c = str[i];
            if (c == '#' &&
                Char.IsNumber(str[i + 1]) &&
                Char.IsNumber(str[i + 2]) &&
                Char.IsNumber(str[i + 3])
                )
            {
                string name = str.Substring(i + 1, 3);
                if (atlas != null)
                {
                    MikuSpriteData spriteInfo = atlas.GetSpriteDataByName(name);
                    Rect           outer      = new Rect(spriteInfo.x, spriteInfo.y, spriteInfo.width, spriteInfo.height);
                    Texture        tex        = atlas.spriteMaterial.mainTexture;
                    Rect           outerUV    = MikuSpriteData.ConvertToTexCoords(outer, tex.width, tex.height);

                    picVertices.Add(pos + new Vector3(0, spriteInfo.height, 0));
                    picVertices.Add(pos + new Vector3(spriteInfo.width, spriteInfo.height, 0));
                    picVertices.Add(pos + new Vector3(spriteInfo.width, 0, 0));
                    picVertices.Add(pos + new Vector3(0, 0, 0));

                    picUV.Add(new Vector2(outerUV.xMin, outerUV.yMax));
                    picUV.Add(new Vector2(outerUV.xMax, outerUV.yMax));
                    picUV.Add(new Vector2(outerUV.xMax, outerUV.yMin)); // ch.uvBottomRight);
                    picUV.Add(new Vector2(outerUV.xMin, outerUV.yMin)); //ch.uvBottomLeft);

                    picTriangles.Add(4 * picIndex + 0);
                    picTriangles.Add(4 * picIndex + 1);
                    picTriangles.Add(4 * picIndex + 2);
                    picTriangles.Add(4 * picIndex + 0);
                    picTriangles.Add(4 * picIndex + 2);
                    picTriangles.Add(4 * picIndex + 3);

                    // Advance character position
                    pos += new Vector3(spriteInfo.width, 0, 0);
                }

                i = i + 4;
                picIndex++;
            }
            else
            {
                // Get character rendering information from the font
                CharacterInfo ch;
                font.GetCharacterInfo(c, out ch, fontSize);

                fontVertices.Add(pos + new Vector3(ch.minX, ch.maxY, 0));
                fontVertices.Add(pos + new Vector3(ch.maxX, ch.maxY, 0));
                fontVertices.Add(pos + new Vector3(ch.maxX, 0, 0));
                fontVertices.Add(pos + new Vector3(ch.minX, 0, 0));

                fontUV.Add(ch.uvTopLeft);
                fontUV.Add(ch.uvTopRight);
                fontUV.Add(ch.uvBottomRight);
                fontUV.Add(ch.uvBottomLeft);

                fontColorList.Add(fontColor);
                fontColorList.Add(fontColor);
                fontColorList.Add(fontColor);
                fontColorList.Add(fontColor);

                fontTriangles.Add(4 * index + 0);
                fontTriangles.Add(4 * index + 1);
                fontTriangles.Add(4 * index + 2);
                fontTriangles.Add(4 * index + 0);
                fontTriangles.Add(4 * index + 2);
                fontTriangles.Add(4 * index + 3);

                // Advance character position
                pos += new Vector3(ch.advance, 0, 0);
                index++;
                i++;
            }
        }
    }