feat: SyncList now supports any IList implementation (#704)

This commit is contained in:
Paul Pacheco 2019-04-02 21:39:19 -05:00 committed by GitHub
parent 523c2eff49
commit 040bcb45ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,7 +54,7 @@ public abstract class SyncList<T> : IList<T>, SyncObject
{ {
public delegate void SyncListChanged(Operation op, int itemIndex, T item); public delegate void SyncListChanged(Operation op, int itemIndex, T item);
readonly List<T> objects = new List<T>(); readonly IList<T> objects;
public int Count => objects.Count; public int Count => objects.Count;
public bool IsReadOnly { get; private set; } public bool IsReadOnly { get; private set; }
@ -88,6 +88,17 @@ struct Change
protected virtual void SerializeItem(NetworkWriter writer, T item) {} protected virtual void SerializeItem(NetworkWriter writer, T item) {}
protected virtual T DeserializeItem(NetworkReader reader) => default; protected virtual T DeserializeItem(NetworkReader reader) => default;
protected SyncList()
{
objects = new List<T>();
}
protected SyncList(IList<T> objects)
{
this.objects = objects;
}
public bool IsDirty => changes.Count > 0; public bool IsDirty => changes.Count > 0;
// throw away all the changes // throw away all the changes