在网上搜到了这段代码 可以生成字体的textrue,但是这个js脚本是把TTF字库中所有的字符都转化成.PNG的图片了,如果是unicode的话生成的textrue就太大了 ,所以各位大侠能不能想想办法只生成需要的字的textrue,不必考虑汉字录入的问题。import System.IO;@MenuItem ("Assets/Save Font Texture")static function SaveFontTexture () {
var tex = Selection.activeObject as Texture2D;
if (tex == null) {
EditorUtility.DisplayDialog("No texture selected", "lease select a texture", "Cancel");
return;
}
if (tex.format != TextureFormat.Alpha8) {
EditorUtility.DisplayDialog("Wrong format", "Texture must be in uncompressed Alpha8 format", "Cancel");
return;
} // 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);
// Save texture
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);
for (var i = 0; i < texBytes.Length; i++) b.Write(texBytes);
b.Close();
}
DestroyImmediate(tex2);
}
var tex = Selection.activeObject as Texture2D;
if (tex == null) {
EditorUtility.DisplayDialog("No texture selected", "lease select a texture", "Cancel");
return;
}
if (tex.format != TextureFormat.Alpha8) {
EditorUtility.DisplayDialog("Wrong format", "Texture must be in uncompressed Alpha8 format", "Cancel");
return;
} // 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);
// Save texture
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);
for (var i = 0; i < texBytes.Length; i++) b.Write(texBytes);
b.Close();
}
DestroyImmediate(tex2);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货