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:
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.
Answer by Herman-Tulleken
Dec 19, 2010 at 07:17 PM
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;
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 AntiAliased 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:
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.
I also added this feature request: http://feedback.unity3d.com/forums/15792-unity/suggestions/1308575-dynamic-font-rendering-on-mobile-devices-?ref=title
Interesting that you compiled a function from the editor into a dll to be available.
Answer by Statement
Dec 15, 2010 at 02:21 PM
See the documenation of Font. I paste some relevant parts for quick access.
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).
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?
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.
Thanks for the link to the docs ;) I am using Unicode, not Dynamic, as the game is for Android / iPhone.
Sigh, beats me. I haven't done asian fonts or Andriod / iPhone development. I think you're better off waiting for someone else to give a better answer.
Just to test, I tried Dynamic. It works to the same extent as the default font... that is, some characters are missing. (And no, it is not the font).
You might want to update your question to make it clear this is on a mobile platform.
Good idea; i'll do it.
Answer by Avi
Jan 02, 2011 at 10:30 AM
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
Answer by jonas-echterhoff
Dec 15, 2010 at 02:33 PM
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.
But this only is supported on Desktop platforms. The problem Herman has is that this is for a mobile product. It wasn't immediately clear, he just commented on my answer.
Thanks Jonas. I have updated my question to include the extra information - the game is for Android / iPhone, so Dynamic fonts is not and option. And I also made sure the fonts I tried have all the necessary characters :) Perhaps the support for Unicode is not as complete as claimed in the docs.
Hi Herman, I wrote a small tutorial for you : http://avi.my/2011/01/dynamic-font-in-unity3d-iphone-or-android/ I am not sure if it will solve your Chinese Character or not, but it solves Dynamic Character problem. I did not have a chinese character to try out. Could you follow this and see it works or not?
@Avi The tutorial looks very cool, and it is sure helpful for general fonts. However, because the Chinese character set is so large, it does not look good when saved to a texture :(
hmm... I understand. Ya you need a lot of fonts for that. Sorry cant help :(
Answer by bnmindstorm
Jun 29, 2012 at 01:07 PM
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/
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
2 People are following this question.
Unicode Character Unity iPhone
Multiple sizes of same font (for mobile)
french accent and dynamic fonts
Streaming assets android
Problems with Asian Font Rendering