溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么使用BMFont制作美術(shù)字體

發(fā)布時間:2021-11-10 16:34:07 來源:億速云 閱讀:322 作者:柒染 欄目:大數(shù)據(jù)

怎么使用BMFont制作美術(shù)字體,相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

怎么使用BMFont制作美術(shù)字體

怎么使用BMFont制作美術(shù)字體

怎么使用BMFont制作美術(shù)字體

怎么使用BMFont制作美術(shù)字體

怎么使用BMFont制作美術(shù)字體

怎么使用BMFont制作美術(shù)字體

怎么使用BMFont制作美術(shù)字體

怎么使用BMFont制作美術(shù)字體

生成 Number.fnt、Number_0.png 兩個文件,將其拖入Unity 相應(yīng)位置,繼續(xù)下一步

怎么使用BMFont制作美術(shù)字體

怎么使用BMFont制作美術(shù)字體

怎么使用BMFont制作美術(shù)字體

怎么使用BMFont制作美術(shù)字體

怎么使用BMFont制作美術(shù)字體

箭頭所指就是我們要得到的最終目標(biāo),在文本處字體使用它就可以了。

在使用 Tools -> BMFont Maker 之前得先完成以下步驟:

using UnityEngine;  
using UnityEditor;  
  
public class BMFontEditor : EditorWindow  
{  
    [MenuItem("Tools/BMFont Maker")]  
    static public void OpenBMFontMaker()  
    {  
        EditorWindow.GetWindow<BMFontEditor>(false, "BMFont Maker", true).Show();  
    }  
  
    [SerializeField]  
    private Font targetFont;  
  
    [SerializeField]  
    private TextAsset fntData;  
  
    [SerializeField]  
    private Material fontMaterial;  
  
    [SerializeField]  
    private Texture2D fontTexture;  
  
    private BMFont bmFont = new BMFont();  
  
    public BMFontEditor()  
    {  
    }  
  
    void OnGUI()  
    {  
        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.x = 0;  
                info.vert.y = -(float)bmInfo.height;  
                info.vert.width = (float)bmInfo.width;  
                info.vert.height = (float)bmInfo.height;  
                info.width = (float)bmInfo.advance;  
                characterInfo[i] = info;  
            }  
            targetFont.characterInfo = characterInfo;  
            if (fontMaterial)  
            {  
                fontMaterial.mainTexture = fontTexture;  
            }  
            targetFont.material = fontMaterial;  
            fontMaterial.shader = Shader.Find("UI/Default");//這一行很關(guān)鍵,如果用standard的shader,放到Android手機上,第一次加載會很慢  
  
            Debug.Log("Create Font <" + targetFont.name + "> Success");  
            Close();  
        }  
    }  
}

將這個類放入工程中,這樣在 Tools 中才可以找到 BMFont Maker,它的作用是賦予字體的詳細信息,由于它是借助 NGUI 來實現(xiàn)的工具,所以得加上 NGUI 中的以下類:

怎么使用BMFont制作美術(shù)字體

看完上述內(nèi)容,你們掌握怎么使用BMFont制作美術(shù)字體的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI