LocalizedAsset<TObject>
A serializable reference to a localized asset that updates as the selected locale changes.
Read time 2 minutesLast updated 12 days ago
Definition
- Type: Class
- Namespace: Unity.Localization
- Assembly: UnityEngine.LocalizationRuntimeModule
- Inherits from: LocalizedEntry<IAssetEntry>
public class LocalizedAsset<TObject> : LocalizedEntry<IAssetEntry> where TObject : Object
Remarks
A LocalizedAsset<TObject> extends LocalizedEntry<TEntry> to resolve an IAssetEntry and load its asset as through the ResourceDatabase provider chain. Load the asset with LocalizedAsset<TObject>.GetLocalizedAssetAsync(), or subscribe to LocalizedAsset<TObject>.AssetChanged to receive it immediately and again whenever the selected locale changes. For common asset types, use the LocalizedTexture, LocalizedGameObject, and LocalizedObject subclasses, which are serializable and appear in the Inspector.
TObjectResolve a localized texture and apply it whenever the locale changes.
Examples
using Unity.Localization;using UnityEngine;namespace Unity.Localization.Samples{ public class LocalizedAssetTextureExample : MonoBehaviour { void OnEnable() { var targetRenderer = GetComponent<Renderer>(); var icon = new LocalizedTexture(); icon.SetReference("My Assets", "ICON"); icon.AssetChanged += texture => targetRenderer.material.mainTexture = texture; } }}
Methods
Method | Description |
|---|---|
| GetLocalizedAsset | Resolves the localized asset synchronously when a synchronous provider and entry can supply it. |
| GetLocalizedAssetAsync | Loads the localized asset asynchronously through the resource database. |
| RefreshAsset | Re-resolves the asset and pushes the result to subscribers. |
Events
Member | Description |
|---|---|
| AssetChanged | Occurs when the resolved asset changes, and once immediately when a handler subscribes. |
Delegates
Delegate | Description |
|---|---|
| LocalizedAsset<TObject>.ChangeHandler | Represents a method that receives a resolved localized asset value. |