/* * private bool LoadTextFile(string inFileName) * { * //FileInfo theSourceFile = null; * TextAsset textFile = (TextAsset)AssetBundleManager.Instance.LoadFromResources("MainMenuResources", inFileName, typeof(TextAsset)); * if ( textFile == null ) * { * Debug.Log(inFileName + " -- was not found"); * return false; * } * * // puzdata.text is a string containing the whole file. To read it line-by-line: * StringReader reader = new StringReader(textFile.text); * if ( reader == null ) * { * Debug.Log("puzzles.txt not found or not readable"); * return false; * } * else * { * ParseFNTFile(reader); * return true; * } * } */ /// <summary>Parses the FNT file.</summary> void ParseFNTFile(StringReader inReader) { m_CharSet = new BitmapCharacterSet(); m_CharSet.MaxCharHeight = 0; //string fntFile = Utility.GetMediaFile( m_fntFile ); //StreamReader stream = new StreamReader( fntFile ); StringReader stream = inReader; string line; char[] separators = new char[] { ' ', '=' }; while ((line = stream.ReadLine()) != null) { string[] tokens = line.Split(separators); if (tokens[0] == "info") { // Get rendered size for (int i = 1; i < tokens.Length; i++) { if (tokens[i] == "size") { m_CharSet.RenderedSize = int.Parse(tokens[i + 1]); } } } else if (tokens[0] == "common") { // Fill out BitmapCharacterSet fields for (int i = 1; i < tokens.Length; i++) { if (tokens[i] == "lineHeight") { m_CharSet.LineHeight = int.Parse(tokens[i + 1]); } else if (tokens[i] == "base") { m_CharSet.Base = int.Parse(tokens[i + 1]); } else if (tokens[i] == "scaleW") { m_CharSet.Width = int.Parse(tokens[i + 1]); } else if (tokens[i] == "scaleH") { m_CharSet.Height = int.Parse(tokens[i + 1]); } } } else if (tokens[0] == "char") { // New BitmapCharacter int index = 0; for (int i = 1; i < tokens.Length; i++) { if (tokens[i] == "id") { index = int.Parse(tokens[i + 1]); m_CharSet.Characters[index] = new BitmapCharacter(); m_CharSet.Characters[index].Char = index; } else if (tokens[i] == "x") { m_CharSet.Characters[index].X = int.Parse(tokens[i + 1]); } else if (tokens[i] == "y") { m_CharSet.Characters[index].Y = int.Parse(tokens[i + 1]); } else if (tokens[i] == "width") { m_CharSet.Characters[index].Width = int.Parse(tokens[i + 1]); } else if (tokens[i] == "height") { m_CharSet.Characters[index].Height = int.Parse(tokens[i + 1]); m_CharSet.MaxCharHeight = Mathf.Max(m_CharSet.MaxCharHeight, m_CharSet.Characters[index].Height); } else if (tokens[i] == "xoffset") { m_CharSet.Characters[index].XOffset = int.Parse(tokens[i + 1]); } else if (tokens[i] == "yoffset") { m_CharSet.Characters[index].YOffset = int.Parse(tokens[i + 1]); } else if (tokens[i] == "xadvance") { m_CharSet.Characters[index].XAdvance = int.Parse(tokens[i + 1]); } } } else if (tokens[0] == "kerning") { // Build kerning list int index = 0; Kerning k = new Kerning(); for (int i = 1; i < tokens.Length; i++) { if (tokens[i] == "first") { index = int.Parse(tokens[i + 1]); } else if (tokens[i] == "second") { k.Second = int.Parse(tokens[i + 1]); } else if (tokens[i] == "amount") { k.Amount = int.Parse(tokens[i + 1]); } } m_CharSet.Characters[index].KerningList.Add(k); } } stream.Close(); }
/// <summary>Creates a new bitmap font.</summary> /// <param name="faceName">Font face name.</param> public BitmapFont( string fntFile, string textureFile ) { m_quads = new List<FontQuad>(); m_strings = new List<StringBlock>(); m_fntFile = fntFile; m_textureFile = textureFile; m_charSet = new BitmapCharacterSet(); ParseFNTFile(); }