diff --git a/Assets/Mirror/Runtime/SyncDictionary.cs b/Assets/Mirror/Runtime/SyncDictionary.cs index dad5f50ce..62ef73bf4 100644 --- a/Assets/Mirror/Runtime/SyncDictionary.cs +++ b/Assets/Mirror/Runtime/SyncDictionary.cs @@ -9,9 +9,9 @@ public abstract class SyncDictionary : IDictionary, SyncObject { public delegate void SyncDictionaryChanged(Operation op, K key, V item); - readonly Dictionary m_Objects; + readonly Dictionary objects; - public int Count => m_Objects.Count; + public int Count => objects.Count; public bool IsReadOnly { get; private set; } public event SyncDictionaryChanged Callback; @@ -31,7 +31,7 @@ struct Change internal V item; } - readonly List Changes = new List(); + readonly List changes = new List(); // how many changes we need to ignore // this is needed because when we initialize the list, // we might later receive changes that have already been applied @@ -43,24 +43,24 @@ protected virtual void SerializeItem(NetworkWriter writer, V item) {} protected virtual K DeserializeKey(NetworkReader reader) => default; protected virtual V DeserializeItem(NetworkReader reader) => default; - public bool IsDirty => Changes.Count > 0; + public bool IsDirty => changes.Count > 0; - public ICollection Keys => m_Objects.Keys; + public ICollection Keys => objects.Keys; - public ICollection Values => m_Objects.Values; + public ICollection Values => objects.Values; // throw away all the changes // this should be called after a successfull sync - public void Flush() => Changes.Clear(); + public void Flush() => changes.Clear(); public SyncDictionary() { - m_Objects = new Dictionary(); + objects = new Dictionary(); } public SyncDictionary(IEqualityComparer eq) { - m_Objects = new Dictionary(eq); + objects = new Dictionary(eq); } void AddOperation(Operation op, K key, V item) @@ -77,7 +77,7 @@ void AddOperation(Operation op, K key, V item) item = item }; - Changes.Add(change); + changes.Add(change); Callback?.Invoke(op, key, item); } @@ -85,9 +85,9 @@ void AddOperation(Operation op, K key, V item) public void OnSerializeAll(NetworkWriter writer) { // if init, write the full list content - writer.WritePackedUInt32((uint)m_Objects.Count); + writer.WritePackedUInt32((uint)objects.Count); - foreach (KeyValuePair syncItem in m_Objects) + foreach (KeyValuePair syncItem in objects) { SerializeKey(writer, syncItem.Key); SerializeItem(writer, syncItem.Value); @@ -97,17 +97,17 @@ public void OnSerializeAll(NetworkWriter writer) // thus the client will need to skip all the pending changes // or they would be applied again. // So we write how many changes are pending - writer.WritePackedUInt32((uint)Changes.Count); + writer.WritePackedUInt32((uint)changes.Count); } public void OnSerializeDelta(NetworkWriter writer) { // write all the queued up changes - writer.WritePackedUInt32((uint)Changes.Count); + writer.WritePackedUInt32((uint)changes.Count); - for (int i = 0; i < Changes.Count; i++) + for (int i = 0; i < changes.Count; i++) { - Change change = Changes[i]; + Change change = changes[i]; writer.Write((byte)change.operation); switch (change.operation) @@ -133,14 +133,14 @@ public void OnDeserializeAll(NetworkReader reader) // if init, write the full list content int count = (int)reader.ReadPackedUInt32(); - m_Objects.Clear(); - Changes.Clear(); + objects.Clear(); + changes.Clear(); for (int i = 0; i < count; i++) { K key = DeserializeKey(reader); V obj = DeserializeItem(reader); - m_Objects.Add(key, obj); + objects.Add(key, obj); } // We will need to skip all these changes @@ -175,14 +175,14 @@ public void OnDeserializeDelta(NetworkReader reader) item = DeserializeItem(reader); if (apply) { - m_Objects[key] = item; + objects[key] = item; } break; case Operation.OP_CLEAR: if (apply) { - m_Objects.Clear(); + objects.Clear(); } break; @@ -191,7 +191,7 @@ public void OnDeserializeDelta(NetworkReader reader) item = DeserializeItem(reader); if (apply) { - m_Objects.Remove(key); + objects.Remove(key); } break; } @@ -210,15 +210,15 @@ public void OnDeserializeDelta(NetworkReader reader) public void Clear() { - m_Objects.Clear(); + objects.Clear(); AddOperation(Operation.OP_CLEAR, default, default); } - public bool ContainsKey(K key) => m_Objects.ContainsKey(key); + public bool ContainsKey(K key) => objects.ContainsKey(key); public bool Remove(K key) { - if (m_Objects.TryGetValue(key, out V item) && m_Objects.Remove(key)) + if (objects.TryGetValue(key, out V item) && objects.Remove(key)) { AddOperation(Operation.OP_REMOVE, key, item); return true; @@ -228,12 +228,12 @@ public bool Remove(K key) public void Dirty(K index) { - AddOperation(Operation.OP_DIRTY, index, m_Objects[index]); + AddOperation(Operation.OP_DIRTY, index, objects[index]); } public V this[K i] { - get => m_Objects[i]; + get => objects[i]; set { if (TryGetValue(i, out V val)) @@ -244,15 +244,15 @@ public V this[K i] { AddOperation(Operation.OP_ADD, i, value); } - m_Objects[i] = value; + objects[i] = value; } } - public bool TryGetValue(K key, out V value) => m_Objects.TryGetValue(key, out value); + public bool TryGetValue(K key, out V value) => objects.TryGetValue(key, out value); public void Add(K key, V value) { - m_Objects.Add(key, value); + objects.Add(key, value); AddOperation(Operation.OP_ADD, key, value); } @@ -279,7 +279,7 @@ public void CopyTo(KeyValuePair[] array, int arrayIndex) } int i = arrayIndex; - foreach (KeyValuePair item in m_Objects) + foreach (KeyValuePair item in objects) { array[i] = item; i++; @@ -288,7 +288,7 @@ public void CopyTo(KeyValuePair[] array, int arrayIndex) public bool Remove(KeyValuePair item) { - bool result = m_Objects.Remove(item.Key); + bool result = objects.Remove(item.Key); if (result) { AddOperation(Operation.OP_REMOVE, item.Key, item.Value); @@ -296,8 +296,8 @@ public bool Remove(KeyValuePair item) return result; } - public IEnumerator> GetEnumerator() => ((IDictionary)m_Objects).GetEnumerator(); + public IEnumerator> GetEnumerator() => ((IDictionary)objects).GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => ((IDictionary)m_Objects).GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => ((IDictionary)objects).GetEnumerator(); } }