Class NetKeyTable<T>

Namespace
Unity.Multiplayer.Core

Live objects by their network key (UM-T60), the engine-free core of the adapter's NetRegistry: at most one item per key, a second claim on a held key refused, and a removal honoured only for the item that holds the key (so a late despawn of an old object never unregisters the new one that took its key).

public sealed class NetKeyTable<T> where T : class

Type Parameters

T
Inheritance
NetKeyTable<T>
Inherited Members

Remarks

Not thread-safe; the adapter uses it from Unity's main thread.

Properties

Count

How many keys are held.

public int Count { get; }

Property Value

int

Items

Every item that holds a key (a copy).

public IReadOnlyList<T> Items { get; }

Property Value

IReadOnlyList<T>

Keys

Every held key (a copy).

public IReadOnlyList<string> Keys { get; }

Property Value

IReadOnlyList<string>

Methods

Add(string, T, out T)

Gives item key unless the key is invalid or another item holds it.

public NetKeyAddResult Add(string key, T item, out T holder)

Parameters

key string

The key to claim.

item T

The item claiming it.

holder T

The item holding the key afterwards (the existing one on Duplicate); null for an invalid key.

Returns

NetKeyAddResult

Exceptions

ArgumentNullException

item is null.

Clear()

Forgets every key.

public void Clear()

Contains(string)

True when some item holds key.

public bool Contains(string key)

Parameters

key string

Returns

bool

Get(string)

The item holding key.

public T Get(string key)

Parameters

key string

Returns

T

Exceptions

KeyNotFoundException

No item holds it (NotFoundMessage(string)).

Remove(string, T)

Frees key if item holds it.

public bool Remove(string key, T item)

Parameters

key string
item T

Returns

bool

True when the key was freed; false when it is unknown or held by another item.

TryGet(string, out T)

The item holding key.

public bool TryGet(string key, out T item)

Parameters

key string
item T

Returns

bool