| Parameter | Description |
|---|---|
| filter | Returns true for each selector to evaluate, or null to evaluate them all. |
Locale The locale the chain produces, or null when there is no project locale either.
Runs the startup selector chain and returns the locale it produces, without selecting it.
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
<para>Show the saved language alongside the one the project would otherwise start in.</para>
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); } } }