Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

PlayerPrefLocaleSelector

class in Unity.Localization


Implements interfaces:IStartupLocaleInitialize, IStartupLocaleSelector

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Stores the last selected locale in PlayerPrefs and restores it on startup.

On startup this selector reads the locale code saved under PlayerPrefLocaleSelector.PlayerPreferenceKey from PlayerPrefs and selects the matching locale. Because it also implements IStartupLocaleInitialize, it subscribes to LocalizationSettings.SelectedLocaleChanged after initialization and writes the new code whenever the locale changes, so the choice persists across sessions. If no code is stored or no available locale matches, PlayerPrefLocaleSelector.GetStartupLocale returns null and the next selector runs. Add it to LocalizationSettings.StartupSelectors to enable persistence.

Additional resources: IStartupLocaleSelector, IStartupLocaleInitialize, LocalizationSettings

<para>Reads the previously saved locale when the game starts.</para>

using Unity.Localization;

namespace Unity.Localization.Samples { public class PlayerPrefLocaleSelectorExample { public Locale Run() { var selector = new PlayerPrefLocaleSelector { PlayerPreferenceKey = "selected-locale" }; Locale saved = selector.GetStartupLocale(LocalizationSettings.Instance); return saved; } } }

Properties

Property Description
PlayerPreferenceKey The PlayerPrefs key used to store the selected locale code.