Export font texture


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. import System.IO;
  2. @MenuItem ("Assets/Save Font Texture...")
  3.  
  4. static function SaveFontTexture () {
  5. var tex = Selection.activeObject as Texture2D;
  6. if (tex == null) {
  7. EditorUtility.DisplayDialog("No texture selected", "Please select a texture", "Cancel");
  8. return;
  9. }
  10. if (tex.format != TextureFormat.Alpha8) {
  11. EditorUtility.DisplayDialog("Wrong format", "Texture must be in uncompressed Alpha8 format", "Cancel");
  12. return;
  13. }
  14.  
  15. // Convert Alpha8 texture to ARGB32 texture so it can be saved as a PNG
  16. var texPixels = tex.GetPixels();
  17. var tex2 = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false);
  18. tex2.SetPixels(texPixels);
  19.  
  20. // Save texture (WriteAllBytes is not used here in order to keep compatibility with Unity iPhone)
  21. var texBytes = tex2.EncodeToPNG();
  22. var fileName = EditorUtility.SaveFilePanel("Save font texture", "", "font Texture", "png");
  23. if (fileName.Length > 0) {
  24. var f : FileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
  25. var b : BinaryWriter = new BinaryWriter(f);
  26. for (var i = 0; i < texBytes.Length; i++) b.Write(texBytes[i]);
  27. b.Close();
  28. }
  29.  
  30. DestroyImmediate(tex2);
  31. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.