Class KeyDatabase
The key database is responsible for holding localization keys and associating keys to unique ids. Each collection of tables will reference a single Key Database asset.
Namespace: UnityEngine.Localization.Tables
Syntax
public class KeyDatabase : ScriptableObject, ISerializationCallbackReceiver
Fields
EmptyId
Represents an empty or null Key Id.
Declaration
public const uint EmptyId = 0U
Field Value
Type | Description |
---|---|
UInt32 |
Properties
Entries
All Key Database entries.
Declaration
public List<KeyDatabase.KeyDatabaseEntry> Entries { get; set; }
Property Value
Type | Description |
---|---|
List<KeyDatabase.KeyDatabaseEntry> |
Metadata
Metadata that is shared between all tables.
Declaration
public MetadataCollection Metadata { get; set; }
Property Value
Type | Description |
---|---|
MetadataCollection |
TableName
The name of this asset table collection. All LocalizedTable that use this KeyDatabase will have this name.
Declaration
public string TableName { get; set; }
Property Value
Type | Description |
---|---|
String |
TableNameGuid
A unique Id that will never change. Comes from the KeyDatabase asset Guid. Provides a way to reference a table that will not be broken if the table name was to be changed.
Declaration
public Guid TableNameGuid { get; }
Property Value
Type | Description |
---|---|
Guid |
Methods
AddKey()
Adds a new key to the database with a default name.
Declaration
public KeyDatabase.KeyDatabaseEntry AddKey()
Returns
Type | Description |
---|---|
KeyDatabase.KeyDatabaseEntry |
AddKey(String)
Adds a new key to the database if one does not already exists with the same value. Duplicates are not allowed.
Declaration
public KeyDatabase.KeyDatabaseEntry AddKey(string key)
Parameters
Type | Name | Description |
---|---|---|
String | key |
Returns
Type | Description |
---|---|
KeyDatabase.KeyDatabaseEntry | The new key or null if the key already exists. |
Contains(String)
Is the key value used by any entries in the database?
Declaration
public bool Contains(string key)
Parameters
Type | Name | Description |
---|---|---|
String | key | Key to check. |
Returns
Type | Description |
---|---|
Boolean |
Contains(UInt32)
Is the Id value used by any entries in the database?
Declaration
public bool Contains(uint id)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | id | Id to check. |
Returns
Type | Description |
---|---|
Boolean |
FindSimilarKey(String, out Int32)
Returns the KeyDatabaseEntry that is the most similar to the text. Uses the Levenshtein distance method.
Declaration
public KeyDatabase.KeyDatabaseEntry FindSimilarKey(string text, out int distance)
Parameters
Type | Name | Description |
---|---|---|
String | text | The text to match against. |
Int32 | distance | The number of edits needed to turn |
Returns
Type | Description |
---|---|
KeyDatabase.KeyDatabaseEntry | The KeyDatabaseEntry that is the most similar to the text or null if one could not be found. |
GenerateUniqueId()
Returns a new unique id for this table.
Declaration
protected virtual uint GenerateUniqueId()
Returns
Type | Description |
---|---|
UInt32 |
GetEntry(String)
Returns the Entry for the key, this contains all data for the key.
Declaration
public KeyDatabase.KeyDatabaseEntry GetEntry(string key)
Parameters
Type | Name | Description |
---|---|---|
String | key | The name of the key. |
Returns
Type | Description |
---|---|
KeyDatabase.KeyDatabaseEntry | The found key entry or null if one can not be found. |
GetEntry(UInt32)
Returns the Entry for the key id, this contains all data for the key.
Declaration
public KeyDatabase.KeyDatabaseEntry GetEntry(uint id)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | id | Id the key belongs to. |
Returns
Type | Description |
---|---|
KeyDatabase.KeyDatabaseEntry | The found key entry or null if one can not be found. |
GetEntry(TableEntryReference)
Returns the Entry for the key id, this contains all data for the key.
Declaration
public KeyDatabase.KeyDatabaseEntry GetEntry(TableEntryReference tableEntryReference)
Parameters
Type | Name | Description |
---|---|---|
TableEntryReference | tableEntryReference |
Returns
Type | Description |
---|---|
KeyDatabase.KeyDatabaseEntry | The found key entry or null if one can not be found. |
GetId(String)
Get the unique Id for the key name from the database.
Declaration
public uint GetId(string key)
Parameters
Type | Name | Description |
---|---|---|
String | key | The key whose id is being requested. |
Returns
Type | Description |
---|---|
UInt32 | The keys id value or EmptyId if one does not exist. |
GetId(String, Boolean)
Get the unique Id for the key name from the database, if one does not exist then a new entry is added.
Declaration
public uint GetId(string key, bool addNewKey)
Parameters
Type | Name | Description |
---|---|---|
String | key | |
Boolean | addNewKey |
Returns
Type | Description |
---|---|
UInt32 |
GetKey(UInt32)
Get the key associated with the id.
Declaration
public string GetKey(uint id)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | id | Id the key belongs to. |
Returns
Type | Description |
---|---|
String | The found key or null if one can not be found. |
OnAfterDeserialize()
Converts the serializable string into a Guid.
Declaration
public void OnAfterDeserialize()
OnBeforeSerialize()
Converts the Guid into a serializable string.
Declaration
public void OnBeforeSerialize()
RemoveKey(String)
Attempts to remove the key from the database.
Declaration
public void RemoveKey(string key)
Parameters
Type | Name | Description |
---|---|---|
String | key | The key to be removed. |
RemoveKey(UInt32)
Attempts to remove the key with provided id.
Declaration
public void RemoveKey(uint id)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | id |
RenameKey(String, String)
Rename the key value if it exists.
Declaration
public void RenameKey(string oldValue, string newValue)
Parameters
Type | Name | Description |
---|---|---|
String | oldValue | |
String | newValue |
RenameKey(UInt32, String)
Rename the key value for the provided id if it exists.
Declaration
public void RenameKey(uint id, string newValue)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | id | |
String | newValue |