Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


DistributedUIDGenerator

The default key generator. It produces a distributed unique id, Snowflake-style, that combines a timestamp, a machine id, and a per-millisecond sequence.
Read time 1 minuteLast updated 6 days ago

Definition

public class DistributedUIDGenerator : IKeyGenerator

Remarks

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). The machine id is derived from _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.

Examples

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 } }}

Constructors

Constructor

Description

DistributedUIDGenerator()Creates a generator that measures timestamps from the current time.
DistributedUIDGenerator(System.Int64)Creates a generator that measures timestamps from a specific epoch.

Properties

Property

Description

CustomEpochThe epoch, in Unix milliseconds, that timestamps are measured from.
MachineIdThe machine id folded into each id.

Methods

Method

Description

GetNextKeyReturns the next distributed unique id.