Class AssetTable
An AssetTable
Inheritance
Inherited Members
Namespace: UnityEngine.Localization.Tables
Syntax
public class AssetTable : DetailedLocalizationTable<AssetTableEntry>, IMetadataCollection, IComparable<LocalizationTable>, IDictionary<long, AssetTableEntry>, ICollection<KeyValuePair<long, AssetTableEntry>>, IEnumerable<KeyValuePair<long, AssetTableEntry>>, IEnumerable, ISerializationCallbackReceiver, IPreloadRequired
Properties
PreloadOperation
Handle to the preload operation for this table. Calling this will start the asset tables preloading operation, it will preload all assets referenced unless the Metadata PreloadAssetTableMetadata is found and has the NoPreload behavior.
Declaration
public virtual AsyncOperationHandle PreloadOperation { get; }
Property Value
Type | Description |
---|---|
AsyncOperationHandle |
Implements
Methods
CreateTableEntry()
Creates a new, empty AssetTableEntry.
Declaration
public override AssetTableEntry CreateTableEntry()
Returns
Type | Description |
---|---|
AssetTableEntry |
Overrides
GetAssetAsync<TObject>(TableEntryReference)
Returns the loading operation for the asset. Check isDone to see if the asset is available for immediate use, if not you can yield on the operation or add a callback subscriber.
Declaration
public AsyncOperationHandle<TObject> GetAssetAsync<TObject>(TableEntryReference entryReference)
where TObject : Object
Parameters
Type | Name | Description |
---|---|---|
TableEntryReference | entryReference |
Returns
Type | Description |
---|---|
AsyncOperationHandle<TObject> |
Type Parameters
Name | Description |
---|---|
TObject | The type of object to load. |
ReleaseAsset(AssetTableEntry)
Release an asset for a single entry that has been preloaded or cached.
Declaration
public void ReleaseAsset(AssetTableEntry entry)
Parameters
Type | Name | Description |
---|---|---|
AssetTableEntry | entry | A reference to the entry in the table. |
ReleaseAsset(TableEntryReference)
Release an asset for a single entry that have been preloaded or cached
Declaration
public void ReleaseAsset(TableEntryReference entry)
Parameters
Type | Name | Description |
---|---|---|
TableEntryReference | entry | A reference to the entry in the table. |
Examples
In this example the Audio Clip is only used by this script and can be unloaded after the clip has finished playing. By using ReleaseAsset we can tell the localization system to release its handle to the asset and allow it to be unloaded from memory.
using System.Collections;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
public class ReleaseAssetExample : MonoBehaviour
{
public LocalizedAudioClip localizedAudioClip = new LocalizedAudioClip { TableReference = "My Table", TableEntryReference = "My Audio Clip" };
public AudioSource audioSource;
bool isLoadingAndPlaying;
private void OnGUI()
{
if (isLoadingAndPlaying)
{
GUILayout.Label("Loading & Playing Clip");
return;
}
if (GUILayout.Button("Load & Play Audio Clip"))
{
StartCoroutine(LoadAndPlay());
}
}
IEnumerator LoadAndPlay()
{
isLoadingAndPlaying = true;
var clipOperation = localizedAudioClip.LoadAssetAsync();
// Acquire the operation. If another part of code was to call ReleaseAsset this would
// prevent the asset from being unloaded whilst we are still using it.
Addressables.ResourceManager.Acquire(clipOperation);
// Wait for the clip to load.
yield return clipOperation;
// Play the clip.
audioSource.clip = clipOperation.Result;
audioSource.Play();
// Wait for the clip to finish.
yield return new WaitForSeconds(clipOperation.Result.length);
// Release our handle
audioSource.clip = null;
Addressables.Release(clipOperation);
// Get the asset table
var table = LocalizationSettings.AssetDatabase.GetTable(localizedAudioClip.TableReference);
// Tell the Asset Table to release the cached version. The asset will now
// be unloaded as long as there are no other references.
table.ReleaseAsset(localizedAudioClip.TableEntryReference);
isLoadingAndPlaying = false;
}
}
ReleaseAssets()
Releases all assets that have been preloaded or cached and resets the preload state so it can be performed again. Note: This is called automatically by LocalizedAssetDatabase when the SelectedLocale is changed.
Declaration
public void ReleaseAssets()