EvaluateStartupLocale(Func<IStartupLocaleSelector, bool>)
Runs the startup selector chain and returns the locale it produces, without selecting it.
Read time 1 minuteLast updated 14 days ago
Definition
- Type: Method
- Namespace: Unity.Localization
- Assembly: UnityEngine.LocalizationRuntimeModule
public Locale EvaluateStartupLocale(Func<IStartupLocaleSelector, bool> filter = null)
Parameters
Returns true for each selector to evaluate, or null to evaluate them all.
Returns
Type | Description |
|---|---|
| Locale | The locale the chain produces, or null when there is no project locale either. |
Remarks
This is the same evaluation LocalizationSettings.InitializeAsync performs, so the result is directly comparable with LocalizationSettings.SelectedLocale. Pass a filter to leave selectors out: excluding the one that applies a saved user choice gives the locale the project would have started with, which is the value to show as the default and to restore when the user resets. Falls back to LocalizationSettings.ProjectLocale when no selector matches. Selectors are asked again on every call, so a selector with side effects sees more than one call.
Additional Resources: LocalizationSettings.StartupSelector, LocalizationSettings.StartupSelectors
Show the saved language alongside the one the project would otherwise start in.
Examples
using Unity.Localization;using UnityEngine;namespace Unity.Localization.Samples{ public class EvaluateStartupLocaleExample : MonoBehaviour { void Start() { var settings = LocalizationSettings.Instance; // What the project would start in with the saved choice ignored, for a "Reset to default" button. var fallback = settings.EvaluateStartupLocale(selector => selector is not PlayerPrefLocaleSelector); Debug.Log($"Playing in {LocalizationSettings.SelectedLocale?.LocaleName}, default is {fallback?.LocaleName}"); if (settings.StartupSelector is PlayerPrefLocaleSelector) Debug.Log("The language came from a saved choice rather than the project default."); } public void ResetToDefault() { var settings = LocalizationSettings.Instance; LocalizationSettings.SelectedLocale = settings.EvaluateStartupLocale(selector => selector is not PlayerPrefLocaleSelector); } }}