SyncDictionary
SyncDictionary is an easy way to keep a Dictionary collection automatically synchronized over the network.
private readonly SyncDictionary<NetworkConnection, string> _playerNames = new();
private void Awake()
{
_playerNames.OnChange += _playerNames_OnChange;
}
// SyncDictionaries also include the asServer parameter.
private void _playerNames_OnChange(SyncDictionaryOperation op,
NetworkConnection key, string value, bool asServer)
{
/* Key will be provided for
* Add, Remove, and Set. */
switch (op)
{
// Adds key with value.
case SyncDictionaryOperation.Add:
break;
// Removes key.
case SyncDictionaryOperation.Remove:
break;
// Sets key to a new value.
case SyncDictionaryOperation.Set:
break;
// Clears the dictionary.
case SyncDictionaryOperation.Clear:
break;
// Like SyncList, indicates all operations are complete.
case SyncDictionaryOperation.Complete:
break;
}
}Last updated