1. First, you can just throw a font. The simplest one is to throw an Arial.
Set Font size, such as 24
In character, Unicode is generally not required unless you want to make Chinese flowers. Select ASCII default set. If only uppercase or lowercase letters are required, select the appropriate one.
2. Create a directory named editor. Create a Javascript file and press enter (MAC) or F2 (WIN) to change it to savefonttexture without adding. js. Double-click and paste the following code:
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", "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 );
} Save and close the editor.
In addition, if you use the iPhone version, use this script:
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
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 );
} 3 at this time, the assests menu of unity has an option, save font texture. In the project panel, find the font that you just dragged in, such as Arial, find the font texture in it, select it, and click "Save font texture" in the menu to open a save dialog box, save the graph to any location in the assests directory of your project.
4. Use Photoshop to open the saved image. If you do not change the name, you should call it font texture.png. You will see a font material diagram. Now you can edit the graph. If you are not familiar with Photoshop, you may find that the image cannot be clearly viewed. Then, add a layer below and fill it in black to make it easy to edit. You can also change the color of the transparent background mesh in the settings.
This figure is changed at will.
[Attachment = 0: 33oqz9vk1_2.jpeg [/Attachment: 33oqz9vk]
5. Press cmd + S or Ctrl + S to save the changes. Switch back to unity. Create a shader, take a name, and paste the following content.
Code:
Shader "Gui/textured text shader"
{
Properties {
_ Maintex ("font texture", 2d) = "white "{}
_ Color ("text color", color) = (1, 1, 1)
}
Subshader {
Lighting off
Cull off
Ztest always
Zwrite off
Fog {mode off}
Tags {"queue" = "Transparent "}
Pass {
Blend srcalpha oneminussrcalpha
Settexture [_ maintex] {
Constantcolor [_ color]
Combine texture * constant, texture * constant
}
}
}
} Save the post.
6. Create a new material and just name it. For example, I name it font mat. Select GUI> textured text shader in the shader. This shader is the shader you just created. Fonttexture: select the font you have changed. Text color is white.
7. Throw a GUI text (gameobject in the menu> create other-> GUI text. Font selects the font you threw in, such as Arial and material, and selects the material you just created, for example, I use font mat.
Complete.
In this way, any Shadow character can be used. I wanted to write a script for processing today. Later I went to the official forum for half a day and finally found a solution.