Author Topic: Force Update UILable with UILocalize in editor  (Read 3137 times)

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Force Update UILable with UILocalize in editor
« on: August 09, 2012, 05:03:15 AM »
I like to force update a(or multible) UILable with UILocalize in editor.

So i wrote a custom inspector for UILocalize:

  1. [CustomEditor(typeof(UILocalize))]
  2. public class UILocalizeInspector : Editor
  3. {
  4.        
  5.         UILocalize mUILocalize;
  6.         public override void OnInspectorGUI ()
  7.         {
  8.                 DrawDefaultInspector();
  9.                 EditorGUIUtility.LookLikeControls(80f);
  10.                 mUILocalize = target as UILocalize;
  11.                 if(GUILayout.Button("Localize!"))
  12.                 {
  13.                         mUILocalize.Localize();
  14.                         mUILocalize.gameObject.GetComponent<UILabel>().MarkAsChanged();
  15.                 }
  16.         }
  17. }

My problem is that the update process of UILabel sheems to call the UIRoot Scritp witch is Producing the following error in the editor around 10 times:


  1. !IsPlayingOrAllowExecuteInEditMode ()
  2. UnityEngine.Component:BroadcastMessage(String, Object, SendMessageOptions)
  3. UIRoot:Broadcast(String, Object) (at Assets/NGUI/Scripts/UI/UIRoot.cs:91)
  4. Localization:Load(TextAsset) (at Assets/NGUI/Scripts/Internal/Localization.cs:157)
  5. Localization:set_currentLanguage(String) (at Assets/NGUI/Scripts/Internal/Localization.cs:100)
  6. Localization:get_currentLanguage() (at Assets/NGUI/Scripts/Internal/Localization.cs:69)
  7. UILocalize:Localize() (at Assets/NGUI/Scripts/UI/UILocalize.cs:73)
  8. UILocalizeInspector:OnInspectorGUI() (at Assets/Scripts/GUI/Editor/UILocalizeInspector.cs:24)
  9. UnityEditor.DockArea:OnGUI()

Without:
  1.  mUILocalize.gameObject.GetComponent<UILabel>().MarkAsChanged();
there are no errors.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Force Update UILable with UILocalize in editor
« Reply #1 on: August 09, 2012, 02:07:52 PM »
Localization system is not marked as ExecuteInEditMode, so it won't work unless the application is playing. Same with UIRoot. The system is simply not designed to be executed in edit mode.