Author Topic: Localization problem  (Read 4992 times)

joelsantos

  • Guest
Localization problem
« on: May 01, 2012, 01:38:50 PM »
I probably can fix this but I am not sure if this is a bug or what.
I have successively implemented localization and it's all working, including the popup list to change the language in the options menu.
But when I leave the main menu scene and go into the game one and after that I return to the main menu scene and try to go to the options menu again it shows me an error on the LanguageSelection class
  1. NullReferenceException: Object reference not set to an instance of an object
  2. LanguageSelection.UpdateList () (at Assets/Plugins/NGUI/Interaction/LanguageSelection.cs:33)
Can you help me on what am I doing wrong? Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Localization problem
« Reply #1 on: May 01, 2012, 03:01:20 PM »
Edit: Localization.instance.languages is null, meaning your list of assets isn't present.
« Last Edit: May 01, 2012, 03:02:51 PM by ArenMook »

joelsantos

  • Guest
Re: Localization problem
« Reply #2 on: May 01, 2012, 03:11:33 PM »
  1. if (Localization.instance != null)//It passes this if.. then it's not Localization.instance
  2.  
  3.                 {
  4.  
  5.                         mList.items.Clear();
  6.  
  7.  
  8.  
  9.                         for (int i = 0, imax = Localization.instance.languages.Length; i < imax; ++i)
  10.  
  11.                         {
  12.  
  13.                                 TextAsset asset = Localization.instance.languages[i];
  14.  
  15.                                 if (asset != null) mList.items.Add(asset.name);
  16.  
  17.                         }
  18.  
  19.                         mList.selection = Localization.instance.currentLanguage;
  20.  
  21.                 }

It breaks on the for... But only when I return to the scene. Not sure why. The only thing I notice it's that the first time I run it the _Localize object doesn't appear, but when I return to the main scene it is there along with the prefab Localize.

While I am asking two things:
1 - Is Ngui ready for Chinese language and similar ones? I mean.. I just have to include the font?
2 - (Not really a question I guess) If the Localize key is changed during game-play it doesn't update the labels right? I made a function to address this.. Just asking if it's normal.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Localization problem
« Reply #3 on: May 01, 2012, 03:33:14 PM »
1. Yeah as long as the font has the eastern glyphs exported, you can use them in your labels.
2. You need to broadcast OnLocalize if you change localization at run-time. Look at Localization line 149:

  1. NGUITools.Broadcast("OnLocalize", this);

In regards to your original problem, try adding this to Localization's Awake:

  1. DontDestroyOnLoad(gameObject);

...or better yet, change it to:

  1. void Awake () { if (mInst == null) { mInst = this; DontDestroyOnLoad(gameObject); } else Destroy(this); }

joelsantos

  • Guest
Re: Localization problem
« Reply #4 on: May 01, 2012, 04:13:49 PM »
Yes I thought on changing the Awake function but wasn't sure if something was wrong. It works now. Although I changed the Destroy(this) to Destroy(gameObject) or else it just detaches the script from the object.

I looked at the OnLocalize function but when I noticed that it only did something if (mLanguage != loc.currentLanguage) I did a similar function and I call it directly. It works fine.

Hope I don't have to brother you again. Thank you so much for your time. Have to include you in the Thanks part of the game =P

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Localization problem
« Reply #5 on: May 01, 2012, 08:14:03 PM »
Oh yes, right you are. It should be destroying the game object, not just the script. I'll have this change in the next update. And no worries.