docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class DistributedUIDGenerator

    A Key generator that uses the current time in ms with the machine id to generate a unique value every time. This means it is safe for multiple users to add entries to the same table without suffering from conflicts due to the entries using the same key but having different values.

    The implementation is based on this article https://www.callicoder.com/distributed-unique-id-sequence-number-generator/

    The Key is made up of the following components:

    Sequence Number12 Bits(0 - 11)A local counter per machine that starts at 0 and is incremented by 1 for each new id request that is made during the same millisecond. The value is limited to 12 bytes so can contain 4095 items before the ids for this millisecond are exhausted and the id generator must wait until the next millisecond before it can continue.
    Machine Id10 Bits(12-21)The Id of the machine. By default, in the Editor, this value is generated from the machines network interface physical address however it can also be set to a user provided value. There is enough space for 1024 machines.
    Epoch Timestamp.41 Bits(22-63)A timestamp using a custom epoch which is the time the class was created. The maximum timestamp that can be represented is 69 years from the custom epoch, at this point the Key generator will have exhausted its possible unique Ids.
    Signed Bit 1 Bit(64) The signed bit is unused by the ID generator. If you wish to add custom Id values then using the signed bit and adding negative ids will avoid conflicts.
    Inheritance
    object
    DistributedUIDGenerator
    Implements
    IKeyGenerator
    Namespace: UnityEngine.Localization.Tables
    Assembly: Unity.Localization.dll
    Syntax
    [Serializable]
    public class DistributedUIDGenerator : IKeyGenerator

    Constructors

    Name Description
    DistributedUIDGenerator()

    Create a default instance which uses the current time as the CustomEpoch the machines physical address as MachineId.

    DistributedUIDGenerator(long)

    Creates an instance with a defined CustomEpoch.

    Fields

    Name Description
    MachineIdPrefKey

    The name of the EditorPrefs that is used to store the machine id.

    Properties

    Name Description
    CustomEpoch

    The custom epoch used to generate the timestamp.

    MachineId

    The Id of the current machine. By default, in the Editor, this value is generated from the machines network interface physical address however it can also be set to a user provided value. There is enough space for 1024 unique machines. Set value will be clamped in the range 1-1023. The value is not serialized into the asset but stored into the EditorPrefs(Editor only).

    Methods

    Name Description
    GetNextKey()

    Returns the next Id using the current time, machine id and sequence number.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)