Unity 使用的字体需要什么
Unity 的文本组件需要 .fontsetting 类型的文件。
这个文件主要组成是:字体图、挂载了字体图的material、字符的配置(指定单个字符占的起点和宽高、字体图的UV)。将这三个数据配置完,字体便合格了。
字体图哪里来
美术出单个字符的图,然后用BMFont,或者任意字体工具导出成一张图集。
挂在了字体图的材质哪里来
Unity 里面右键创建一个,Shader 选 UI/Default 即可,代码设置下材质的 mainTexture 为字体图集。
字符的配置哪里来
使用BMFont导出后,会有一份 .fnt 文件,里面记录了字体的配置,包括字符宽高,起点坐标,对应到字体图集的UV等。这里需要借助工具或者自己写个脚本,读取字符配置,写入 fontsetting 中。