Interface ITableProvider
Can be assigned to TableProvider to override the default table loading through Addressables in order to provide a custom table.
Namespace: UnityEngine.Localization.Settings
Syntax
public interface ITableProvider
Examples
This example demonstrates how to use the ITableProvider to provide a custom String Table without using the Addressables system. This approach is particularly useful when you want to allow users to add third-party content, such as modding. The localization data could be loaded from an external file and then converted into a table at runtime.
[Serializable]
public class CustomTableProvider : ITableProvider
{
public string customTableCollectionName = "My Custom Table";
public AsyncOperationHandle<TTable> ProvideTableAsync<TTable>(string tableCollectionName, Locale locale) where TTable : LocalizationTable
{
Debug.Log($"Requested {locale.LocaleName} {typeof(TTable).Name} with the name `{tableCollectionName}`.");
// Provide a custom string table only with the name "My Custom Table".
if (typeof(TTable) == typeof(StringTable) && tableCollectionName == customTableCollectionName)
{
// Create the table and its shared table data.
var table = ScriptableObject.CreateInstance<StringTable>();
table.SharedData = ScriptableObject.CreateInstance<SharedTableData>();
table.SharedData.TableCollectionName = customTableCollectionName;
table.LocaleIdentifier = locale.Identifier;
// Add some values
table.AddEntry("My Entry 1", "My localized value 1");
table.AddEntry("My Entry 2", "My localized value 2");
return Addressables.ResourceManager.CreateCompletedOperation(table as TTable, null);
}
// Fallback to default table loading.
return default;
}
}
public static class AssignCustomTableProviderExample
{
[MenuItem("Localization Samples/Assign Custom table provider")]
public static void AssignTableProvider()
{
// Create an instance of the table provider.
var provider = new CustomTableProvider();
// A provider can be assigned to each database or the same provider can be shared between both.
var settings = LocalizationEditorSettings.ActiveLocalizationSettings;
settings.GetStringDatabase().TableProvider = provider;
settings.GetAssetDatabase().TableProvider = provider;
// Set dirty so the changes are saved.
EditorUtility.SetDirty(settings);
}
}
Methods
ProvideTableAsync<TTable>(String, Locale)
Provides a way to return a custom table when when attempting to load from GetTableAsync(TableReference, Locale).
Declaration
AsyncOperationHandle<TTable> ProvideTableAsync<TTable>(string tableCollectionName, Locale locale)
where TTable : LocalizationTable
Parameters
Type | Name | Description |
---|---|---|
String | tableCollectionName | |
Locale | locale |
Returns
Type | Description |
---|---|
AsyncOperationHandle<TTable> | A valid table or default, which will trigger the default table loading. |
Type Parameters
Name | Description |
---|---|
TTable |