Photon Fusion 2.1.1

NetworkDictionary< K, V > Struct Template Reference

Fusion type for networking Dictionaries. Maximum capacity is fixed, and is set with the CapacityAttribute.

. More...

Inherits .

Classes

struct  Enumerator
 Enumerator for NetworkDictionary. More...

Public Member Functions

bool Add (K key, V value)
 Adds a new key value pair to the Dictionary. If the key already exists, will return false.
void INetworkDictionary. Add (object item)
 Adds an item to the networked dictionary.
void Clear ()
 Remove all entries from the Dictionary, and clear backing memory.
bool ContainsKey (K key)
 Returns true if the Dictionary contains an entry for the given key.
bool ContainsValue (V value, IEqualityComparer< V > equalityComparer=null)
 Returns true if the Dictionary contains an entry value which compares as equal to given value.
void Dispose ()
 Dispose enumerator.
Get (K key)
 Returns the value for the given key. Will throw an error if the key is not found.
Enumerator GetEnumerator ()
 Returns an enumerator that iterates through the NetworkDictionary.
bool MoveNext ()
 Move to next entry in dictionary.
 NetworkDictionary (int *data, int capacity, IElementReaderWriter< K > keyReaderWriter, IElementReaderWriter< V > valReaderWriter)
 NetworkDictionary constructor.
bool Remove (K key)
 Remove entry from Dictionary.
bool Remove (K key, out V value)
 Removes entry from Dictionary. If successful (key existed), returns true and the value of removed item.
void Reset ()
 Reset enumerator.
Set (K key, V value)
 Sets the value for the given key. Will add a new key if the key does not already exist.
KeyValuePair< K, V >[] ToArray ()
 Copies all key-value pairs to a new array.
NetworkDictionaryReadOnly< K, V > ToReadOnly ()
 Converts the current NetworkDictionary to a read-only version.
bool TryGet (K key, out V value)
 Attempts to get the value for a given key. If found, returns true.

Static Public Member Functions

static implicit operator NetworkDictionaryReadOnly< K, V > (NetworkDictionary< K, V > value)
 Converts the current NetworkDictionary to a read-only version.

Static Public Attributes

const int META_WORD_COUNT = 3
 Meta word count for NetworkDictionary.

Properties

readonly int Capacity [get]
 The maximum number of entries this dictionary may contain.
readonly int Count [get]
 Current number of key/value entries in the Dictionary.
readonly KeyValuePair< K, V > Current [get]
 Current key/value pair.
this[K key] [get, set]
 Key indexer. Gets/Sets value for specified key.

Detailed Description

Fusion type for networking Dictionaries. Maximum capacity is fixed, and is set with the CapacityAttribute.

.

Typical Usage:

[Networked, Capacity(10)]<br></br>
NetworkDictionary&lt;int, float&gt; syncedDict => default;<br></br>
NetworkDictionary(int *data, int capacity, IElementReaderWriter< K > keyReaderWriter, IElementReaderWriter< V > valReaderWriter)
NetworkDictionary constructor.
Definition NetworkDictionary.cs:534
readonly int Capacity
The maximum number of entries this dictionary may contain.
Definition NetworkDictionary.cs:167

Usage for modifying data:

var dict = syncedDict;
dict.Add(5, 123);
dict[5] = 456;
dict.Remove(5);
Template Parameters
KKey can be a primitive, or an INetworkStruct.
VValue can be a primitive, or an INetworkStruct.

Member Function Documentation

◆ Add()

void INetworkDictionary. Add ( object item)

Adds an item to the networked dictionary.

Parameters
itemThe item to add to the dictionary.

Implements INetworkDictionary.

◆ ContainsValue()

bool ContainsValue ( V value,
IEqualityComparer< V > equalityComparer = null )

Returns true if the Dictionary contains an entry value which compares as equal to given value.

Parameters
valueThe value to compare against.
equalityComparerSpecify custom IEqualityComparer to be used for compare.

◆ Remove() [1/2]

bool Remove ( K key)

Remove entry from Dictionary.

Parameters
keyThe key to remove.
Returns
Returns true if key was found.

◆ Remove() [2/2]

bool Remove ( K key,
out V value )

Removes entry from Dictionary. If successful (key existed), returns true and the value of removed item.

Parameters
keyThe key to remove.
valueReturns value of removed item. Returns default value if key did not exist.
Returns
Returns true if key was found.

◆ TryGet()

bool TryGet ( K key,
out V value )

Attempts to get the value for a given key. If found, returns true.

Parameters
keyThe key to remove.
valueReturns value of removed item. Returns default value if key did not exist.
Returns
Returns true if key was found.