class in Unity.Localization
Implements interfaces:IKeyGenerator, ISerializationCallbackReceiver
The default key generator. It produces a distributed unique id, Snowflake-style, that combines a timestamp, a machine id, and a per-millisecond sequence.
The generated ids are non-sequential, so several users can add keys to the same table without id collisions. The id
packs a per-millisecond sequence (12 bits), a machine id (10 bits), and a timestamp measured from
DistributedUIDGenerator.CustomEpoch (41 bits). Timestamps count from a fixed default epoch of 2020-01-01T00:00:00Z, and every
generator in the process draws from one sequence counter, so two default generators created at the same moment
still hand out different ids. The machine id is derived from
SystemInfo.deviceUniqueIdentifier so it is stable per machine. Assign an instance to
SharedTableData.KeyGenerator to control how a collection assigns key ids, or implement
IKeyGenerator for a different scheme.
Additional resources: IKeyGenerator, SharedTableData
Generate two ids and confirm they differ.
using Unity.Localization; using UnityEngine;
namespace Unity.Localization.Samples { public class DistributedUIDGeneratorOverviewExample { public void Run() { var generator = new DistributedUIDGenerator();
var first = generator.GetNextKey(); var second = generator.GetNextKey();
Debug.Log(first != second); // True: ids are unique } } }
| Property | Description |
|---|---|
| CustomEpoch | The epoch, in Unix milliseconds, that timestamps are measured from. |
| MachineId | The machine id folded into each id. |
| Constructor | Description |
|---|---|
| DistributedUIDGenerator | Creates a generator that measures timestamps from the default epoch. |
| Method | Description |
|---|---|
| GetNextKey | Returns the next distributed unique id. |