Creation of Textmeshpro font resources for Unity3d plugin

Source: Internet
Author: User

Because the font resource suffix for textmeshpro is. Asset, we need to use the plugin's font tool Textmeshpro-font Asset Creator to generate new font resources. The tool opens the path: Window-font Asset Creator. See the Textmeshpro/user guide/textmesh Pro User guide.pdf This document for detailed instructions.

Because of the use of Chinese fonts, it is necessary to modify the plugin source code. This blog also provides a common txt document for 3,500 fonts, download links:

The following are the steps to make a font:

1. Generate txt font file

Copy the fonts you need into the TXT document, save As, and select Unicode format in the encoding format. For the character encoding format, see the above article. Click the Open link.

2, familiar with the plug-in tool--font Asset Creator


1) Font Source: Set the font format, I use the subordinate, in order to avoid errors, try to go to the Windows system to copy fonts to come. Create a new fonts directory under the project directory, and copy it in.

2) Font size: Set font sizes, preferably using auto Sizing

3) Font Padding: Set the font spacing, pixels, 512*512 size, the spacing is set to 5

4) Atlas Resolution: Set the size of the album, depending on how many fonts are determined

5) Character set: Sets the font content, that is, which fonts are included in the font resources to be made. (1) ASCII: ASCII-only character set, (2) ASCII lowercase: lowercase ascii character set, (3) Asciiuppercase: Uppercase ASCII character set, (4) Numbers+symbols: number + symbol Character set ; (5) Custom range: You can define a range of character sets, but only ASCII and Latin alphabet, such as in the custom window range input 32-126 or 161-255; (6) Custom characters: custom Character set, You can enter custom characters in the custom window, (7) characters from file: read from external files, which is the main content of our article. When you select this mode, you can drag a txt document to the custom window. as shown;

6) Font Style: Font formatting, such as bold, underline, outline, etc. But this setting is non-essential;

7) Font render mode: Font rendering modes. (1) hinted Smooth: anti-aliasing rendering mode, (2) Smooth: and (1) almost, (3) Raster hinted: Raster rendering mode with hinting effect, (4) Raster: Raster mode, without hinting effect ; (5) Signed Distance field 16: Create the standard mode of the SDF font set, use 16X for font sampling, generate more accurate resources, (6) signed Distance Field 32: Use 32X, handle complex fonts or high-frequency curve changes, Note: This process is significantly lower than the 16X mode.

8) Get Kerning Pairs: Temporarily do not understand, also useless to.

9) Generate font Atlas: Generating font resources

Save Textmeshpro Font Asset: Saves the font resource, which is saved in the. Asset suffix file. The save location is placed in the fonts directory you just created, and if you use signed Distance field's render mode, you will be generated with the font resource name followed by SDF.

3, modify Textmeshpro source code

Using the 2 generated font resources, we will quote the given key is not present in the dictionary: The reason is that this plugin is based on ASCII, processing the code logic, so need to make some modifications. Through the code we can see that when saving the font resource, the use of the word typical data structure, the key value using the font is currently encoded under the 10 binary number. such as "A" in the ASCII encoding format is 65, save the key is 65. Another example is the Chinese character "I" in Unicode encoding format is \u6211, converted to decimal is 25105, then save the key value is 25105. and the plug-in source of the default for us to add linefeed (10), Return (13), Space (32) 3 ASCII characters, so this three characters characters using ASCII encoding values. Therefore, when we use Unicode, if we insert ASCII encoded values, we will definitely get an error. So let's comment it out. namely: TextMeshProFont.cs 151: Add/*, 202 Add/*, 208:65 changed to 12290;tmpro_private.cs 453:fonts/arial SDF to Ui/fonts/simli. You can search the Characterdictionary.trygetvalue on your own, and see where you can use the key value you haven't used, comment or modify it. Save, run;

Run the discovery or error, again check found that textmeshpro default to us using Arial SDF, that is, Tmpro_private.cs 453 lines, the font is set to your own font resources. Note the path problem.

At the same time, Textmeshpro sets the length of text to default to 8, but when we pass in a string that is longer than 8 o'clock, it gives us a new array and assigns a value to the original array. See Tmpro_private.cs 287 lines and 792 lines.

4. Tools used

1) Various conversion: http://jinzhi.supfree.net/

2) Conversion of Unicode to Chinese: http://app.baidu.com/2unicode

You can convert the Chinese characters we specify to Unicode encoding in Tool 2. 16 bytes of 16 binary number, such as \u6211, if not enough, in front of the FF, this can Baidu a bit of Unicode size end problem. Then use tool 1 to convert the 16 binary number of the previous step to 10 binary number, you can break the point in the program to find whether this key value is included in the font resource.

5, the use of font resources

This resource cannot be dragged by public and can only be created in the way that the code gets the script Gameobject

As follows:

Include namespace using Tmpro first

private Textmeshpro m_name;private textmeshpro m_sign;private gameobject headshowobj;private GameObject headSignObj;private Transform objtrans;private Transform signtrans;private Vector3 v = new Vector3 (0,2.0f,0);p rivate Vector3 vs = new Vector3 ( 0,2.5f,0); headshowobj = new Gameobject ("PlayerName"); Objtrans = Headshowobj.transform;objtrans.parent = _ controller.trans;//camera.main.transform;objtrans.localposition = Vector3.zero + v;objTrans.localRotation = Quaternion.identity;objtrans.localscale = Vector3.one;objtrans.lookat (Camera.main.transform.position); m_name = Headshowobj.addcomponent<textmeshpro> (); M_name.font = Resources.load ("Ui/fonts/simli", typeof ( Textmeshprofont)) as Textmeshprofont;m_name.fontsize = 4;m_name.isoverlay = True;m_name.alignment = Alignmenttypes.center;m_name.anchor = Anchorpositions.center;m_name.text = "hehe"; 
Run to see the effect, in fact, do not understand the detailed look at the above mentioned documents.


Creation of Textmeshpro font resources for Unity3d plugin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.