SyncDictionary
A SyncDictionary is an associative array containing an unordered list of key, value pairs. Keys and values can be any supported mirror type. By default we use .Net Dictionary which may impose additional constraints on the keys and values.
SyncDictionary works much like SyncLists: when you make a change on the server the change is propagated to all clients and the Callback is called. Only deltas are transmitted.
Usage
Add a field to your NetworkBehaviour class of type SyncDictionary
.
SyncDictionary must
be declared readonly and initialized in the constructor.
Note that by the time you subscribe to the callback, the dictionary will already be initialized, so you will not get a call for the initial data, only updates.
Simple Example
By default, SyncDictionary uses a Dictionary to store it's data. If you want to use a different IDictionary
implementation such as SortedList or SortedDictionary, then use SyncIDictionary
and pass the dictionary instance you want it to use. For example:
Last updated