Class PlatformOverride
UnityEngine.Localization.Metadata that can be used to redirect the localization system to a different table entry based on the current runtime platform. This UnityEngine.Localization.Metadata can be applied to SharedTableData.SharedTableEntry, StringTableEntry or AssetTableEntry.
Namespace: UnityEngine.Localization.Metadata
Syntax
public class PlatformOverride : object, IEntryOverride, IMetadata, ISerializationCallbackReceiver
Methods
AddPlatformEntryOverride(RuntimePlatform, TableEntryReference)
Add a platform override for the current entry. This will use the same table collection but a different entry in the table than the one this Metadata is attached to. This is useful if you want to have overrides for entries that are stored in the same table.
Declaration
public void AddPlatformEntryOverride(RuntimePlatform platform, TableEntryReference entry)
Parameters
Type | Name | Description |
---|---|---|
RuntimePlatform | platform | The platform to override. |
TableEntryReference | entry | The entry to use instead of the current one. |
Examples
This example shows how you could set up platform overrides using a single table.
public void SetupEntryOverrideInEditor()
{
var collection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
var englishTable = collection.GetTable("en") as StringTable;
// Add the default entry
var entry = englishTable.AddEntry("COPYRIGHT_NOTICE", "This is some copyright info for general platforms...");
// Add the entry we want to use on PS4
englishTable.AddEntry("COPYRIGHT_NOTICE_PS4", "This is some copyright info for PS4 platforms...");
// Set up the platform override so that COPYRIGHT_NOTICE redirects to COPYRIGHT_NOTICE_PS4 when running on PS4.
var platformOverride = new PlatformOverride();
platformOverride.AddPlatformEntryOverride(RuntimePlatform.PS4, "COPYRIGHT_NOTICE_PS4");
entry.SharedEntry.Metadata.AddMetadata(platformOverride);
// Mark the assets dirty so changes are saved
EditorUtility.SetDirty(collection.SharedData);
EditorUtility.SetDirty(englishTable);
}
AddPlatformOverride(RuntimePlatform, TableReference, TableEntryReference, EntryOverrideType)
Add a platform override for the table, entry or both.
Declaration
public void AddPlatformOverride(RuntimePlatform platform, TableReference table, TableEntryReference entry, EntryOverrideType entryOverrideType = EntryOverrideType.TableAndEntry)
Parameters
Type | Name | Description |
---|---|---|
RuntimePlatform | platform | The platform to override. |
TableReference | table | The table collection to use instead of the current one. |
TableEntryReference | entry | The entry to use instead of the current one. |
EntryOverrideType | entryOverrideType | Flags to insidcate the type of override to apply, table, entry or both. |
AddPlatformTableOverride(RuntimePlatform, TableReference)
Add a platform override for the current table collection. This will result in the table being switched but the same entry name being used. This is useful if you want to have specialist tables that will implement the same keys for certain entries.
Declaration
public void AddPlatformTableOverride(RuntimePlatform platform, TableReference table)
Parameters
Type | Name | Description |
---|---|---|
RuntimePlatform | platform | The platform to override. |
TableReference | table | The table collection to use instead of the current one. |
Examples
This example shows how you could set up platform overrides using a table for each platform.
public void SetupTableOverrideInEditor()
{
// Get the 2 table collections. 1 for default and 1 for our chosen platform (PS4).
var collection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
var collectionPs4 = LocalizationEditorSettings.GetStringTableCollection("My Strings PS4");
var englishTable = collection.GetTable("en") as StringTable;
var englishTablePs4 = collectionPs4.GetTable("en") as StringTable;
// Add the default entry
var entry = englishTable.AddEntry("COPYRIGHT_NOTICE", "This is some copyright info for general platforms...");
// Add the entry we want to use on PS4 using the same entry name.
englishTablePs4.AddEntry("COPYRIGHT_NOTICE", "This is some copyright info for PS4 platforms...");
// Set up the platform override so that COPYRIGHT_NOTICE redirects to a different table but uses the same key.
var platformOverride = new PlatformOverride();
platformOverride.AddPlatformTableOverride(RuntimePlatform.PS4, "My Strings PS4");
entry.SharedEntry.Metadata.AddMetadata(platformOverride);
// Mark the assets dirty so changes are saved
EditorUtility.SetDirty(collection.SharedData);
EditorUtility.SetDirty(englishTable);
}
GetOverride(out TableReference, out TableEntryReference)
Returns the EntryOverrideType for the platform the application is currently running on using Application.platform.
Declaration
public EntryOverrideType GetOverride(out TableReference tableReference, out TableEntryReference tableEntryReference)
Parameters
Type | Name | Description |
---|---|---|
TableReference | tableReference | The table to use or |
TableEntryReference | tableEntryReference | The entry to use or |
Returns
Type | Description |
---|---|
EntryOverrideType | Returns the fields that should be overridden. |
Implements
GetOverride(out TableReference, out TableEntryReference, RuntimePlatform)
Returns the EntryOverrideType for the platform.
Declaration
public EntryOverrideType GetOverride(out TableReference tableReference, out TableEntryReference tableEntryReference, RuntimePlatform platform)
Parameters
Type | Name | Description |
---|---|---|
TableReference | tableReference | The table to use or |
TableEntryReference | tableEntryReference | The entry to use or |
RuntimePlatform | platform | The platform to return the override for. |
Returns
Type | Description |
---|---|
EntryOverrideType | Returns the fields that should be overridden. |
RemovePlatformOverride(RuntimePlatform)
Removes the platform override for the chosen platform.
Declaration
public bool RemovePlatformOverride(RuntimePlatform platform)
Parameters
Type | Name | Description |
---|---|---|
RuntimePlatform | platform | The platform to remove. |
Returns
Type | Description |
---|---|
Boolean |
|