How do I display Chinese in Unity?

I can display Chinese characters fine using the default skin. But as soon as I try to skin them, using my own fonts, I can't get them to display (in the editor).

The fonts are imported using the Unicode setting, but fonts that support Chinese characters (as confirmed in tests in other programs) just does not work.

This post suggests that it must be possible: http://forum.unity3d.com/threads/20358-Chinese-IME-into-Unity

Unfortunately all the links are broken.

As if to further mock me, the text even displays correctly in the inspector!

Edit: It seems even the default font does not work completely (some characters are missing). These characters are definitely in the font; I have tested this with another program.

Edit: This is for Android iPhone, thus using Dynamic a font is not an option.

Just to test for interest sake, I tried dynamic fonts. They work (just on PC, of course), except that the same characters are missing (in the editor). Just to emphasize, the same fonts display all the characters in other programs.

By using larger textures, I could get the characters to display, but they looked so awful that I ended up using images for text. Because we only have 20 strings in game (and no dynamic text except for numbers), the following simple scheme worked well.

I implemented an editor feature to render the text. Because it requires System.Drawing which is unaccessible from the Unity project, I had to compile the core function into a DLL. The basic function takes a string, and several parameters to control the color, font, etc.

Anti-aliasing does not work correctly on a transparent background, so I drew white text on black, and then used this for the alpha of the final image (in a single color - the color of the font).

void RenderText(string text, ... /*lots of parameters.*/)
{
   Bitmap image = new Bitmap(width, height);
   Graphics g = Graphics.FromImage(image);
   g.SmoothingMode = SmoothingMode.AntiAlias;

   //render white text on black
   g.DrawString(text, /*lots of parameters*/);

   // Pseudocode follows!

   // this happens at development time
   // there is no concern for efficiency

   foreach pixel in image
   {
      alpha = pixel.r; //r, g, and b are all the same - see note below
      pixel.rgb = fontColor;
      pixel.a = alpha;
   }

   image.Save(filename);  
}

Note: On windows, the `Quality` smoothness type results in text that is rendered using cool type. In this case, the channels are not the same; I assume an aggregate of the channels can be used, but it should probably be the same as plain `AntiAlias`ed text.

My editor plugin simply calls this function for each string in the game.

The actual game then uses these images (loaded as Textures) for labels, instead of strings when the language is Chinese.

The method is crude - here are the disadvantages:

  • Not suitable for massive amounts of texts or dynamic text.
  • Not suitable to support large number of languages.
  • It's a pain to keep the look-and-feel the same as the text for other languages, especially if many styles are used. (I store a style type each string, and then render it out accordingly).

On the upside, for a small number of strings and one or two languages, it is simple to implement (much simpler than to implement your own character-based font renderer), and it looks pretty.

See the documenation of Font. I paste some relevant parts for quick access.

Dynamic fonts

Unity 3.0 adds support for dynamic font rendering. When you set the Characters drop-down in the Import Settings to Dynamic, Unity will not pre-generate a texture with all font characters. Instead, it will use the OS built-in font rendering to create the texture on the fly. This has the advantage that it can save in download size and texture memory, especially when you are using a font which is commonly included in user systems, so you don't have to include the font data, or when you need to support asian languages or large font sizes (which would make the font textures very large using normal font textures).

  • Dynamic fonts are currently only supported on Desktop platforms (Mac and Windows).

Unicode support

Unity has full unicode support. Unicode text allows you to display German, French, Danish or Japanese characters that are usually not supported in an ASCII character set. You can also enter a lot of different special purpose characters like arrow signs or the option key sign, if your font supports it.

To use unicode characters, choose either Unicode or Dynamic from the Characters drop-down in the Import Settings. You can now display unicode characters with this font. If you are using a GUIText or Text Mesh, you can enter unicode characters into the Component's Text field in the Inspector. Note that the Inspector on Mac may not show the unicode characters correctly.


I don't know about other methods you can use since I haven't been working with asian fonts myself. Did you try setting it to dynamic?


  • It seems that unicode have problems on iPhone.

This leads me to question what "full unicode support" means. Is it enabled for iPhone? Does it only apply for desktop application? Is it a typo in the help? Are people misinterpreting the manual are make errors? It's hard to tell.

As Statement wrote, try the "Dynamic" option. "Unicode" will pre-generate a texture of all the characters contained in the font. However, many fonts don't have chinese characters. "Dynamic" will use the OS fallback mechanisms for font rendering, so chinese characters should work regardless of whether the font has them or not.

I had the same problem and the only thing I could use was 3d text. I know this is not the best solution but it might help to know it works.

I basically had to put the 3d text under the camera as child so that it stays on the screen even when the camera moves. Then I had to resize to scale of 0.5 in XYZ.

EDIT: Oh and just to add on, to update the 3d text you got to add like

var hitCount : TextMesh;
hitCount.GetComponent(TextMesh).text = ballCount.ToString() + " ball";

As you can see, my ballcount was the data I was getting.

Quite messy I know, but I could not find a better way yet

We did create a package that supports asiatic fonts by rendering them directly as text mesh and thus not using textures to store the font. If you think you may be interested by this package, have a look at our website : http://ttftext.computerdreams.org/

[1445-ttftextasiatic.png|1445]

Hi,

I have made an asset for localization using Excel. Please take a look and let me know what you think !

http://u3d.as/content/dream-creations/excel-local