From 4d685169854598ea0e5b684c10cbcb4b5393c14d Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Thu, 8 Oct 2015 12:19:26 +0100 Subject: [PATCH] Fixed localization language does not persist between scenes #271 --- .../Fungus/Narrative/Scripts/Commands/SetLanguage.cs | 6 ++++++ Assets/Fungus/Narrative/Scripts/Localization.cs | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/Assets/Fungus/Narrative/Scripts/Commands/SetLanguage.cs b/Assets/Fungus/Narrative/Scripts/Commands/SetLanguage.cs index d7323305..22d91709 100644 --- a/Assets/Fungus/Narrative/Scripts/Commands/SetLanguage.cs +++ b/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")] public string languageCode; + public static string mostRecentLanguage = ""; + public override void OnEnter() { Localization localization = GameObject.FindObjectOfType(); if (localization != null) { 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(); diff --git a/Assets/Fungus/Narrative/Scripts/Localization.cs b/Assets/Fungus/Narrative/Scripts/Localization.cs index d960a562..3700baab 100644 --- a/Assets/Fungus/Narrative/Scripts/Localization.cs +++ b/Assets/Fungus/Narrative/Scripts/Localization.cs @@ -56,6 +56,16 @@ namespace Fungus [NonSerialized] 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() { CacheLocalizeableObjects();