Search Unity

show GUIContent with Chinese

Discussion in 'Immediate Mode GUI (IMGUI)' started by bohu, Apr 22, 2008.

  1. bohu

    bohu

    Joined:
    Feb 25, 2008
    Posts:
    2
    Hello everybody


    function OnGUI () {

    GUI.Button (Rect (10,10,100,20), GUIContent ("Click me", "This is the tooltip"));

    GUI.Label (Rect (10,40,100,40), GUI.tooltip);
    }



    how can I show "Click me", "This is the tooltip"with Chinese?
     
  2. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    First you need a UNICODE font that supports Chinese letters. Make sure its a TTF. Google something like unicode chinese ttf and you should find what you need. Drop that into the project folder and unity will build an appropriate font. If it beachballs, just wait five minutes or so. It may take a little time to import.

    Next, create a GUISkin. http://unity3d.com/support/documentation/Components/class-GUISkin.html
    And assign the font you have imported to the font in the GUISkin.

    Then you need to have a Game Object that contains your GUI scripting. And you need to declare the Guiskin and use it like this:

    Code (csharp):
    1. var nameofyourguiskin : GUISkin;
    and this:

    Code (csharp):
    1. function OnGUI () {
    2.     GUI.skin = nameofyourguiskin;
    3.     GUI.Button (Rect (10,10,100,20), GUIContent ("点击我", "这是工具套子"));
    4.     GUI.Label (Rect (10,40,100,40), GUI.tooltip);
    5. }
    6.  
    You also need to make sure that you are saving your scripts as unicode formatted files. That way, you can include non-ascii characters when you save it.

    If I'm forgetting anything, someone please post the rest of this process. But I think that's most of it.

    I hope this helps.
     
  3. dongke

    dongke

    Joined:
    Apr 17, 2008
    Posts:
    93
    Hi hai_ok:
    I have tried your method but falled, because I don't know how to save chinese charactor in script, everytime I save it , It only display ?????? for unicode. anything I am wrong?

    thankyou for replying.

    dongke