Browse Source

Fixed localization language does not persist between scenes #271

master
chrisgregan 9 years ago
parent
commit
4d68516985
  1. 6
      Assets/Fungus/Narrative/Scripts/Commands/SetLanguage.cs
  2. 10
      Assets/Fungus/Narrative/Scripts/Localization.cs

6
Assets/Fungus/Narrative/Scripts/Commands/SetLanguage.cs

@ -12,12 +12,18 @@ namespace Fungus
[Tooltip("Code of the language to set. e.g. ES, DE, JA")] [Tooltip("Code of the language to set. e.g. ES, DE, JA")]
public string languageCode; public string languageCode;
public static string mostRecentLanguage = "";
public override void OnEnter() public override void OnEnter()
{ {
Localization localization = GameObject.FindObjectOfType<Localization>(); Localization localization = GameObject.FindObjectOfType<Localization>();
if (localization != null) if (localization != null)
{ {
localization.SetActiveLanguage(languageCode, true); localization.SetActiveLanguage(languageCode, true);
// Cache the most recently set language code so we can continue to
// use the same language in subsequent scenes.
mostRecentLanguage = languageCode;
} }
Continue(); Continue();

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

@ -56,6 +56,16 @@ namespace Fungus
[NonSerialized] [NonSerialized]
public string notificationText = ""; public string notificationText = "";
public virtual void OnLevelWasLoaded(int level)
{
// Check if a language has been selected using the Set Language command in a previous scene.
if (SetLanguage.mostRecentLanguage != "")
{
// This language will be used when Start() is called
activeLanguage = SetLanguage.mostRecentLanguage;
}
}
public virtual void Start() public virtual void Start()
{ {
CacheLocalizeableObjects(); CacheLocalizeableObjects();

Loading…
Cancel
Save