Skip to content

Commit

Permalink
Use standard C# events instead of one callback (MirrorNetworking#100)
Browse files Browse the repository at this point in the history
* Use standard C# events instead of one callback

* Fix tests

* Trigger new build

* Trigger new build

* Remove blank line
  • Loading branch information
paulpach authored and vis2k committed Nov 1, 2018
1 parent 9068803 commit 0a16b18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 7 additions & 8 deletions Mirror/Runtime/SyncList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public abstract class SyncList<T> : IList<T>, SyncObject

public int Count { get { return m_Objects.Count; } }
public bool IsReadOnly { get { return false; } }
public SyncListChanged Callback { get { return m_Callback; } set { m_Callback = value; } }
public event SyncListChanged Callback;

public enum Operation : byte
{
Expand All @@ -132,8 +132,6 @@ struct Change
// so we need to skip them
int changesAhead = 0;

SyncListChanged m_Callback;

protected abstract void SerializeItem(NetworkWriter writer, T item);
protected abstract T DeserializeItem(NetworkReader reader);

Expand Down Expand Up @@ -163,10 +161,10 @@ void AddOperation(Operation op, int itemIndex, T item)

Changes.Add(change);

// ensure it is invoked on host
if (m_Callback != null)
SyncListChanged listChanged = Callback;
if (listChanged != null)
{
m_Callback.Invoke(op, itemIndex);
listChanged(op, itemIndex);
}
}

Expand Down Expand Up @@ -321,9 +319,10 @@ public void OnDeserializeDelta(NetworkReader reader)
break;
}

if (m_Callback != null && apply)
SyncListChanged listChanged = Callback;
if (apply && listChanged != null)
{
m_Callback.Invoke(operation, index);
listChanged(operation, index);
}

// we just skipped this change
Expand Down
3 changes: 1 addition & 2 deletions Mirror/Tests/SyncListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ public void SyncListFloatTest()
public void CallbackTest()
{
bool called = false;
clientSyncList.Callback = (op, index) => { called = true; };

clientSyncList.Callback += (op, index) => { called = true; };
serverSyncList.Add("yay");
SerializeDeltaTo(serverSyncList, clientSyncList);

Expand Down

0 comments on commit 0a16b18

Please sign in to comment.