ResourceTable
A localization table that holds the translated values for one locale in a collection.
Read time 5 minutesLast updated 6 days ago
Definition
- Type: Class
- Namespace: Unity.Localization
- Assembly: UnityEngine.LocalizationRuntimeModule
- Inherits from: ScriptableObject
- Implements: ISerializationCallbackReceiver
[HelpURL("localization/localization-tables")]public sealed class ResourceTable : ScriptableObject, ISerializationCallbackReceiver
Remarks
Each table targets a single locale (reported by ResourceTable.LocaleIdentifier) and shares its keys with every other locale table in the collection through one SharedTableData. Values are stored as polymorphic IResourceEntry objects (strings, assets, variants, or custom kinds) held through , so a single table type covers every entry kind. Look entries up by stable key id or by key text with the ResourceTable.GetEntry family, add plain strings with ResourceTable.AddStringEntry, and add fully-formed entries with ResourceTable.AddEntry. Tables belong to a collection: create one through the Resource Tables window, or with the ScriptableObject.CreateInstance method, assigning ResourceTable.SharedData before resolving keys by text.
[SerializeReference]Create a table, add a string, and read it back.
Examples
using Unity.Localization;using UnityEngine;namespace Unity.Localization.Samples{ public class ResourceTableOverviewExample { public void Run() { var shared = ScriptableObject.CreateInstance<SharedTableData>(); var table = ScriptableObject.CreateInstance<ResourceTable>(); table.SharedData = shared; table.LocaleIdentifier = "en"; table.AddStringEntry("Greeting", "Hello"); var entry = table.GetEntry<IStringEntry>("Greeting"); Debug.Log(entry.Value); // Hello } }}
Properties
Property | Description |
|---|---|
| Entries | The entries this table holds for its locale. |
| LocaleIdentifier | The locale this table provides values for. |
| Metadata | The metadata attached to this table for its locale. |
| SharedData | The shared key data for the collection this table belongs to. |
| TableCollectionName | The name of the collection this table belongs to. |
Methods
Method | Description |
|---|---|
| AddEntry | Adds an entry, replacing any existing entry with the same key id. |
| AddStringEntry | Adds or updates a plain string entry for a key. |
| AddStringVariant | Adds or updates a variant value for a string key in this table. |
| GetEntry | Returns the entry stored for a stable key id. |
| RemoveAllEntries | Removes every entry from this table. |
| RemoveEntry | Removes the entry for a stable key id from this table. |
| RemoveVariant | Removes one variant value from a key's entry in this table. |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |