Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,14 @@ public TValue this[TKey key]
set
{
if (NetworkingManager.Singleton.IsServer)
{
dictionary[key] = value;
if (NetworkingManager.Singleton.ConnectedClients.Count == 0)
{
dirtyEvents.Clear();
return;
}
}

NetworkedDictionaryEvent<TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent<TKey, TValue>()
{
Expand Down Expand Up @@ -416,7 +423,14 @@ public TValue this[TKey key]
public void Add(TKey key, TValue value)
{
if (NetworkingManager.Singleton.IsServer)
{
dictionary.Add(key, value);
if (NetworkingManager.Singleton.ConnectedClients.Count == 0)
{
dirtyEvents.Clear();
return;
}
}

NetworkedDictionaryEvent<TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent<TKey, TValue>()
{
Expand All @@ -434,7 +448,14 @@ public void Add(TKey key, TValue value)
public void Add(KeyValuePair<TKey, TValue> item)
{
if (NetworkingManager.Singleton.IsServer)
{
dictionary.Add(item);
if (NetworkingManager.Singleton.ConnectedClients.Count == 0)
{
dirtyEvents.Clear();
return;
}
}

NetworkedDictionaryEvent<TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent<TKey, TValue>()
{
Expand All @@ -452,7 +473,14 @@ public void Add(KeyValuePair<TKey, TValue> item)
public void Clear()
{
if (NetworkingManager.Singleton.IsServer)
{
dictionary.Clear();
if (NetworkingManager.Singleton.ConnectedClients.Count == 0)
{
dirtyEvents.Clear();
return;
}
}

NetworkedDictionaryEvent<TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent<TKey, TValue>()
{
Expand Down Expand Up @@ -492,7 +520,14 @@ public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
public bool Remove(TKey key)
{
if (NetworkingManager.Singleton.IsServer)
{
dictionary.Remove(key);
if (NetworkingManager.Singleton.ConnectedClients.Count == 0)
{
dirtyEvents.Clear();
return true;
}
}

TValue value;
dictionary.TryGetValue(key, out value);
Expand All @@ -516,7 +551,14 @@ public bool Remove(TKey key)
public bool Remove(KeyValuePair<TKey, TValue> item)
{
if (NetworkingManager.Singleton.IsServer)
{
dictionary.Remove(item);
if (NetworkingManager.Singleton.ConnectedClients.Count == 0)
{
dirtyEvents.Clear();
return true;
}
}

NetworkedDictionaryEvent<TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent<TKey, TValue>()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using MLAPI.Serialization;
using MLAPI.Serialization.Pooled;
using UnityEngine;

namespace MLAPI.NetworkedVar.Collections
{
Expand Down Expand Up @@ -406,7 +407,15 @@ IEnumerator IEnumerable.GetEnumerator()
public void Add(T item)
{
if (NetworkingManager.Singleton.IsServer)
{
list.Add(item);
if (NetworkingManager.Singleton.ConnectedClients.Count == 0)
{
dirtyEvents.Clear();
return;
}
}


NetworkedListEvent<T> listEvent = new NetworkedListEvent<T>()
{
Expand All @@ -424,7 +433,14 @@ public void Add(T item)
public void Clear()
{
if (NetworkingManager.Singleton.IsServer)
{
list.Clear();
if (NetworkingManager.Singleton.ConnectedClients.Count == 0)
{
dirtyEvents.Clear();
return;
}
}

NetworkedListEvent<T> listEvent = new NetworkedListEvent<T>()
{
Expand Down Expand Up @@ -452,7 +468,14 @@ public void CopyTo(T[] array, int arrayIndex)
public bool Remove(T item)
{
if (NetworkingManager.Singleton.IsServer)
{
list.Remove(item);
if (NetworkingManager.Singleton.ConnectedClients.Count == 0)
{
dirtyEvents.Clear();
return true;
}
}

NetworkedListEvent<T> listEvent = new NetworkedListEvent<T>()
{
Expand Down Expand Up @@ -483,7 +506,14 @@ public int IndexOf(T item)
public void Insert(int index, T item)
{
if (NetworkingManager.Singleton.IsServer)
{
list.Insert(index, item);
if (NetworkingManager.Singleton.ConnectedClients.Count == 0)
{
dirtyEvents.Clear();
return;
}
}

NetworkedListEvent<T> listEvent = new NetworkedListEvent<T>()
{
Expand All @@ -501,7 +531,14 @@ public void Insert(int index, T item)
public void RemoveAt(int index)
{
if (NetworkingManager.Singleton.IsServer)
{
list.RemoveAt(index);
if (NetworkingManager.Singleton.ConnectedClients.Count == 0)
{
dirtyEvents.Clear();
return;
}
}

NetworkedListEvent<T> listEvent = new NetworkedListEvent<T>()
{
Expand All @@ -522,7 +559,14 @@ public T this[int index]
set
{
if (NetworkingManager.Singleton.IsServer)
{
list[index] = value;
if (NetworkingManager.Singleton.ConnectedClients.Count == 0)
{
dirtyEvents.Clear();
return;
}
}

NetworkedListEvent<T> listEvent = new NetworkedListEvent<T>()
{
Expand Down