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

DistributedUIDGenerator Constructor

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

Declaration

public DistributedUIDGenerator();

Description

Creates a generator that measures timestamps from the current time.

The current UTC time becomes the DistributedUIDGenerator.CustomEpoch. Use the DistributedUIDGenerator.DistributedUIDGenerator overload to pin the epoch to a fixed point instead.

<para>Assign a default generator to a collection's shared data.</para>

using Unity.Localization;
using UnityEngine;

namespace Unity.Localization.Samples { public class DistributedUIDGeneratorConstructorExample { public void Run() { var sharedData = ScriptableObject.CreateInstance<SharedTableData>(); sharedData.KeyGenerator = new DistributedUIDGenerator();

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

Debug.Log(entry.Id != 0); // True } } }

Declaration

public DistributedUIDGenerator(long customEpoch);

Parameters

Parameter Description
customEpoch The epoch, in Unix milliseconds, that timestamps are measured from.

Description

Creates a generator that measures timestamps from a specific epoch.

Because the timestamp portion of each id counts from customEpoch, a later epoch keeps ids smaller for longer before the 41-bit timestamp range is exhausted.

<para>Create a generator pinned to a fixed epoch.</para>

using System;
using Unity.Localization;
using UnityEngine;

namespace Unity.Localization.Samples { public class DistributedUIDGeneratorCustomEpochExample { public void Run() { var epoch = new DateTimeOffset(2020, 1, 1, 0, 0, 0, TimeSpan.Zero).ToUnixTimeMilliseconds(); var generator = new DistributedUIDGenerator(epoch);

Debug.Log(generator.CustomEpoch == epoch); // True } } }