AssetEntryBase<TStore>
Serves as the base class for asset entries that own a stored reference and load and release the asset themselves.
Read time 2 minutesLast updated 7 days ago
Definition
- Type: Class
- Namespace: Unity.Localization
- Assembly: UnityEngine.LocalizationRuntimeModule
- Inherits from: ResourceEntryBase
- Implements: IAssetEntry, IResourceEntry, ISynchronousAssetEntry
public abstract class AssetEntryBase<TStore> : ResourceEntryBase, IAssetEntry, IResourceEntry, ISynchronousAssetEntry
Remarks
The type parameter is the stored reference the entry keeps in AssetEntryBase<TStore>.Default, and each concrete kind decides how that reference resolves to an asset: AssetEntry stores a direct object, and ResourceAssetEntry stores a path. The built-in kinds are synchronous: they resolve through ISynchronousAssetEntry.TryLoadAsset, and public callers use the IAssetEntry members HasAsset and ReleaseAsset. To add a custom kind, override the protected , , and members to back a different storage, such as an Addressables handle provided by a package.
ResourcesHasValueTryLoadSyncReleaseRead the base members through a concrete asset entry.
Examples
using Unity.Localization;using UnityEngine;namespace Unity.Localization.Samples{ public class AssetEntryBaseOverviewExample { public void Run() { var shared = ScriptableObject.CreateInstance<SharedTableData>(); shared.TableCollectionName = "UI Assets"; var table = ScriptableObject.CreateInstance<ResourceTable>(); table.SharedData = shared; table.LocaleIdentifier = new LocaleIdentifier("en"); var entry = new AssetEntry(shared.AddKey("icon").Id); table.AddEntry(entry); AssetEntryBase<Object> baseEntry = entry; // AssetEntry derives from AssetEntryBase<Object> Debug.Log(baseEntry.HasAsset()); // False: no asset assigned Debug.Log(baseEntry.Default); // null } }}
Constructors
Constructor | Description |
|---|---|
| AssetEntryBase`1() | Creates an empty entry. |
| AssetEntryBase`1(System.Int64) | Creates an entry for a key id. |
Properties
Property | Description |
|---|---|
| Default | The stored reference this entry loads its asset from. |
Methods
Method | Description |
|---|---|
| HasValue | Returns whether the given stored reference holds a value. |
| Release | Releases an asset that was loaded from a stored reference. |
| TryLoadSync | Resolves the asset from the given stored reference synchronously, when the kind supports it. |