//this script changes the guiText color of the object and should be attached to an guiText object
//from http://www.plinan.com
var TextColor : Color = Color.white; // define the color for this guiText object
function Start () {
guiText.material.color = TextColor;
}
Description
If you’ve ever wanted to get at the auto-generated font bitmap that Unity creates when importing vector fonts, now’s your chance. SaveFontTexture saves that bitmap as a .png file so you can edit it, add whatever whizbang effects you want to it, and then use it as a colored font, using the TexturedFont shader and a GUIText object.
Script Setup
You must place the script in a folder named Editor in your project’s Assets folder for it to work properly. When this is done, you will then have a Save Font Texture menu item in the Assets menu. Find the TrueType font you want in Unity and open the root, which reveals the auto-generated material and texture. Click once on the texture (called “font Texture”) and select the Save Font Texture menu item. Choose a file name and location in the file dialog, and hit save. (Technically this script will work for any texture in Alpha8 format, if for some reason you wanted to save it as a .png file.)
Customizing and Using Font Textures
1. Get the TrueType font that you want to modify in Unity at the desired Font Size (so that you can use Pixel Correct in the GUI_Text object that will use it for crisp rendering).
2. Use this script (installed as described above) to save the texture Unity generates automatically for the font.
3. Edit that texture file in Photoshop to use in your project.
4. Create a new Material in Unity.
5. Set the texture of the material to the modified texture.
6. Set the shader of the material to the TexturedFont Shader.
7. In any scene GUI_Text objects that will use the custom font, apply the original font to the object then change its material to the custom material created in steps 4-6.
Hi, when I try to follow the instructions to Save Font Texture with the “font Texture” selected. I get an error:
UnityException: Texture ‘font Texture’ is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.UnityEngine.Texture2D.GetPixels (Int32 miplevel) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/ExportGenerated/Editor/Graphics.cs:1035)UnityEngine.Texture2D.GetPixels () (at C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/ExportGenerated/Editor/Graphics.cs:1029)SaveFontTexture.SaveFontTexture () (at Assets/Editor/SaveFontTexture.js:27)
I tried creating a TextureImporter:
var texImporter = TextureImporter.GetAtPath(texFile) as TextureImporter;
Where texFile is:
var texFile = AssetDatabase.GetAssetPath(tex) as String;
But the file reads the ttf file, which doesn’t have a TextureImporter, but a TrueTypeFontImporter component.
What should I do to fix the problem?
Thanks
Hi Miyudreams,
Hmm not sure what the problem is. It could be because of the different Unity version, as this post was written when I was using Unity 2.6. Were you able to solve this problem?
This might help: http://forum.anbsoft.com/viewtopic.php?f=9&t=98
-Brandon
How do you deal with font texture tiling? It just cuts straight through my outlines and shadows.
Cool article. Add more pictures showing off what you’re doing?
This is what we’ve been working on :)
http://www.pepwuper.com/portfolio/item/my-giants/
Categories
Comments