Unity3D 教程:制作彩色字体
Posted on 2013 年 06 月 22 日 by U3d / Unity3D 基础教程/被围观 56 次
1.首先随便扔进去一个字体,最简单的比如扔进去一个 arial。
设置好 Font Size,比如 24。Character 里一般来说不需要 Unicode,除非你要把中
文做成花。我选 ASCII default set。如果只要大写或者小写,自己选。
2.建一个目录,取名叫 Editor。然后创建一个 Javascript,按回车(Mac)或者 F2(Win)
改名成 SaveFontTexture,不用加.js。然后双击,贴进去下面代码:
@MenuItem ("Assets/Save Font Texture")
static function SaveFontTexture () {
var tex = Selection.activeObject as Texture2D;
EditorUtility.DisplayDialog("No texture selected", "lease select a
texture", "Cancel");
if (tex.format != TextureFormat.Alpha8) {
EditorUtility.DisplayDialog("Wrong format", "Texture must be in
uncompressed Alpha8 format", "Cancel");
}//Unity3D
教程手册:
www.unitymanual.com
// Convert Alpha8 texture to ARGB32 texture so it can be saved as a
PNG
var texPixels = tex.GetPixels();
var tex2 = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32,
false);
tex2.SetPixels(texPixels);
var texBytes = tex2.EncodeToPNG();
var fileName = EditorUtility.SaveFilePanel("Save font texture", "",
"font Texture", "png");
if (fileName.Length > 0) {
var f : FileStream = new FileStream(fileName,
FileMode.OpenOrCreate, FileAccess.Write);
var b : BinaryWriter = new BinaryWriter(f);