docs.unity3d.com
    Show / Hide Table of Contents

    Class AssetTableEntry

    Run time representation of an entry in a AssetTable.

    Inheritance
    Object
    TableEntry
    AssetTableEntry
    Inherited Members
    TableEntry.Table
    TableEntry.SharedEntry
    TableEntry.Key
    TableEntry.KeyId
    TableEntry.LocalizedValue
    TableEntry.MetadataEntries
    TableEntry.GetMetadata<TObject>()
    TableEntry.GetMetadatas<TObject>(IList<TObject>)
    TableEntry.GetMetadatas<TObject>()
    TableEntry.HasTagMetadata<TShared>()
    TableEntry.AddTagMetadata<TShared>()
    TableEntry.AddSharedMetadata(SharedTableEntryMetadata)
    TableEntry.AddSharedMetadata(SharedTableCollectionMetadata)
    TableEntry.AddMetadata(IMetadata)
    TableEntry.RemoveTagMetadata<TShared>()
    TableEntry.RemoveSharedMetadata(SharedTableEntryMetadata)
    TableEntry.RemoveSharedMetadata(SharedTableCollectionMetadata)
    TableEntry.RemoveMetadata(IMetadata)
    TableEntry.Contains(IMetadata)
    Namespace: UnityEngine.Localization.Tables
    Syntax
    public class AssetTableEntry : TableEntry, IMetadataCollection

    Properties

    Address

    The address used to load the asset from Addressables. Contains the Guid and the optional SubAssetName in the form Guid[SubAssetName].

    Declaration
    public string Address { get; set; }
    Property Value
    Type Description
    String

    Guid

    The asset Guid.

    Declaration
    public string Guid { get; set; }
    Property Value
    Type Description
    String

    IsEmpty

    Does this entry contain any data? Checks if Address is empty.

    Declaration
    public bool IsEmpty { get; }
    Property Value
    Type Description
    Boolean

    IsSubAsset

    Does the Address reference a sub-asset?

    Declaration
    public bool IsSubAsset { get; }
    Property Value
    Type Description
    Boolean

    SubAssetName

    The name of the sub-asset if one is used; otherwise null.

    Declaration
    public string SubAssetName { get; }
    Property Value
    Type Description
    String

    Methods

    RemoveFromTable()

    Attempts to remove the entry from the AssetTable that it belongs to. If Table is null then a warning will be produced.

    Declaration
    public void RemoveFromTable()

    SetAssetOverride<T>(T)

    Provides support for overriding the localized asset for the Entry. Note this is only temporary and will not persist in the Editor or if the table is reloaded. This allows for a table to be updated in the player.

    Declaration
    public void SetAssetOverride<T>(T asset)
        where T : Object
    Parameters
    Type Name Description
    T asset

    The asset reference to use instead of Address.

    Type Parameters
    Name Description
    T

    The type to store the asset as locally.

    Examples

    This example shows how you can update the AssetTable entry values when the Locale is changed.

    public class UpdateAssetTableExample : MonoBehaviour
    {
    public LocalizedAssetTable myAssetTable = new LocalizedAssetTable("My Asset Table");
    
    public Texture englishTexture;
    public Texture frenchTexture;
    
    void OnEnable()
    {
        myAssetTable.TableChanged += UpdateTable;
    }
    
    void OnDisable()
    {
        myAssetTable.TableChanged -= UpdateTable;
    }
    
    Texture GetTextureForLocale(LocaleIdentifier localeIdentifier)
    {
        if (localeIdentifier.Code == "en")
            return englishTexture;
        else if (localeIdentifier == "fr")
            return frenchTexture;
        return null;
    }
    
    void UpdateTable(AssetTable value)
    {
        var entry = value.GetEntry("My Table Entry") ?? value.AddEntry("My Table Entry", string.Empty);
        entry.SetAssetOverride(GetTextureForLocale(value.LocaleIdentifier));
    }
    }

    This example shows how you can update all AssetTable entries at the start and ensure that the tables are never unloaded so that the changes are persistent throughtout the lifetime of the player.

    public class OverrideAllAssetTables : MonoBehaviour
    {
    public LocalizedAssetTable myAssetTable = new LocalizedAssetTable("My Asset Table");
    
    public Texture englishTexture;
    public Texture frenchTexture;
    
    IEnumerator Start()
    {
        yield return LocalizationSettings.InitializationOperation;
    
        foreach (var locale in LocalizationSettings.AvailableLocales.Locales)
        {
            var table = LocalizationSettings.AssetDatabase.GetTableAsync(myAssetTable.TableReference, locale);
    
            // Acquire a reference to the table. This will prevent the table from unloading until we have released it with Addressables.Release.
            Addressables.ResourceManager.Acquire(table);
    
            yield return table;
            UpdateTable(table.Result);
        }
    }
    
    Texture GetTextureForLocale(LocaleIdentifier localeIdentifier)
    {
        if (localeIdentifier.Code == "en")
            return englishTexture;
        else if (localeIdentifier == "fr")
            return frenchTexture;
        return null;
    }
    
    void UpdateTable(AssetTable value)
    {
        var entry = value.GetEntry("My Table Entry") ?? value.AddEntry("My Table Entry", string.Empty);
        entry.SetAssetOverride(GetTextureForLocale(value.LocaleIdentifier));
    }
    }

    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
      • Address
      • Guid
      • IsEmpty
      • IsSubAsset
      • SubAssetName
    • Methods
      • RemoveFromTable()
      • SetAssetOverride<T>(T)
    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