| Parameter | Description |
|---|---|
| key | The key to add. |
SharedTableEntry
The new or existing entry, or null when the key is empty.
Adds a key and returns its entry.
When the key already exists, its existing entry is returned rather than a duplicate being created. A new id is drawn
from the SharedTableData.KeyGenerator and retried until it is unique. Returns null when the key is
empty or null.
Additional resources: SharedTableData.AddKey, SharedTableData.RemoveKey, SharedTableData.RenameKey
<para>Add a key and observe that adding it again returns the same entry.</para>
using Unity.Localization; using UnityEngine;
namespace Unity.Localization.Samples { public class SharedTableDataAddKeyExample { public void Run() { var sharedData = ScriptableObject.CreateInstance<SharedTableData>();
SharedTableData.SharedTableEntry entry = sharedData.AddKey("GREETING"); SharedTableData.SharedTableEntry again = sharedData.AddKey("GREETING"); // same entry, no duplicate
Debug.Log(entry.Id == again.Id); // True } } }
| Parameter | Description |
|---|---|
| key | The key to add. |
| id | The stable id to assign. |
SharedTableEntry
The new or existing entry, or null when the key or id cannot be used.
Adds a key with an explicit id and returns its entry.
Use this to preserve ids when rebuilding from serialized data, for example importing or loading from a file. Returns
the existing entry when the key is already present, logging a warning if the requested id differs from the stored
one. Returns null when the key is empty, the id is 0, or the id is already used by another
key.
Additional resources: SharedTableData.AddKey, SharedTableData.GetEntry
<para>Add a key with an id preserved from serialized data.</para>
using Unity.Localization; using UnityEngine;
namespace Unity.Localization.Samples { public class SharedTableDataAddKeyWithIdExample { public void Run() { var sharedData = ScriptableObject.CreateInstance<SharedTableData>();
SharedTableData.SharedTableEntry entry = sharedData.AddKey("GREETING", 1001);
Debug.Log(entry.Id); // 1001 } } }