Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Konstantin on April 17, 2014, 08:57:51 AM

Title: Localization bug: clears current locale when duplicated
Post by: Konstantin on April 17, 2014, 08:57:51 AM
Let's assume we have a scene with Localization script. It is loaded twice and Localization is duplicated. The second instance will destroy itself, but it will also break static fields. Here is some code from Localization.cs:

  1. void Awake ()
  2. {
  3.         if (mInstance == null) // mInstance is not null, this is the second Localization
  4.         {
  5.         ...
  6.         }
  7.         else Destroy(gameObject); // Destroy duplicate which will call OnDisable
  8. }
  9.  
  10. void OnDisable ()
  11. {
  12.         localizationHasBeenSet = false;
  13.         mLanguageIndex = -1;
  14.         mDictionary.Clear(); // BOOM! current locale texts wiped out
  15.         mOldDictionary.Clear();
  16. }
  17.  
Title: Re: Localization bug: clears current locale when duplicated
Post by: ArenMook on April 17, 2014, 12:18:26 PM
Thanks! Add the "if (mInstance != this) return;" to the top of OnDisable.

P.S. There is no reason to add the Localization script to the scene anymore. I strongly advise you to remove it as with the next update you will get errors otherwise.