コード例 #1
0
    static IntFontInfo ParseBMFontText(string path)
    {
        IntFontInfo fontInfo = new IntFontInfo();

        FileInfo     finfo  = new FileInfo(path);
        StreamReader reader = finfo.OpenText();
        string       line;

        while ((line = reader.ReadLine()) != null)
        {
            string[] tokens = line.Split(' ');

            if (tokens[0] == "common")
            {
                fontInfo.lineHeight = int.Parse(FindKeyValue(tokens, "lineHeight"));
                fontInfo.scaleW     = int.Parse(FindKeyValue(tokens, "scaleW"));
                fontInfo.scaleH     = int.Parse(FindKeyValue(tokens, "scaleH"));
                int pages = int.Parse(FindKeyValue(tokens, "pages"));
                if (pages != 1)
                {
                    EditorUtility.DisplayDialog("Fatal error", "Only one page supported in font. Please change the setting and re-export.", "Ok");
                    return(null);
                }
            }
            else if (tokens[0] == "char")
            {
                IntChar thisChar = new IntChar();
                thisChar.id       = int.Parse(FindKeyValue(tokens, "id"));
                thisChar.x        = int.Parse(FindKeyValue(tokens, "x"));
                thisChar.y        = int.Parse(FindKeyValue(tokens, "y"));
                thisChar.width    = int.Parse(FindKeyValue(tokens, "width"));
                thisChar.height   = int.Parse(FindKeyValue(tokens, "height"));
                thisChar.xoffset  = int.Parse(FindKeyValue(tokens, "xoffset"));
                thisChar.yoffset  = int.Parse(FindKeyValue(tokens, "yoffset"));
                thisChar.xadvance = int.Parse(FindKeyValue(tokens, "xadvance"));
                fontInfo.chars.Add(thisChar);
            }
            else if (tokens[0] == "kerning")
            {
                IntKerning thisKerning = new IntKerning();
                thisKerning.first  = int.Parse(FindKeyValue(tokens, "first"));
                thisKerning.second = int.Parse(FindKeyValue(tokens, "second"));
                thisKerning.amount = int.Parse(FindKeyValue(tokens, "amount"));
                fontInfo.kernings.Add(thisKerning);
            }
            else if (tokens[0] == "page")
            {
                fontInfo.texName = FindKeyValue(tokens, "file");
            }
        }
        reader.Close();

        return(fontInfo);
    }
コード例 #2
0
    static IntFontInfo ParseBMFontXml(XmlDocument doc)
    {
        IntFontInfo fontInfo = new IntFontInfo();

        XmlNode nodeCommon = doc.SelectSingleNode("/font/common");

        fontInfo.scaleW     = ReadIntAttribute(nodeCommon, "scaleW");
        fontInfo.scaleH     = ReadIntAttribute(nodeCommon, "scaleH");
        fontInfo.lineHeight = ReadIntAttribute(nodeCommon, "lineHeight");
        int pages = ReadIntAttribute(nodeCommon, "pages");

        if (pages != 1)
        {
            EditorUtility.DisplayDialog("Fatal error", "Only one page supported in font. Please change the setting and re-export.", "Ok");
            return(null);
        }

        foreach (XmlNode node in doc.SelectNodes(("/font/pages/page")))
        {
            fontInfo.texName = ReadStringAttribute(node, "file");
        }

        foreach (XmlNode node in doc.SelectNodes(("/font/chars/char")))
        {
            IntChar thisChar = new IntChar();
            thisChar.id       = ReadIntAttribute(node, "id");
            thisChar.x        = ReadIntAttribute(node, "x");
            thisChar.y        = ReadIntAttribute(node, "y");
            thisChar.width    = ReadIntAttribute(node, "width");
            thisChar.height   = ReadIntAttribute(node, "height");
            thisChar.xoffset  = ReadIntAttribute(node, "xoffset");
            thisChar.yoffset  = ReadIntAttribute(node, "yoffset");
            thisChar.xadvance = ReadIntAttribute(node, "xadvance");

            fontInfo.chars.Add(thisChar);
        }

        foreach (XmlNode node in doc.SelectNodes("/font/kernings/kerning"))
        {
            IntKerning thisKerning = new IntKerning();
            thisKerning.first  = ReadIntAttribute(node, "first");
            thisKerning.second = ReadIntAttribute(node, "second");
            thisKerning.amount = ReadIntAttribute(node, "amount");

            fontInfo.kernings.Add(thisKerning);
        }

        return(fontInfo);
    }
