docs.unity3d.com
    Show / Hide Table of Contents

    Class AssetTable

    An AssetTable

    Inheritance
    Object
    Object
    ScriptableObject
    LocalizationTable
    DetailedLocalizationTable<AssetTableEntry>
    AssetTable
    Inherited Members
    DetailedLocalizationTable<AssetTableEntry>.Values
    DetailedLocalizationTable<AssetTableEntry>.Count
    DetailedLocalizationTable<AssetTableEntry>.IsReadOnly
    DetailedLocalizationTable<AssetTableEntry>.Item[Int64]
    DetailedLocalizationTable<AssetTableEntry>.Item[String]
    DetailedLocalizationTable<AssetTableEntry>.CreateEmpty(TableEntryReference)
    DetailedLocalizationTable<AssetTableEntry>.AddEntry(String, String)
    DetailedLocalizationTable<AssetTableEntry>.AddEntry(Int64, String)
    DetailedLocalizationTable<AssetTableEntry>.AddEntryFromReference(TableEntryReference, String)
    DetailedLocalizationTable<AssetTableEntry>.RemoveEntry(String)
    DetailedLocalizationTable<AssetTableEntry>.RemoveEntry(Int64)
    DetailedLocalizationTable<AssetTableEntry>.GetEntryFromReference(TableEntryReference)
    DetailedLocalizationTable<AssetTableEntry>.GetEntry(String)
    DetailedLocalizationTable<AssetTableEntry>.GetEntry(Int64)
    DetailedLocalizationTable<AssetTableEntry>.Add(Int64, AssetTableEntry)
    DetailedLocalizationTable<AssetTableEntry>.Add(KeyValuePair<Int64, AssetTableEntry>)
    DetailedLocalizationTable<AssetTableEntry>.ContainsKey(Int64)
    DetailedLocalizationTable<AssetTableEntry>.ContainsValue(String)
    DetailedLocalizationTable<AssetTableEntry>.Contains(KeyValuePair<Int64, AssetTableEntry>)
    DetailedLocalizationTable<AssetTableEntry>.Remove(Int64)
    DetailedLocalizationTable<AssetTableEntry>.Remove(KeyValuePair<Int64, AssetTableEntry>)
    DetailedLocalizationTable<AssetTableEntry>.CheckForMissingSharedTableDataEntries(MissingEntryAction)
    DetailedLocalizationTable<AssetTableEntry>.TryGetValue(Int64, AssetTableEntry)
    DetailedLocalizationTable<AssetTableEntry>.Clear()
    DetailedLocalizationTable<AssetTableEntry>.CopyTo(KeyValuePair<Int64, AssetTableEntry>[], Int32)
    DetailedLocalizationTable<AssetTableEntry>.GetEnumerator()
    LocalizationTable.LocaleIdentifier
    LocalizationTable.TableCollectionName
    LocalizationTable.SharedData
    LocalizationTable.MetadataEntries
    LocalizationTable.GetMetadata<TObject>()
    LocalizationTable.GetMetadatas<TObject>(IList<TObject>)
    LocalizationTable.GetMetadatas<TObject>()
    LocalizationTable.AddMetadata(IMetadata)
    LocalizationTable.RemoveMetadata(IMetadata)
    LocalizationTable.Contains(IMetadata)
    LocalizationTable.FindKeyId(String, Boolean)
    LocalizationTable.CompareTo(LocalizationTable)
    ScriptableObject.SetDirty()
    ScriptableObject.CreateInstance(String)
    ScriptableObject.CreateInstance(Type)
    ScriptableObject.CreateInstance<T>()
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(Object)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, Boolean)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, Boolean)
    Object.Destroy(Object, Single)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, Boolean)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, Single)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    Object.FindObjectOfType<T>()
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.name
    Object.hideFlags
    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
    IPreloadRequired.PreloadOperation

    Methods

    CreateTableEntry()

    Creates a new, empty AssetTableEntry.

    Declaration
    public override AssetTableEntry CreateTableEntry()
    Returns
    Type Description
    AssetTableEntry
    Overrides
    UnityEngine.Localization.Tables.DetailedLocalizationTable<UnityEngine.Localization.Tables.AssetTableEntry>.CreateTableEntry()

    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()

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Properties
      • PreloadOperation
    • Methods
      • CreateTableEntry()
      • GetAssetAsync<TObject>(TableEntryReference)
      • ReleaseAsset(AssetTableEntry)
      • ReleaseAsset(TableEntryReference)
      • ReleaseAssets()
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023