mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
fix(SyncList): Clear after Callback
Allows users to iterate the list before it's wiped
This commit is contained in:
parent
c7305db462
commit
aecc8f2587
@ -192,12 +192,14 @@ public override void OnDeserializeDelta(NetworkReader reader)
|
||||
case Operation.OP_CLEAR:
|
||||
if (apply)
|
||||
{
|
||||
objects.Clear();
|
||||
// add dirty + changes.
|
||||
// ClientToServer needs to set dirty in server OnDeserialize.
|
||||
// no access check: server OnDeserialize can always
|
||||
// write, even for ClientToServer (for broadcasting).
|
||||
AddOperation(Operation.OP_CLEAR, 0, default, default, false);
|
||||
// clear after invoking the callback so users can iterate the list
|
||||
// and take appropriate action on the items before they are wiped.
|
||||
objects.Clear();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -267,8 +269,10 @@ public void AddRange(IEnumerable<T> range)
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
objects.Clear();
|
||||
AddOperation(Operation.OP_CLEAR, 0, default, default, true);
|
||||
// clear after invoking the callback so users can iterate the list
|
||||
// and take appropriate action on the items before they are wiped.
|
||||
objects.Clear();
|
||||
}
|
||||
|
||||
public bool Contains(T item) => IndexOf(item) >= 0;
|
||||
|
@ -97,9 +97,19 @@ public void TestAddRange()
|
||||
[Test]
|
||||
public void TestClear()
|
||||
{
|
||||
bool called = false;
|
||||
clientSyncList.Callback = (op, index, oldItem, newItem) =>
|
||||
{
|
||||
called = true;
|
||||
|
||||
Assert.That(op, Is.EqualTo(SyncList<string>.Operation.OP_CLEAR));
|
||||
Assert.That(clientSyncList.Count, Is.EqualTo(3));
|
||||
};
|
||||
|
||||
serverSyncList.Clear();
|
||||
SerializeDeltaTo(serverSyncList, clientSyncList);
|
||||
Assert.That(clientSyncList, Is.EquivalentTo(new string[] {}));
|
||||
Assert.That(called, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
Loading…
Reference in New Issue
Block a user