Adding localize component on runtime
9 years 11 months ago #402
by intacto
Adding localize component on runtime was created by intacto
For some reason I have to add the localize component to some gameobjects on runtime.
I'm adding the component with addcomponent and use the setterm method to set the key.
But it throws out some errors like:
ArgumentNullException: Argument cannot be null.
Parameter name: key
System.Collections.Generic.Dictionary`2[System.String,I2.Loc.TermData].TryGetValue (System.String key, I2.Loc.TermData& value) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:588)
I2.Loc.LanguageSource.GetTermData (System.String term) (at Assets/I2/Localization/Scripts/LanguageSource.cs:246)
I2.Loc.LocalizeInspector.OnGUI_SelectKey (System.String& Term, Boolean Inherited) (at Assets/I2/Localization/Editor/Inspectors/LocalizeInspector.cs:258)
I2.Loc.LocalizeInspector.OnGUI_SecondaryTerm (Boolean OnOpen) (at Assets/I2/Localization/Editor/Inspectors/LocalizeInspector.cs:205)
I2.Loc.LocalizeInspector.OnGUI_Terms () (at Assets/I2/Localization/Editor/Inspectors/LocalizeInspector.cs:148)
I2.Loc.LocalizeInspector.OnInspectorGUI () (at Assets/I2/Localization/Editor/Inspectors/LocalizeInspector.cs:82)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Inspector/InspectorWindow.cs:1094)
UnityEditor.DockArea:OnGUI()
Is there some sort of initialization that should be done before using it?
Thanks in advance.
I'm adding the component with addcomponent and use the setterm method to set the key.
But it throws out some errors like:
ArgumentNullException: Argument cannot be null.
Parameter name: key
System.Collections.Generic.Dictionary`2[System.String,I2.Loc.TermData].TryGetValue (System.String key, I2.Loc.TermData& value) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:588)
I2.Loc.LanguageSource.GetTermData (System.String term) (at Assets/I2/Localization/Scripts/LanguageSource.cs:246)
I2.Loc.LocalizeInspector.OnGUI_SelectKey (System.String& Term, Boolean Inherited) (at Assets/I2/Localization/Editor/Inspectors/LocalizeInspector.cs:258)
I2.Loc.LocalizeInspector.OnGUI_SecondaryTerm (Boolean OnOpen) (at Assets/I2/Localization/Editor/Inspectors/LocalizeInspector.cs:205)
I2.Loc.LocalizeInspector.OnGUI_Terms () (at Assets/I2/Localization/Editor/Inspectors/LocalizeInspector.cs:148)
I2.Loc.LocalizeInspector.OnInspectorGUI () (at Assets/I2/Localization/Editor/Inspectors/LocalizeInspector.cs:82)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Inspector/InspectorWindow.cs:1094)
UnityEditor.DockArea:OnGUI()
Is there some sort of initialization that should be done before using it?
Thanks in advance.
Please Log in or Create an account to join the conversation.
9 years 11 months ago #403
by intacto
Replied by intacto on topic Adding localize component on runtime
I found the bug I think, even if I call SetTerm it has a empty string control and the secondary key is kept null:
public void SetTerm (string primary, string secondary)
{
if (!string.IsNullOrEmpty(primary))
Term = primary;
if (!string.IsNullOrEmpty(secondary))
SecondaryTerm = secondary;
OnLocalize ();
}
public void SetTerm (string primary, string secondary)
{
if (!string.IsNullOrEmpty(primary))
Term = primary;
if (!string.IsNullOrEmpty(secondary))
SecondaryTerm = secondary;
OnLocalize ();
}
Please Log in or Create an account to join the conversation.
9 years 11 months ago #409
by Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
Replied by Frank on topic Adding localize component on runtime
Hi,
You are right! Normally when a localized object is created at RunTime it is created from a Prefab and so all values are initialized.
But when adding the Localize component directly, it doesn't set all values.
I corrected that in the new version by modifying line 23-27 in Localize.cs to initialize the terms:
Thanks,
Frank
You are right! Normally when a localized object is created at RunTime it is created from a Prefab and so all values are initialized.
But when adding the Localize component directly, it doesn't set all values.
I corrected that in the new version by modifying line 23-27 in Localize.cs to initialize the terms:
public string mTerm = string.Empty, // if Target is a Label, this will be the text, if sprite, this will be the spriteName, etc
mTermSecondary = string.Empty; // if Target is a Label, this will be the font Name, if sprite, this will be the Atlas name, etc
public string FinalTerm = string.Empty,
FinalSecondaryTerm = string.Empty;
Thanks,
Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
To get the betas as soon as they are ready,
check this out
Please Log in or Create an account to join the conversation.
Time to create page: 0.174 seconds