Return to Snippet

Revision: 59159
at August 21, 2012 18:24 by jquery404


Initial Code
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", "Please 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 (WriteAllBytes is not used here in order to keep compatibility with Unity iPhone)
	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[i]);
		b.Close(); 
	}
 
	DestroyImmediate(tex2);
}

Initial URL


Initial Description
This allow to export any font texture as .png format. This is very much useful to create some great font style effect which we can use as GUI Text i.e. glow, shadow, outer glow etc.
For better view use -
 Mobile->Particles->VertexLit Blended

How to use:
Create an Editor folder and move this script to that folder. Now Go to -> Assets  so you will see a menu called Save Font Texture bingoo!!!
now click on existing font texture which you like to export and click Save Font Texture. Go grab your texture img that's all.

Initial Title
Export font texture

Initial Tags


Initial Language
JavaScript