docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Event StringChanged

    Provides a callback that will be invoked when the translated string has changed. The following events will trigger an update:

    • The first time the action is added to the event.
    • The SelectedLocale changing.
    • If the string is currently using a IVariable which supports IVariableValueChanged and it's value has changed.
    • When RefreshString() is called.
    • The TableReference or TableEntryReference changing.
    When the first LocalizedString.ChangeHandler is added, a loading operation (see CurrentLoadingOperationHandle) automatically starts. When the loading operation is completed, the localized string value is sent to the subscriber. If you add additional subscribers after loading has completed, they are also sent the latest localized string value. This ensures that a subscriber will always have the correct localized value regardless of when it was added.
    Namespace: UnityEngine.Localization
    Assembly: Unity.Localization.dll
    Syntax
    public event LocalizedString.ChangeHandler StringChanged
    Returns
    Type Description
    LocalizedString.ChangeHandler
    Examples

    This example shows how the StringChanged event can be used to trigger updates to a string.

    public class LocalizedStringWithEvents : MonoBehaviour
    {
        public LocalizedString myString;
    
        string localizedText;
    
        /// <summary>
        /// Register a ChangeHandler. This is called whenever the string needs to be updated.
        /// </summary>
        void OnEnable()
        {
            myString.StringChanged += UpdateString;
        }
    
        void OnDisable()
        {
            myString.StringChanged -= UpdateString;
        }
    
        void UpdateString(string s)
        {
            localizedText = s;
        }
    
        void OnGUI()
        {
            EditorGUILayout.LabelField(localizedText);
        }
    }
    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)