コード例 #1
0
        private void buildGlyphs()
        {
            glyphs = new GlyphData[256];
            for (int i = 4; i < fontData.Length; i++)
            {
                string[] data = fontData[i].Split(spaceSeparator, StringSplitOptions.RemoveEmptyEntries);

                int id     = int.Parse(data[1].Substring(3));
                int x      = int.Parse(data[2].Substring(2));
                int y      = int.Parse(data[3].Substring(2));
                int width  = int.Parse(data[4].Substring(6));
                int height = int.Parse(data[5].Substring(7));
                int xOff   = int.Parse(data[6].Substring(8));
                int yOff   = int.Parse(data[7].Substring(8));
                int xAdv   = int.Parse(data[8].Substring(9));

                //Unity's texRect's origin is bottom left
                Rect textureCoordinates = new Rect(x / glyphTextureWidth, ((glyphTextureHeight - y - height) / glyphTextureHeight), width / glyphTextureWidth, height / glyphTextureHeight);

                glyphs[id] = new GlyphData(
                    textureCoordinates,
                    width,
                    height,
                    xOff,
                    yOff,
                    xAdv);
            }
        }
コード例 #2
0
        public void debug(String str)
        {
            foreach (int id in str)
            {
                System.Console.Write("char= " + (char)id + "\tid= " + id + "\t");

                GlyphData g = getGlyphFromID(id);
                if (g != null)
                {
                    System.Console.WriteLine(g.ToString());
                }
                else
                {
                    System.Console.WriteLine("No Glyph Found");
                }
            }
        }
コード例 #3
0
        private void internalDrawString(String text, float x, float y, float scale, HorizontalAlignment hAlign, Color color, bool drawGUI)
        {
            //byte[] ascii = defaultEncoding.GetBytes(text);

            float totalWidth = 0;

            foreach (int id in text)
            {
                GlyphData glyph = getGlyphFromID(id);
                totalWidth += glyph.xAdvance * scale;
            }

            float hAlignFactor = 0;

            if (hAlign == HorizontalAlignment.RIGHT)
            {
                hAlignFactor = -totalWidth;
            }

            float cursorX = x;

            foreach (int id in text)
            {
                GlyphData glyph = getGlyphFromID(id);
                destRect.x      = cursorX + (glyph.xOffset + hAlignFactor) * scale;
                destRect.y      = y + glyph.yOffset * scale;
                destRect.width  = glyph.width * scale;
                destRect.height = glyph.height * scale;

                if (drawGUI)
                {
                    GUI.DrawTextureWithTexCoords(destRect, fontTexture, glyph.srcRect);
                }
                else
                {
                    Graphics.DrawTexture(destRect, fontTexture, glyph.srcRect, 0, 0, 0, 0, color);
                }

                cursorX += glyph.xAdvance * scale;
            }
        }