![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
生成 Number.fnt、Number_0.png 兩個文件,將其拖入Unity 相應位置,繼續下一步工具
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
箭頭所指就是咱們要獲得的最終目標,在文本處字體使用它就能夠了。字體
在使用 Tools -> BMFont Maker 以前得先完成如下步驟:spa
-
-
-
-
public class BMFontEditor : EditorWindow
-
-
[MenuItem("Tools/BMFont Maker")]
-
static public void OpenBMFontMaker()
-
-
EditorWindow.GetWindow
<BMFontEditor>(false, "BMFont Maker", true).Show();
-
-
-
-
-
-
-
private TextAsset fntData;
-
-
-
private Material fontMaterial;
-
-
-
private Texture2D fontTexture;
-
-
private BMFont bmFont = new BMFont();
-
-
-
-
-
-
-
-
targetFont = EditorGUILayout.ObjectField("Target Font", targetFont, typeof(Font), false) as Font;
-
fntData = EditorGUILayout.ObjectField("Fnt Data", fntData, typeof(TextAsset), false) as TextAsset;
-
fontMaterial = EditorGUILayout.ObjectField("Font Material", fontMaterial, typeof(Material), false) as Material;
-
fontTexture = EditorGUILayout.ObjectField("Font Texture", fontTexture, typeof(Texture2D), false) as Texture2D;
-
-
if (GUILayout.Button("Create BMFont"))
-
-
BMFontReader.Load(bmFont, fntData.name, fntData.bytes); //借用NGUI封裝的讀取類
-
CharacterInfo[] characterInfo = new CharacterInfo[bmFont.glyphs.Count];
-
for (int i = 0; i
< bmFont.glyphs.Count; i++)
-
-
BMGlyph bmInfo = bmFont.glyphs[i];
-
CharacterInfo info = new CharacterInfo();
-
info.index = bmInfo.index;
-
info.uv.x = (float)bmInfo.x / (float)bmFont.texWidth;
-
info.uv.y = 1 - (float)bmInfo.y / (float)bmFont.texHeight;
-
info.uv.width = (float)bmInfo.width / (float)bmFont.texWidth;
-
info.uv.height = -1f * (float)bmInfo.height / (float)bmFont.texHeight;
-
-
info.vert.y = -(float)bmInfo.height;
-
info.vert.width = (float)bmInfo.width;
-
info.vert.height = (float)bmInfo.height;
-
info.width = (float)bmInfo.advance;
-
-
-
targetFont.characterInfo = characterInfo;
-
-
-
fontMaterial.mainTexture = fontTexture;
-
-
targetFont.material = fontMaterial;
-
fontMaterial.shader = Shader.Find("UI/Default");//這一行很關鍵,若是用standard的shader,放到Android手機上,第一次加載會很慢
-
-
Debug.Log("Create Font <" + targetFont.name + "> Success");
-
-
-
-
將這個類放入工程中,這樣在 Tools 中才能夠找到 BMFont Maker,它的做用是賦予字體的詳細信息,因爲它是藉助 NGUI 來實現的工具,因此得加上 NGUI 中的如下類:code
![](http://static.javashuo.com/static/loading.gif)