docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Event SelectedLocaleChanged

    Event that is sent when the SelectedLocale is changed.

    Namespace: UnityEngine.Localization.Settings
    Assembly: Unity.Localization.dll
    Syntax
    public static event Action<Locale> SelectedLocaleChanged
    Returns
    Type Description
    Action<Locale>
    Examples

    This shows how to keep track of the current selected Locale.

    public class SelectedLocaleChangedExample : MonoBehaviour
    {
        Locale currentLocale;
    
        void OnEnable()
        {
            LocalizationSettings.SelectedLocaleChanged += OnSelectedLocaleChanged;
        }
    
        void OnDisable()
        {
            LocalizationSettings.SelectedLocaleChanged -= OnSelectedLocaleChanged;
        }
    
        IEnumerable Start()
        {
            // Get the initial selected locale value
            var selectedLocale = LocalizationSettings.SelectedLocaleAsync;
            yield return selectedLocale;
            currentLocale = selectedLocale.Result;
        }
    
        void OnSelectedLocaleChanged(Locale locale)
        {
            currentLocale = locale;
        }
    
        void OnGUI()
        {
            if (currentLocale != null)
                GUILayout.Label("The current locale is " + currentLocale.LocaleName);
        }
    }
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)