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

DistributedUIDGenerator

class in Unity.Localization


Implements interfaces:IKeyGenerator

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

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). 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

<para>Generate two ids and confirm they differ.</para>

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

Properties

Property Description
CustomEpoch The epoch, in Unix milliseconds, that timestamps are measured from.
MachineId The machine id folded into each id.

Constructors

Constructor Description
DistributedUIDGenerator Creates a generator that measures timestamps from the current time.

Public Methods

Method Description
GetNextKey Returns the next distributed unique id.