#if UNITY_EDITOR using UnityEngine; using System.Collections; using System; using UnityEditor; using System.IO; using System.Xml; public static class BitmapFontImporter { [MenuItem("Assets/Generate Bitmap Font")] public static void GenerateFont () { TextAsset selected = (TextAsset)Selection.activeObject; string rootPath = Path.GetDirectoryName (AssetDatabase.GetAssetPath (selected)); Texture2D texture = AssetDatabase.LoadAssetAtPath (rootPath + "/" + selected.name + ".png", typeof(Texture2D)) as Texture2D; if (!texture) throw new UnityException ("Texture2d asset doesn't exist for " + selected.name); string exportPath = rootPath + "/" + Path.GetFileNameWithoutExtension (selected.name); Work (selected, exportPath, texture); } private static void Work (TextAsset import, string exportPath, Texture2D texture) { if (!import) throw new UnityException (import.name + "is not a valid font-xml file"); XmlDocument xml = new XmlDocument (); xml.LoadXml (import.text); XmlNode info = xml.GetElementsByTagName ("info") [0]; XmlNode common = xml.GetElementsByTagName("common")[0]; XmlNodeList chars = xml.GetElementsByTagName ("chars") [0].ChildNodes; float texW = texture.width; float texH = texture.height; CharacterInfo[] charInfos = new CharacterInfo[chars.Count]; Rect r; for (int i=0; i 0) { SerializedProperty kerningsProp = mFont.FindProperty("m_KerningValues"); for (int i = 0; i < kerningsCount; i++) { kerningsProp.InsertArrayElementAtIndex(i); XmlNode kerning = kernings.ChildNodes[i]; SerializedProperty kern = kerningsProp.GetArrayElementAtIndex(i); kern.FindPropertyRelative("second").floatValue = float.Parse(kerning.Attributes.GetNamedItem("amount").InnerText); ; } }*/ mFont.ApplyModifiedProperties(); AssetDatabase.CreateAsset (font, exportPath + ".fontsettings"); } private static float ToFloat (XmlNode node, string name) { return float.Parse (node.Attributes.GetNamedItem (name).InnerText); } } #endif