unity将图片转换成字体的方法

这篇文章主要为大家详细介绍了unity将图片转换成字体的方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了unity利用图片来生成字体的具体代码,供大家参考,具体内容如下

开发中,可能会用到需要将图片转换成字体的需求。

BMFONT 插件 导入图片

然后生成 .fnt 和 .png-600 两个文件 (文件格式可以在设置中更改)
将这两个文件导入unity 将png 切割成精灵
创建材质、将贴图拖上去。
创建字体、将材质拖上去。

数据怎么算出来的公式百度上面有,此处略去。也可以利用代码来生成

 using UnityEngine; using System.Collections; using System; using System.Xml; public class CustomFontImportor : MonoBehaviour { public Font font; public TextAsset textAsset; void Awake() { if (font == null || textAsset == null) { Debug.LogError("请设置font和textAsset."); return; } XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(textAsset.text); int totalWidth = Convert.ToInt32(xmlDocument["font"]["common"].Attributes["scaleW"].InnerText); int totalHeight = Convert.ToInt32(xmlDocument["font"]["common"].Attributes["scaleH"].InnerText); XmlElement xml = xmlDocument["font"]["chars"]; ArrayList characterInfoList = new ArrayList(); for (int i = 0; i 

以上就是unity将图片转换成字体的方法的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 其他教程