Unity TextMeshPro uses Chinese fonts

TextMeshPro

  TextMeshPro is a new generation font for Unity and the ultimate text solution for Unity. It is a perfect alternative to Unity UI Text and the old Text Mesh. Powerful, easy to use, and efficient. Currently, TextMeshPro's support for Chinese is okay, but it is not available by default and needs to be generated by yourself.
  This article introduces the method of generating Chinese font files in TextMeshPro and analyzes the reasons why Chinese garbled characters may appear.

Chinese font generation method

  First prepare a native Chinese font file (.ttf, .ttc), etc. There are many font files that come with Windows that can be used in the C:\Windows\Fonts directory under the Windows 10 operating system. Find a font with Chinese characters, copy it directly to the desktop with Ctrl+C or Ctrl+V, and you can see the font file. Double-click the font file to preview the font. Right-click on the properties of the font file. If you see that the file is less than 1MB in size, it most likely does not have Chinese fonts . Even if you can see Chinese after double-clicking, it is Fallback for other fonts.

  This is the regular font of Microsoft Yahei font, which can be used to generate TextMeshPro font. Added to Unity.
  After seeing the font, you can directly right-click Create-TextMeshPro-Font Asset to generate TextMeshPro font, but the generated font file is a dynamic font file, that is, only the words used are added to the font file, and they will not be added when they are not used. This method is relatively simple. The generated font file is very small (the size of a few characters is the same as the size of a few words), but the performance is poor, and there may be many bugs. For example, fonts that are not added will display garbled characters. .
Insert image description here
  The following focuses on how to generate static fonts.

Static font generation method

  In Unity, open Window-TextMeshPro-FontAssetCreator on the top menu bar to open the panel.
Insert image description here
  Import the TextMeshPro package. If you do not import it, the text will not be displayed (English will not be displayed either).
Insert image description here
  Drag the native font file into the Source Font File.
Insert image description here
  You can view the detailed introduction in this blog for each parameter.   What I want to say about creating TextMeshPro Chinese fonts in Unity is that creating Chinese fonts is different from English fonts. English characters are few and relatively simple, so there are several parameters that need to be paid attention to when creating Chinese .   It is best to choose Characters from File for Character Set. Character File specifies a Chinese character file. File link: all Chinese characters . After opening the link, right-click the webpage and click "Save webpage as" to save all Chinese character files "chinese.txt" and then drag them into it. The Atlas Resolution parameter must be as large as possible, and the Sampling Point Size must be as small as possible, so that Chinese garbled characters do not appear! The Padding parameter is 1/10 of the Sampling Point Size.   After the generation is successful, click Save and drag the generated font file into the TextMeshPro text. You can see that no matter how you enlarge it, the font will not be distorted.


  
Insert image description here

Insert image description here
Insert image description here

Guess you like

Origin blog.csdn.net/qq_44284055/article/details/132393719