class in Unity.Localization
Implements interfaces:IStartupLocaleInitialize, IStartupLocaleSelector
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; } } }
| Property | Description |
|---|---|
| PlayerPreferenceKey | The PlayerPrefs key used to store the selected locale code. |