UGUI艺术字制作
来源:互联网 发布:图书管理系统 php 编辑:程序博客网 时间:2024/06/03 00:36
艺术字制作流程
1、下载BMFont官网
2、首先你还得有美术制作的艺术字,或者自己做几个艺术字。好吧,全部奉上
3、使用BMFont制作艺术字图集
4、将生成的.fnt文件和图集.png文件导入到项目中
5、你还得有NGUI的有关BMFont的代码,不知道在哪?已经全部奉上啦
6、制作CustomFont,按照教程来做挺累的,编辑器上场
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");//这一行很关键,如果用standard的shader,放到Android手机上,第一次加载会很慢 Debug.Log("create font <" + targetFont.name + "> success"); Close(); } }}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
7、给Text指定字体和材质吧,材质用Sprites-Default,颜色就白色
最终效果
需要注意的问题
1、CustomFont用Standard材质,最终放到手机上,第一次加载会很慢,亲测,小米3要3秒,红米2要9秒。既然如此,那就用UI/Default吧,其他的可能也行,我就懒得一个一个测了。至于为什么Standard会造成加载慢,容我思考思考
2、上面的Editor代码执行后,在Unity上能立刻看到效果,但是CustomFont的设置没有立刻保存,需要自己手动保存。博主不才,不知道代码怎么写才能自动保存设置。
3、如果单独某个字显示的位置不对,可以调整下字符Vertex的位置,比如上面效果图中的“+”有点偏上了,可以把“Y”值调小一点。有兴趣也可以研究下其他参数的含义。
版权声明:本文为博主原创文章,未经博主允许不得转载。
0 0
- UGUI艺术字制作
- 【Unity3D ugui】使用艺术字
- 【Unity3D ugui】使用艺术字
- 【Unity3D ugui】使用艺术字
- 巧用CSS制作艺术字
- C#制作 艺术字
- C#制作 艺术字
- C#设计制作艺术字
- PS制作艺术字
- 用C#制作艺术字
- C# 制作 艺术字
- 火焰艺术字效果制作
- photoshop制作艺术字视频教学
- PPT中制作倒影艺术字
- ASP.NET实例:用C#制作艺术字
- 巧用CSS制作特效艺术字(7例)
- UGUI 动手制作字体
- UGUI - 制作九宫贴图
- 代码:用车申请-列表查询
- 归一化方法(Normalization Method)
- 浏览器缓存原理
- 关闭Windows 2008下面应用程序出错后的提示
- 多线程还是多进程的区别
- UGUI艺术字制作
- mysql数据库优化小结
- linked-list-cycle-ii
- 存储过程与事务应用的探究
- java读取jar包中的资源文件或properties配置文件路径的方法
- webstorm快捷键大全
- Speed/accuracy trade-offs for modern convolutional object detectors
- Hibernate逆向工程示例
- SATA SAS SSD 硬盘介绍和评测