NGUI FontMaker 简单使用,以及在文字源文件丢失的情况下,怎么根据UIFont预制获取全部文字

来源:互联网 发布:手机自动连接移动网络 编辑:程序博客网 时间:2024/05/17 01:17
  • 重点在这里 在文字源文件丢失的情况下,怎么根据UIFont预制获取全部文字,但是说明这点之前还是有必要简单说明下NGui FontMaker 的使用,虽然网上有很多使用介绍,如果有大神路过有什么描述不对的地方,欢迎指正:首先上图吧简单介绍下Type,
  • Generated Bitmap :其实它就是根据一种你指定的系统字体生成你指定文字的字体集,直接上图更简单其它不过多介绍,相信大家都能明白,简单说下红色区域,大概意思是如果你不指定一个atlas,当使用这个字体的时候会产生额外的drawCall,简单说明下atlas需要指定的情况,除非你需要你的字体显示的地方和你指定的atlas需要一起显示,并且你的指定的字体内容比较小,这样用比较合适,其他不要指定,因为
    1. 指定:至少一个drawcall,不指定:至少一个drawcall,这个dc量其实跟你做UI的用法有关系,用法不规范,怎么做都不行的
    2. 指定的话其实就是把你的需要的文字以一个sprite的方式在altlas上
    3. atlas和文字绑定,就算你没用到atlas里的图片,在你使用文字的时候,它也会把整个atlas加载到内存中去
  • imported Bitmap: 这个类型就需要另一个工具的支持了,BMFont,网上都可以下载得到,分享地址http://download.csdn.net/detail/yhy2218/9394795,这个工具会生成两个文件,一个.fnt(包含你指定的文字),和一个.png(根据你选择的文字生成的png图片)  Font Data 需要你把.fnt修改为.txt文件,然后拖上去就行了,Texture就是指定那个.png,atlas 和上面介绍的一样
  • Dynamic 这个很简单了,就是你指定一个系统字体就行了
  1. 以上只是简单介绍,下面介绍重点:文字源文件丢失的情况下,怎么根据UIFont预制获取全部文字随便创建一个UIlabel,在随便写入几个字,在脚本UILabel里有个变量,在这里稍微改动下就能得到你的UIFont包含的所有文字
    public UIFont bitmapFont{get{return mFont;}set{if (mFont != value){RemoveFromPanel();mFont = value;mTrueTypeFont = null;MarkAsChanged();Debug.Log("bitmap font  ="+value);Debug.Log("bitmap font  ="+mFont.bmFont.glyphs.Count);string text = "";foreach(BMGlyph gly in mFont.bmFont.glyphs){char c = (char)gly.index;text += c.ToString();}File.WriteAllText(Application.dataPath+"/Fonts/newAllText.txt",text);}}
    你的所有文字都会包含在bmfont类里的glyphs这个list里面,BMGlyph类会定义你的单个文字的相关信息,
    public class BMGlyph{public int index;// Index of this glyph (used by BMFont)public int x;// Offset from the left side of the texture to the left side of the glyphpublic int y;// Offset from the top of the texture to the top of the glyphpublic int width;// Glyph's width in pixelspublic int height;// Glyph's height in pixelspublic int offsetX;// Offset to apply to the cursor's left position before drawing this glyphpublic int offsetY; // Offset to apply to the cursor's top position before drawing this glyphpublic int advance;// How much to move the cursor after printing this characterpublic int channel;// Channel mask (in most cases this will be 15 (RGBA, 1+2+4+8)public List<int> kerning;
    截取一部分,都有注释,说下index字段,它是char 转换为int以后代表的值,反转一下就能得到你想要的字符串文字了,然后你就可以根据生成的文字重新生成新的字体集了

1 0
原创粉丝点击