コード例 #3
0
ファイル: BMFont.cs プロジェクト: groscalin/unityScriptLab
    static IntFontInfo ParseBMFontXml(XmlDocument doc)
    {
        IntFontInfo fontInfo = new IntFontInfo();

        XmlNode nodeCommon = doc.SelectSingleNode("/font/common");
        fontInfo.scaleW = ReadIntAttribute(nodeCommon, "scaleW");
        fontInfo.scaleH = ReadIntAttribute(nodeCommon, "scaleH");
        fontInfo.lineHeight = ReadIntAttribute(nodeCommon, "lineHeight");
        int pages = ReadIntAttribute(nodeCommon, "pages");
        if (pages != 1)
        {
            EditorUtility.DisplayDialog("Fatal error", "Only one page supported in font. Please change the setting and re-export.", "Ok");
            return null;
        }

        foreach (XmlNode node in doc.SelectNodes(("/font/pages/page")))
        {
            fontInfo.texName = ReadStringAttribute(node, "file");
        }

        foreach (XmlNode node in doc.SelectNodes(("/font/chars/char")))
        {
            IntChar thisChar = new IntChar();
            thisChar.id = ReadIntAttribute(node, "id");
            thisChar.x = ReadIntAttribute(node, "x");
            thisChar.y = ReadIntAttribute(node, "y");
            thisChar.width = ReadIntAttribute(node, "width");
            thisChar.height = ReadIntAttribute(node, "height");
            thisChar.xoffset = ReadIntAttribute(node, "xoffset");
            thisChar.yoffset = ReadIntAttribute(node, "yoffset");
            thisChar.xadvance = ReadIntAttribute(node, "xadvance");

            fontInfo.chars.Add(thisChar);
        }

        foreach (XmlNode node in doc.SelectNodes("/font/kernings/kerning"))
        {
            IntKerning thisKerning = new IntKerning();
            thisKerning.first = ReadIntAttribute(node, "first");
            thisKerning.second = ReadIntAttribute(node, "second");
            thisKerning.amount = ReadIntAttribute(node, "amount");

            fontInfo.kernings.Add(thisKerning);
        }

        return fontInfo;
    }
コード例 #4
0
ファイル: BMFont.cs プロジェクト: groscalin/unityScriptLab
    static IntFontInfo ParseBMFontText(string path)
    {
        IntFontInfo fontInfo = new IntFontInfo();

        FileInfo finfo = new FileInfo(path);
        StreamReader reader = finfo.OpenText();
        string line;
        while ((line = reader.ReadLine()) != null)
        {
            string[] tokens = line.Split( ' ' );

            if (tokens[0] == "common")
            {
                fontInfo.lineHeight = int.Parse( FindKeyValue(tokens, "lineHeight") );
                fontInfo.scaleW = int.Parse( FindKeyValue(tokens, "scaleW") );
                fontInfo.scaleH = int.Parse( FindKeyValue(tokens, "scaleH") );
                int pages = int.Parse( FindKeyValue(tokens, "pages") );
                if (pages != 1)
                {
                    EditorUtility.DisplayDialog("Fatal error", "Only one page supported in font. Please change the setting and re-export.", "Ok");
                    return null;
                }
            }
            else if (tokens[0] == "char")
            {
                IntChar thisChar = new IntChar();
                thisChar.id = int.Parse(FindKeyValue(tokens, "id"));
                thisChar.x = int.Parse(FindKeyValue(tokens, "x"));
                thisChar.y = int.Parse(FindKeyValue(tokens, "y"));
                thisChar.width = int.Parse(FindKeyValue(tokens, "width"));
                thisChar.height = int.Parse(FindKeyValue(tokens, "height"));
                thisChar.xoffset = int.Parse(FindKeyValue(tokens, "xoffset"));
                thisChar.yoffset = int.Parse(FindKeyValue(tokens, "yoffset"));
                thisChar.xadvance = int.Parse(FindKeyValue(tokens, "xadvance"));
                fontInfo.chars.Add(thisChar);
            }
            else if (tokens[0] == "kerning")
            {
                IntKerning thisKerning = new IntKerning();
                thisKerning.first = int.Parse(FindKeyValue(tokens, "first"));
                thisKerning.second = int.Parse(FindKeyValue(tokens, "second"));
                thisKerning.amount = int.Parse(FindKeyValue(tokens, "amount"));
                fontInfo.kernings.Add(thisKerning);
            }
            else if (tokens[0] == "page")
            {
                fontInfo.texName = FindKeyValue(tokens, "file");
            }
        }
        reader.Close();

        return fontInfo;
    }