diff --git a/Assets/Mirror/Runtime/SyncDictionary.cs b/Assets/Mirror/Runtime/SyncDictionary.cs index ff662e340..669911958 100644 --- a/Assets/Mirror/Runtime/SyncDictionary.cs +++ b/Assets/Mirror/Runtime/SyncDictionary.cs @@ -229,13 +229,14 @@ public TValue this[TKey i] { if (ContainsKey(i)) { + objects[i] = value; AddOperation(Operation.OP_SET, i, value); } else { + objects[i] = value; AddOperation(Operation.OP_ADD, i, value); } - objects[i] = value; } } diff --git a/Assets/Mirror/Tests/Editor/SyncDictionaryTest.cs b/Assets/Mirror/Tests/Editor/SyncDictionaryTest.cs index b883a938c..2d6ad7406 100644 --- a/Assets/Mirror/Tests/Editor/SyncDictionaryTest.cs +++ b/Assets/Mirror/Tests/Editor/SyncDictionaryTest.cs @@ -159,12 +159,31 @@ public void CallbackTest() Assert.That(op, Is.EqualTo(SyncDictionaryIntString.Operation.OP_ADD)); Assert.That(index, Is.EqualTo(3)); Assert.That(item, Is.EqualTo("yay")); + Assert.That(clientSyncDictionary[index], Is.EqualTo("yay")); + }; serverSyncDictionary.Add(3, "yay"); SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary); Assert.That(called, Is.True); } + [Test] + public void ServerCallbackTest() + { + bool called = false; + serverSyncDictionary.Callback += (op, index, item) => + { + called = true; + + Assert.That(op, Is.EqualTo(SyncDictionaryIntString.Operation.OP_ADD)); + Assert.That(index, Is.EqualTo(3)); + Assert.That(item, Is.EqualTo("yay")); + Assert.That(serverSyncDictionary[index], Is.EqualTo("yay")); + }; + serverSyncDictionary[3] = "yay"; + Assert.That(called, Is.True); + } + [Test] public void CallbackRemoveTest() {