bmfont 下载地址:bmfont1.14a.zip-游戏开发文档类资源-CSDN下载
第一步 导入图片 选择对应id
![](https://img-blog.csdnimg.cn/0f4be0b6b47d422fb3e25984336e33b9.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Iqx55Sf57OWQA==,size_20,color_FFFFFF,t_70,g_se,x_16)
?导入图片
![](https://img-blog.csdnimg.cn/ee8f6e7ba98343eaac7a28d20ec146a8.png)
?数字对应的id? 48![](https://img-blog.csdnimg.cn/1049daae703f41a6b990a1ddffeced4f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Iqx55Sf57OWQA==,size_20,color_FFFFFF,t_70,g_se,x_16)
?![](https://img-blog.csdnimg.cn/45306c09b2214740badfbc0128439c71.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Iqx55Sf57OWQA==,size_20,color_FFFFFF,t_70,g_se,x_16)
?选好后 会在对应的数字下面有一蓝色的点
第二不就是设置格式
![](https://img-blog.csdnimg.cn/a587fcf7b5f54865aa785d815dfa58c0.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Iqx55Sf57OWQA==,size_13,color_FFFFFF,t_70,g_se,x_16) ![](https://img-blog.csdnimg.cn/500574c63866472886ef4ff0eed148fc.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Iqx55Sf57OWQA==,size_10,color_FFFFFF,t_70,g_se,x_16)
然后亣保存就可以了??
?![](https://img-blog.csdnimg.cn/c5a461c9e0e94a958b7ae0a0e6b01f56.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Iqx55Sf57OWQA==,size_11,color_FFFFFF,t_70,g_se,x_16)
保存后会有两个文件
?![](https://img-blog.csdnimg.cn/e34f365d6b8f4a4db4fb604c445db9a4.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Iqx55Sf57OWQA==,size_13,color_FFFFFF,t_70,g_se,x_16)
bmfont 的工作到这里就结束了 接下来进入unity中
?![](https://img-blog.csdnimg.cn/d5e68aa1aa9546319770321f78ec43ac.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Iqx55Sf57OWQA==,size_20,color_FFFFFF,t_70,g_se,x_16)
?点击create 就可以 生成文件
?![](https://img-blog.csdnimg.cn/7a00c50e9d4d4db4a59e1dac38dd547f.png)
?![](https://img-blog.csdnimg.cn/8338e2bb33254e0c9d659269e74d4fc9.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6Iqx55Sf57OWQA==,size_20,color_FFFFFF,t_70,g_se,x_16)
?测试成功
最后附上生成字集文字的代码
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Xml;
using System;
public class BitmapFontExporter : ScriptableWizard
{
[MenuItem("BitmapFontExporter/Create")]
private static void CreateFont()
{
ScriptableWizard.DisplayWizard<BitmapFontExporter>("Create Font");
}
public TextAsset fontFile;
public Texture2D textureFile;
private void OnWizardCreate()
{
if (fontFile == null || textureFile == null)
{
return;
}
string path = EditorUtility.SaveFilePanelInProject("Save Font", fontFile.name, "", "");
if (!string.IsNullOrEmpty(path))
{
ResolveFont(path);
}
}
private void ResolveFont(string exportPath)
{
if (!fontFile) throw new UnityException(fontFile.name + "is not a valid font-xml file");
Font font = new Font();
XmlDocument xml = new XmlDocument();
xml.LoadXml(fontFile.text);
XmlNode info = xml.GetElementsByTagName("info")[0];
XmlNodeList chars = xml.GetElementsByTagName("chars")[0].ChildNodes;
CharacterInfo[] charInfos = new CharacterInfo[chars.Count];
for (int cnt = 0; cnt < chars.Count; cnt++)
{
XmlNode node = chars[cnt];
CharacterInfo charInfo = new CharacterInfo();
charInfo.index = ToInt(node, "id");
charInfo.width = ToInt(node, "xadvance");
charInfo.uv = GetUV(node);
charInfo.vert = GetVert(node);
charInfos[cnt] = charInfo;
}
Shader shader = Shader.Find("Unlit/Transparent");
Material material = new Material(shader);
material.mainTexture = textureFile;
AssetDatabase.CreateAsset(material, exportPath + ".mat");
font.material = material;
font.name = info.Attributes.GetNamedItem("face").InnerText;
font.characterInfo = charInfos;
AssetDatabase.CreateAsset(font, exportPath + ".fontsettings");
}
private Rect GetUV(XmlNode node)
{
Rect uv = new Rect();
uv.x = ToFloat(node, "x") / textureFile.width;
uv.y = ToFloat(node, "y") / textureFile.height;
uv.width = ToFloat(node, "width") / textureFile.width;
uv.height = ToFloat(node, "height") / textureFile.height;
uv.y = 1f - uv.y - uv.height;
return uv;
}
private Rect GetVert(XmlNode node)
{
Rect uv = new Rect();
uv.x = ToFloat(node, "xoffset");
uv.y = ToFloat(node, "yoffset");
uv.width = ToFloat(node, "width");
uv.height = ToFloat(node, "height");
uv.y = -uv.y;
uv.height = -uv.height;
return uv;
}
private int ToInt(XmlNode node, string name)
{
return Convert.ToInt32(node.Attributes.GetNamedItem(name).InnerText);
}
private float ToFloat(XmlNode node, string name)
{
return (float)ToInt(node, name);
}
}
|