Browse Source

Merge pull request #330 from FungusGames/cache-inactive-localizable

Inactive localizeable game objects are now cached #322
master
Chris Gregan 9 years ago
parent
commit
116398373e
  1. 6
      Assets/Fungus/Narrative/Editor/LocalizationEditor.cs
  2. 19
      Assets/Fungus/Narrative/Scripts/Localization.cs

6
Assets/Fungus/Narrative/Editor/LocalizationEditor.cs

@ -86,7 +86,9 @@ namespace Fungus
{ {
return; return;
} }
localization.ClearLocalizeableCache();
string textData = localization.GetStandardText(); string textData = localization.GetStandardText();
File.WriteAllText(path, textData); File.WriteAllText(path, textData);
AssetDatabase.Refresh(); AssetDatabase.Refresh();
@ -102,6 +104,8 @@ namespace Fungus
return; return;
} }
localization.ClearLocalizeableCache();
string textData = File.ReadAllText(path); string textData = File.ReadAllText(path);
localization.SetStandardText(textData); localization.SetStandardText(textData);

19
Assets/Fungus/Narrative/Scripts/Localization.cs

@ -77,13 +77,18 @@ namespace Fungus
} }
} }
public virtual void ClearLocalizeableCache()
{
localizeableObjects.Clear();
}
// Build a cache of all the localizeable objects in the scene // Build a cache of all the localizeable objects in the scene
protected virtual void CacheLocalizeableObjects() protected virtual void CacheLocalizeableObjects()
{ {
Component[] components = GameObject.FindObjectsOfType<Component>(); UnityEngine.Object[] objects = Resources.FindObjectsOfTypeAll(typeof(Component));
foreach (Component component in components) foreach (UnityEngine.Object o in objects)
{ {
ILocalizable localizable = component as ILocalizable; ILocalizable localizable = o as ILocalizable;
if (localizable != null) if (localizable != null)
{ {
localizeableObjects[localizable.GetStringId()] = localizable; localizeableObjects[localizable.GetStringId()] = localizable;
@ -202,11 +207,11 @@ namespace Fungus
} }
} }
// Add everything else that's localizable // Add everything else that's localizable (including inactive objects)
Component[] components = GameObject.FindObjectsOfType<Component>(); UnityEngine.Object[] objects = Resources.FindObjectsOfTypeAll(typeof(Component));
foreach (Component component in components) foreach (UnityEngine.Object o in objects)
{ {
ILocalizable localizable = component as ILocalizable; ILocalizable localizable = o as ILocalizable;
if (localizable != null) if (localizable != null)
{ {
string stringId = localizable.GetStringId(); string stringId = localizable.GetStringId();

Loading…
Cancel
Save