Skip to content

Commit

Permalink
feat: SyncSet raise event when initially synchronized
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpach committed Oct 23, 2020
1 parent 9f679c5 commit 03f2075
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Assets/Mirror/Runtime/SyncSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,20 @@ public void OnDeserializeAll(NetworkReader reader)

objects.Clear();
changes.Clear();
OnClear?.Invoke();

for (int i = 0; i < count; i++)
{
T obj = reader.Read<T>();
objects.Add(obj);
OnAdd?.Invoke(obj);
}

// We will need to skip all these changes
// the next time the list is synchronized
// because they have already been applied
changesAhead = (int)reader.ReadPackedUInt32();
OnChange?.Invoke();
}

public void OnDeserializeDelta(NetworkReader reader)
Expand Down
31 changes: 31 additions & 0 deletions Assets/Tests/Editor/SyncSetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,37 @@ public void TestInit()
Assert.That(clientSyncSet, Is.EquivalentTo(new[] { "Hello", "World", "!" }));
}

[Test]
public void ClearEventOnSyncAll()
{
Action callback = Substitute.For<Action>();
clientSyncSet.OnClear += callback;
SerializeAllTo(serverSyncSet, clientSyncSet);
callback.Received().Invoke();
}

[Test]
public void InsertEventOnSyncAll()
{
Action<string> callback = Substitute.For<Action<string>>();
clientSyncSet.OnAdd += callback;
SerializeAllTo(serverSyncSet, clientSyncSet);

callback.Received().Invoke("Hello");
callback.Received().Invoke("World");
callback.Received().Invoke("!");
}

[Test]
public void ChangeEventOnSyncAll()
{
Action callback = Substitute.For<Action>();
clientSyncSet.OnChange += callback;
SerializeAllTo(serverSyncSet, clientSyncSet);
callback.Received().Invoke();
}


[Test]
public void TestAdd()
{
Expand Down

0 comments on commit 03f2075

Please sign in to comment.