docs.unity3d.com

Localization 1.5.1

Search Results for

    Show / Hide Table of Contents

    Event AssetChanged

    Provides a callback that will be invoked when the asset is available or has changed.

    Namespace: UnityEngine.Localization
    Assembly: Unity.Localization.dll
    Syntax
    public event LocalizedAsset<TObject>.ChangeHandler AssetChanged
    Returns
    Type Description
    LocalizedAsset<TObject>.ChangeHandler
    Remarks

    The following events will trigger an update:

    • The first time the action is added to the event.
    • The SelectedLocale changing.
    • The TableReference or TableEntryReference changing.

    When the first LocalizedAsset<TObject>.ChangeHandler is added, a loading operation (see CurrentLoadingOperationHandle) will automatically start and the localized asset will be sent to the subscriber when completed. Any adding additional subscribers added after loading has completed will also be sent the latest localized asset when they are added. This ensures that a subscriber will always have the correct localized value regardless of when it was added.

    Examples

    This example shows how the AssetChanged event could be used to change the Font on some localized Text.

    public class LocalizedTextWithFont : MonoBehaviour
    {
        [Serializable]
        public class LocalizedFont : LocalizedAsset<Font> {}
    
        public LocalizedString localizedString;
        public LocalizedFont localizedFont;
    
        public Text uiText;
    
        void OnEnable()
        {
            localizedString.StringChanged += UpdateText;
            localizedFont.AssetChanged += FontChanged;
        }
    
        void OnDisable()
        {
            localizedString.StringChanged -= UpdateText;
            localizedFont.AssetChanged -= FontChanged;
        }
    
        void FontChanged(Font f)
        {
            uiText.font = f;
        }
    
        void UpdateText(string s)
        {
            uiText.text = s;
        }
    }
    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)