diff --git a/Assets/Mirror/Runtime/SyncDictionary.cs b/Assets/Mirror/Runtime/SyncDictionary.cs index f2ea6364d..70ca170f5 100644 --- a/Assets/Mirror/Runtime/SyncDictionary.cs +++ b/Assets/Mirror/Runtime/SyncDictionary.cs @@ -5,11 +5,11 @@ namespace Mirror { [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class SyncDictionary : IDictionary, SyncObject + public abstract class SyncIDictionary : IDictionary, SyncObject { public delegate void SyncDictionaryChanged(Operation op, TKey key, TValue item); - readonly IDictionary objects; + protected readonly IDictionary objects; public int Count => objects.Count; public bool IsReadOnly { get; private set; } @@ -53,17 +53,7 @@ protected virtual void SerializeItem(NetworkWriter writer, TValue item) { } // this should be called after a successfull sync public void Flush() => changes.Clear(); - protected SyncDictionary() - { - objects = new Dictionary(); - } - - protected SyncDictionary(IEqualityComparer eq) - { - objects = new Dictionary(eq); - } - - protected SyncDictionary(IDictionary objects) + protected SyncIDictionary(IDictionary objects) { this.objects = objects; } @@ -301,8 +291,26 @@ public bool Remove(KeyValuePair item) return result; } - public IEnumerator> GetEnumerator() => ((IDictionary)objects).GetEnumerator(); + public IEnumerator> GetEnumerator() => objects.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => objects.GetEnumerator(); + } + + public abstract class SyncDictionary: SyncIDictionary + { + protected SyncDictionary() : base(new Dictionary()) + { + } + + protected SyncDictionary(IEqualityComparer eq) : base(new Dictionary(eq)) + { + } + + public new Dictionary.ValueCollection Values => ((Dictionary)objects).Values; + + public new Dictionary.KeyCollection Keys => ((Dictionary)objects).Keys; + + public new Dictionary.Enumerator GetEnumerator() => ((Dictionary)objects).GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => ((IDictionary)objects).GetEnumerator(); } }