docs.unity3d.com
    Show / Hide Table of Contents

    Class SharedTableData

    The SharedTableData holds data that is accessible across all tables. It is responsible for the localization keys and associating the keys to unique ids. Each collection of tables will reference a single SharedTableData asset.

    Inheritance
    Object
    Object
    ScriptableObject
    SharedTableData
    Inherited Members
    ScriptableObject.SetDirty()
    ScriptableObject.CreateInstance(String)
    ScriptableObject.CreateInstance(Type)
    ScriptableObject.CreateInstance<T>()
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(Object)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, Boolean)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, Boolean)
    Object.Destroy(Object, Single)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, Boolean)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, Single)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    Object.FindObjectOfType<T>()
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.name
    Object.hideFlags
    Namespace: UnityEngine.Localization.Tables
    Syntax
    public class SharedTableData : ScriptableObject, ISerializationCallbackReceiver

    Fields

    EmptyId

    Represents an empty or null Key Id.

    Declaration
    public const long EmptyId = 0L
    Field Value
    Type Description
    Int64

    Properties

    Entries

    All entries.

    Declaration
    public List<SharedTableData.SharedTableEntry> Entries { get; set; }
    Property Value
    Type Description
    List<SharedTableData.SharedTableEntry>

    KeyGenerator

    The Key Generator to use when adding new entries. By default this will use DistributedUIDGenerator.

    Declaration
    public IKeyGenerator KeyGenerator { get; set; }
    Property Value
    Type Description
    IKeyGenerator
    Examples

    This example shows how the KeyGenerator could be configured to use a SequentialIDGenerator.

    using System.Linq;
    using UnityEditor;
    using UnityEditor.Localization;
    using UnityEngine.Localization.Tables;
    
    public class ChangeKeyGeneratorExample
    {
    public void ChangeKeyGenerator()
    {
        var stringTableCollection = LocalizationEditorSettings.GetStringTableCollection("My Game Text");
    
        // Determine the highest Key Id so Unity can continue generating Ids that do not conflict with existing Ids.
        long maxKeyId = 0;
        if (stringTableCollection.SharedData.Entries.Count > 0)
            maxKeyId = stringTableCollection.SharedData.Entries.Max(e => e.Id);
    
        stringTableCollection.SharedData.KeyGenerator = new SequentialIDGenerator(maxKeyId + 1);
    
        // Mark the asset dirty so that Unity saves the changes
        EditorUtility.SetDirty(stringTableCollection.SharedData);
    }
    }

    Metadata

    Metadata that is shared between all tables.

    Declaration
    public MetadataCollection Metadata { get; set; }
    Property Value
    Type Description
    MetadataCollection

    TableCollectionName

    The name of this table collection. All LocalizationTable that use this SharedTableData will have this name.

    Declaration
    public string TableCollectionName { get; set; }
    Property Value
    Type Description
    String

    TableCollectionNameGuid

    A unique Id that will never change. Comes from the SharedTableData asset Guid. Provides a way to reference a table that will not be broken if the table collection name was to be changed.

    Declaration
    public Guid TableCollectionNameGuid { get; }
    Property Value
    Type Description
    Guid

    Methods

    AddKey(String)

    Adds a new key to this SharedTableData with a default name. If the name already exists then a unique version is generated based on the provided name.

    Declaration
    public SharedTableData.SharedTableEntry AddKey(string key = null)
    Parameters
    Type Name Description
    String key

    The name for the new Key.

    Returns
    Type Description
    SharedTableData.SharedTableEntry

    AddKey(String, Int64)

    Adds a new key to this SharedTableData if one does not already exists with the same id.

    Declaration
    public SharedTableData.SharedTableEntry AddKey(string key, long id)
    Parameters
    Type Name Description
    String key

    The unique key name to assign to the entry.

    Int64 id

    The unique id to assign to the key.

    Returns
    Type Description
    SharedTableData.SharedTableEntry

    The new entry or null if an entry already exists with the same id.

    Clear()

    Clear all entries in this table.

    Declaration
    public void Clear()

    Contains(Int64)

    Is the Id value used by any entries in this SharedTableData?

    Declaration
    public bool Contains(long id)
    Parameters
    Type Name Description
    Int64 id

    Id to check.

    Returns
    Type Description
    Boolean

    Contains(String)

    Is the key value used by any entries in this SharedTableData?

    Declaration
    public bool Contains(string key)
    Parameters
    Type Name Description
    String key

    Key to check.

    Returns
    Type Description
    Boolean

    FindSimilarKey(String, out Int32)

    Returns the SharedTableData.SharedTableEntry that is the most similar to the text. Uses the Levenshtein distance method.

    Declaration
    [Obsolete("FindSimilarKey will be removed in the future, please use Unity Search. See TableEntrySearchData class for further details.")]
    public SharedTableData.SharedTableEntry 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 text into the returned SharedTableData.SharedTableEntry, 0 being an exact match.

    Returns
    Type Description
    SharedTableData.SharedTableEntry

    The SharedTableData.SharedTableEntry that is the most similar to the text or null if one could not be found.

    GetEntry(Int64)

    Returns the Entry for the key id, this contains all data for the key.

    Declaration
    public SharedTableData.SharedTableEntry GetEntry(long id)
    Parameters
    Type Name Description
    Int64 id

    Id the key belongs to.

    Returns
    Type Description
    SharedTableData.SharedTableEntry

    The found key entry or null if one can not be found.

    GetEntry(String)

    Returns the Entry for the key, this contains all data for the key.

    Declaration
    public SharedTableData.SharedTableEntry GetEntry(string key)
    Parameters
    Type Name Description
    String key

    The name of the key.

    Returns
    Type Description
    SharedTableData.SharedTableEntry

    The found key entry or null if one can not be found.

    GetEntryFromReference(TableEntryReference)

    Returns the Entry for the key id, this contains all data for the key.

    Declaration
    public SharedTableData.SharedTableEntry GetEntryFromReference(TableEntryReference tableEntryReference)
    Parameters
    Type Name Description
    TableEntryReference tableEntryReference

    Reference to the entry.

    Returns
    Type Description
    SharedTableData.SharedTableEntry

    The found key entry or null if one can not be found.

    GetId(String)

    Get the unique Id for the key name from the shared table data.

    Declaration
    public long GetId(string key)
    Parameters
    Type Name Description
    String key

    The key whose id is being requested.

    Returns
    Type Description
    Int64

    The keys id value or EmptyId if one does not exist.

    GetId(String, Boolean)

    Get the unique Id for the key name, if one does not exist then a new entry is added.

    Declaration
    public long GetId(string key, bool addNewKey)
    Parameters
    Type Name Description
    String key
    Boolean addNewKey
    Returns
    Type Description
    Int64

    Id of the Key that exists else the Id of the newly created Key if addNewKey is True or EmptyId.

    GetKey(Int64)

    Get the key associated with the id.

    Declaration
    public string GetKey(long id)
    Parameters
    Type Name Description
    Int64 id

    Id the key belongs to.

    Returns
    Type Description
    String

    The found key or null if one can not be found.

    RemapId(Int64, Int64)

    Attempts to change the Id of an entry.

    Declaration
    public bool RemapId(long currentId, long newId)
    Parameters
    Type Name Description
    Int64 currentId

    The current Id that should be changed. Must exist.

    Int64 newId

    The new Id to use. Must not already be in use.

    Returns
    Type Description
    Boolean

    True is the Id was changed successfully.

    RemoveKey(Int64)

    Attempts to remove the key with provided id.

    Declaration
    public void RemoveKey(long id)
    Parameters
    Type Name Description
    Int64 id

    RemoveKey(String)

    Attempts to remove the key from this SharedTableData.

    Declaration
    public void RemoveKey(string key)
    Parameters
    Type Name Description
    String key

    The key to be removed.

    RenameKey(Int64, String)

    Rename the key value for the provided id if it exists.

    Declaration
    public void RenameKey(long id, string newValue)
    Parameters
    Type Name Description
    Int64 id
    String newValue

    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

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Fields
      • EmptyId
    • Properties
      • Entries
      • KeyGenerator
      • Metadata
      • TableCollectionName
      • TableCollectionNameGuid
    • Methods
      • AddKey(String)
      • AddKey(String, Int64)
      • Clear()
      • Contains(Int64)
      • Contains(String)
      • FindSimilarKey(String, out Int32)
      • GetEntry(Int64)
      • GetEntry(String)
      • GetEntryFromReference(TableEntryReference)
      • GetId(String)
      • GetId(String, Boolean)
      • GetKey(Int64)
      • RemapId(Int64, Int64)
      • RemoveKey(Int64)
      • RemoveKey(String)
      • RenameKey(Int64, String)
      • RenameKey(String, String)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023