Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

IKeyGenerator

interface in Unity.Localization

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Generates the unique ids assigned to table keys.

A collection's SharedTableData asks its generator for a new id whenever a key is added, and the id stays with that key for its lifetime. The default implementation is DistributedUIDGenerator, which produces non-sequential ids so several users can add keys without collisions. Implement this interface to supply a different scheme, then assign it through SharedTableData.KeyGenerator.

Additional resources: DistributedUIDGenerator, SharedTableData

<para>A simple generator that hands out increasing ids.</para>

using Unity.Localization;
using UnityEngine;

namespace Unity.Localization.Samples { public class IKeyGeneratorExample : IKeyGenerator { long m_Next = 1;

public long GetNextKey() => m_Next++;

public static void Use() { var sharedData = ScriptableObject.CreateInstance<SharedTableData>(); sharedData.KeyGenerator = new IKeyGeneratorExample();

SharedTableData.SharedTableEntry entry = sharedData.AddKey("GREETING");

Debug.Log(entry.Id); // 1 } } }

Public Methods

Method Description
GetNextKey Returns the next id to assign to a key.