LocalizeAssetEvent<TObject>
Serves as the base component that resolves a localized asset and forwards it through a UnityEvent whenever the value or the selected locale changes.
Read time 7 minutesLast updated 11 days ago
Definition
- Type: Class
- Namespace: Unity.Localization.Components
- Assembly: UnityEngine.LocalizationRuntimeModule
- Inherits from: MonoBehaviour
public abstract class LocalizeAssetEvent<TObject> : MonoBehaviour where TObject : Object
Remarks
Derive a concrete component for a specific asset type by closing the type parameter, for example LocalizeTextureEvent for Texture. Add the derived component to a GameObject, assign its LocalizeAssetEvent<TObject>.AssetReference in the Inspector, then connect LocalizeAssetEvent<TObject>.OnUpdateAsset to a consumer such as an image component. While the component is active it subscribes to the localized asset's LocalizedAsset<TObject>.AssetChanged event, so it re-resolves and re-invokes the event when LocalizationSettings.SelectedLocale changes. Use it to swap assets such as flags or localized artwork per locale.
Forward the resolved asset to a consumer.
Examples
using Unity.Localization.Components;using UnityEngine;namespace Unity.Localization.Samples{ public class LocalizeTextureEventBindingExample : MonoBehaviour { public LocalizeTextureEvent localize; public Renderer target; void OnEnable() => localize.OnUpdateAsset.AddListener(OnUpdate); void OnDisable() => localize.OnUpdateAsset.RemoveListener(OnUpdate); void OnUpdate(Texture value) => target.material.mainTexture = value; }}
Properties
Property | Description |
|---|---|
| AssetReference | The localized asset reference to resolve. |
| OnUpdateAsset | The event invoked with the localized asset each time it resolves. |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |