Class AssetTableEntry
Run time representation of an entry in a AssetTable.
Inherited Members
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));
}
}