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

    Guid

    The asset Guid, used to load the asset by the Addressables system.

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

    IsEmpty

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

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

    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 Guid.

    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));
    }
    }
    Back to top
    Terms of use
    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