x


UTF-8 for foreign language characters on GUI

My project has some foreign characters like "á" or "ñ" but the GUI does not display them.

I guess is because the mMnodevelop Editor tool that came along with unity is not encoding my scripts with UTF-8.

Well I'm unable to find a way to do so, I check all the options in the editor and I couldn't find it, can somebody please point it out for me?

Thanks!

more ▼

asked Aug 06, 2012 at 10:11 PM

Ordosx gravatar image

Ordosx
5 31 22 24

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Here is how I did to use Unicode for GUI in my projects.

  • Create a GUISkin and set your font in

'Font'. - Use the GUISkin in OnGUI. Look at the code below.

Like this:

  public GUISkin guiSkin; // for in case you want to set it in your editor
  void OnGUI()
  {
      GUI.skin = guiSkin;
 
      // GUI.Label(new Rect(10.0f, 400.0f, 500.0f, 500.0f), "something");
  }

If it doesn't work, select the font you're using and set 'Unicode' in the 'Character' property.

more ▼

answered Aug 07, 2012 at 02:29 AM

afromofu gravatar image

afromofu
1 6 4 5

(comments are locked)
10|3000 characters needed characters left

Unity does not use UTF-8 but UTF-16. There is an option in Monodevelop to set the default character encoding (don't remember where).

more ▼

answered Aug 07, 2012 at 09:33 AM

Kryptos gravatar image

Kryptos
8.3k 2 11 50

Thanks for the answer, but some issues remain :( If I use the guiSkin tip from afromofu It works as soon as I set the text in my script, but it still doesn't work with text that I bring from an XML file.

I create the xml with notepad++ so I sure I encode it with UTF-8 (besides the headline of the file is ), so I guess the problem is in the way I read the xml file.

My code is like this:

var xmlDoc : XmlDocument = new XmlDocument();

var ta : TextAsset = Resources.Load(persistentSc.textsFile);

xmlDoc.LoadXml(ta.ToString());

var nodes: XmlNodeList = xmlDoc.SelectNodes("tutorial");

...

var aux : String;

aux = nodes[0].SelectSingleNode("text").InnerText;

By now aux already has no foreign characteres so I guess the problem could be in "ta".

Any help?

Thanks!

Aug 07, 2012 at 11:23 AM Ordosx

YES!, that works! Thanks a lot Kryptos!

Aug 07, 2012 at 12:19 PM Ordosx

Depends on what language you're using...UTF-8 works fine for Unityscript, but not C#.

Aug 07, 2012 at 02:23 PM Eric5h5

Like I said UTF-8 is not fully supported. You have to encode your file with UTF-16. In Notepad++ this will be UCS-2 Little Endian.

Aug 07, 2012 at 12:14 PM Kryptos
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5892
x83
x18

asked: Aug 06, 2012 at 10:11 PM

Seen: 4199 times

Last Updated: Aug 07, 2012 at 02:23 PM