Esempio n. 1
0
        /// <inheritdoc />
        public bool Remove(TKey key)
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                dictionary.Remove(key);
            }

            TValue value;

            dictionary.TryGetValue(key, out value);

            NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
            {
                eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Remove,
                key       = key,
                value     = value
            };

            dirtyEvents.Add(dictionaryEvent);

            if (NetworkingManager.Singleton.IsServer && OnDictionaryChanged != null)
            {
                OnDictionaryChanged(dictionaryEvent);
            }

            return(true);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public TValue this[TKey key]
        {
            get
            {
                return(dictionary[key]);
            }
            set
            {
                if (NetworkingManager.Singleton.IsServer)
                {
                    dictionary[key] = value;
                }

                NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
                {
                    eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Value,
                    key       = key,
                    value     = value
                };
                dirtyEvents.Add(dictionaryEvent);

                if (NetworkingManager.Singleton.IsServer && OnDictionaryChanged != null)
                {
                    OnDictionaryChanged(dictionaryEvent);
                }
            }
        }
Esempio n. 3
0
        /// <inheritdoc />
        public void ReadDelta(Stream stream)
        {
            using (PooledBitReader reader = PooledBitReader.Get(stream))
            {
                ushort deltaCount = reader.ReadUInt16Packed();
                for (int i = 0; i < deltaCount; i++)
                {
                    NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType eventType = (NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType)reader.ReadBits(3);
                    switch (eventType)
                    {
                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Add:
                    {
                        TKey   key   = (TKey)reader.ReadObjectPacked(typeof(TKey));
                        TValue value = (TValue)reader.ReadObjectPacked(typeof(TValue));
                        dictionary.Add(key, value);
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Remove:
                    {
                        TKey key = (TKey)reader.ReadObjectPacked(typeof(TKey));
                        dictionary.Remove(key);
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.RemovePair:
                    {
                        TKey   key   = (TKey)reader.ReadObjectPacked(typeof(TKey));
                        TValue value = (TValue)reader.ReadObjectPacked(typeof(TValue));
                        dictionary.Remove(new KeyValuePair <TKey, TValue>(key, value));
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Clear:
                    {
                        //read nothing
                        dictionary.Clear();
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Value:
                    {
                        TKey   key   = (TKey)reader.ReadObjectPacked(typeof(TKey));
                        TValue value = (TValue)reader.ReadObjectPacked(typeof(TValue));
                        if (dictionary.ContainsKey(key))
                        {
                            dictionary[key] = value;
                        }
                    }
                    break;

                    default:
                        break;
                    }
                }
            }
        }
        /// <inheritdoc />
        public void Clear()
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                dictionary.Clear();
            }

            NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
            {
                eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Clear
            };

            HandleAddDictionaryEvent(dictionaryEvent);
        }
Esempio n. 5
0
        /// <inheritdoc />
        public void Clear()
        {
            dictionary.Clear();
            NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
            {
                eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Clear
            };

            dirtyEvents.Add(dictionaryEvent);

            if (OnDictionaryChanged != null)
            {
                OnDictionaryChanged(dictionaryEvent);
            }
        }
        /// <inheritdoc />
        public void Add(TKey key, TValue value)
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                dictionary.Add(key, value);
            }

            NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
            {
                eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Add,
                key       = key,
                value     = value
            };

            HandleAddDictionaryEvent(dictionaryEvent);
        }
        private void HandleAddDictionaryEvent(NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent)
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                if (NetworkingManager.Singleton.ConnectedClients.Count > 0)
                {
                    dirtyEvents.Add(dictionaryEvent);
                }

                OnDictionaryChanged?.Invoke(dictionaryEvent);
            }
            else
            {
                dirtyEvents.Add(dictionaryEvent);
            }
        }
        /// <inheritdoc />
        public void Add(KeyValuePair <TKey, TValue> item)
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                dictionary.Add(item);
            }

            NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
            {
                eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Add,
                key       = item.Key,
                value     = item.Value
            };

            HandleAddDictionaryEvent(dictionaryEvent);
        }
Esempio n. 9
0
        /// <inheritdoc />
        public void Add(TKey key, TValue value)
        {
            dictionary.Add(key, value);
            NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
            {
                eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Add,
                key       = key,
                value     = value
            };

            dirtyEvents.Add(dictionaryEvent);

            if (OnDictionaryChanged != null)
            {
                OnDictionaryChanged(dictionaryEvent);
            }
        }
Esempio n. 10
0
        /// <inheritdoc />
        public void Add(KeyValuePair <TKey, TValue> item)
        {
            dictionary.Add(item);
            NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
            {
                eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Add,
                key       = item.Key,
                value     = item.Value
            };

            dirtyEvents.Add(dictionaryEvent);

            if (OnDictionaryChanged != null)
            {
                OnDictionaryChanged(dictionaryEvent);
            }
        }
        /// <inheritdoc />
        public bool Remove(KeyValuePair <TKey, TValue> item)
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                dictionary.Remove(item);
            }

            NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
            {
                eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.RemovePair,
                key       = item.Key,
                value     = item.Value
            };

            HandleAddDictionaryEvent(dictionaryEvent);
            return(true);
        }
Esempio n. 12
0
        /// <inheritdoc />
        public void Clear()
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                dictionary.Clear();
            }

            NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
            {
                eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Clear
            };

            dirtyEvents.Add(dictionaryEvent);

            if (NetworkingManager.Singleton.IsServer && OnDictionaryChanged != null)
            {
                OnDictionaryChanged(dictionaryEvent);
            }
        }
        /// <inheritdoc />
        public TValue this[TKey key]
        {
            get { return(dictionary[key]); }
            set
            {
                if (NetworkingManager.Singleton.IsServer)
                {
                    dictionary[key] = value;
                }

                NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
                {
                    eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Value,
                    key       = key,
                    value     = value
                };

                HandleAddDictionaryEvent(dictionaryEvent);
            }
        }
Esempio n. 14
0
        /// <inheritdoc />
        public bool Remove(KeyValuePair <TKey, TValue> item)
        {
            bool state = dictionary.Remove(item);

            if (state)
            {
                NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
                {
                    eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.RemovePair,
                    key       = item.Key,
                    value     = item.Value
                };
                dirtyEvents.Add(dictionaryEvent);

                if (OnDictionaryChanged != null)
                {
                    OnDictionaryChanged(dictionaryEvent);
                }
            }
            return(state);
        }
        /// <inheritdoc />
        public void Add(TKey key, TValue value)
        {
            if (NetworkManager.Get().isServer)
            {
                dictionary.Add(key, value);
            }

            NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
            {
                eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Add,
                key       = key,
                value     = value
            };

            dirtyEvents.Add(dictionaryEvent);

            if (NetworkManager.Get().isServer&& OnDictionaryChanged != null)
            {
                OnDictionaryChanged(dictionaryEvent);
            }
        }
Esempio n. 16
0
        /// <inheritdoc />
        public void Add(KeyValuePair <TKey, TValue> item)
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                dictionary.Add(item);
            }

            NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
            {
                eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Add,
                key       = item.Key,
                value     = item.Value
            };

            dirtyEvents.Add(dictionaryEvent);

            if (NetworkingManager.Singleton.IsServer && OnDictionaryChanged != null)
            {
                OnDictionaryChanged(dictionaryEvent);
            }
        }
        /// <inheritdoc />
        public bool Remove(TKey key)
        {
            if (NetworkingManager.Singleton.IsServer)
            {
                dictionary.Remove(key);
            }

            TValue value;

            dictionary.TryGetValue(key, out value);

            NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
            {
                eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Remove,
                key       = key,
                value     = value
            };

            HandleAddDictionaryEvent(dictionaryEvent);

            return(true);
        }
        /// <inheritdoc />
        public bool Remove(KeyValuePair <TKey, TValue> item)
        {
            if (NetworkManager.Get().isServer)
            {
                dictionary.Remove(item);
            }

            NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
            {
                eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.RemovePair,
                key       = item.Key,
                value     = item.Value
            };

            dirtyEvents.Add(dictionaryEvent);

            if (NetworkManager.Get().isServer&& OnDictionaryChanged != null)
            {
                OnDictionaryChanged(dictionaryEvent);
            }

            return(true);
        }
Esempio n. 19
0
        /// <inheritdoc />
        public TValue this[TKey key]
        {
            get
            {
                return(dictionary[key]);
            }
            set
            {
                dictionary[key] = value;
                NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
                {
                    eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Value,
                    key       = key,
                    value     = value
                };
                dirtyEvents.Add(dictionaryEvent);

                if (OnDictionaryChanged != null)
                {
                    OnDictionaryChanged(dictionaryEvent);
                }
            }
        }
Esempio n. 20
0
        /// <inheritdoc />
        public bool Remove(TKey key)
        {
            TValue value;

            dictionary.TryGetValue(key, out value);
            bool state = dictionary.Remove(key);

            if (state)
            {
                NetworkedDictionaryEvent <TKey, TValue> dictionaryEvent = new NetworkedDictionaryEvent <TKey, TValue>()
                {
                    eventType = NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Remove,
                    key       = key,
                    value     = value
                };
                dirtyEvents.Add(dictionaryEvent);

                if (OnDictionaryChanged != null)
                {
                    OnDictionaryChanged(dictionaryEvent);
                }
            }
            return(state);
        }
        /// <inheritdoc />
        public void ReadDelta(Stream stream, bool keepDirtyDelta)
        {
            using (PooledBitReader reader = PooledBitReader.Get(stream))
            {
                ushort deltaCount = reader.ReadUInt16Packed();
                for (int i = 0; i < deltaCount; i++)
                {
                    NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType eventType = (NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType)reader.ReadBits(3);
                    switch (eventType)
                    {
                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Add:
                    {
                        TKey   key   = (TKey)reader.ReadObjectPacked(typeof(TKey));
                        TValue value = (TValue)reader.ReadObjectPacked(typeof(TValue));
                        dictionary.Add(key, value);

                        if (OnDictionaryChanged != null)
                        {
                            OnDictionaryChanged(new NetworkedDictionaryEvent <TKey, TValue>
                                {
                                    eventType = eventType,
                                    key       = key,
                                    value     = value
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            dirtyEvents.Add(new NetworkedDictionaryEvent <TKey, TValue>()
                                {
                                    eventType = eventType,
                                    key       = key,
                                    value     = value
                                });
                        }
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Remove:
                    {
                        TKey   key = (TKey)reader.ReadObjectPacked(typeof(TKey));
                        TValue value;
                        dictionary.TryGetValue(key, out value);
                        dictionary.Remove(key);

                        if (OnDictionaryChanged != null)
                        {
                            OnDictionaryChanged(new NetworkedDictionaryEvent <TKey, TValue>
                                {
                                    eventType = eventType,
                                    key       = key,
                                    value     = value
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            dirtyEvents.Add(new NetworkedDictionaryEvent <TKey, TValue>()
                                {
                                    eventType = eventType,
                                    key       = key,
                                    value     = value
                                });
                        }
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.RemovePair:
                    {
                        TKey   key   = (TKey)reader.ReadObjectPacked(typeof(TKey));
                        TValue value = (TValue)reader.ReadObjectPacked(typeof(TValue));
                        dictionary.Remove(new KeyValuePair <TKey, TValue>(key, value));

                        if (OnDictionaryChanged != null)
                        {
                            OnDictionaryChanged(new NetworkedDictionaryEvent <TKey, TValue>
                                {
                                    eventType = eventType,
                                    key       = key,
                                    value     = value
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            dirtyEvents.Add(new NetworkedDictionaryEvent <TKey, TValue>()
                                {
                                    eventType = eventType,
                                    key       = key,
                                    value     = value
                                });
                        }
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Clear:
                    {
                        //read nothing
                        dictionary.Clear();

                        if (OnDictionaryChanged != null)
                        {
                            OnDictionaryChanged(new NetworkedDictionaryEvent <TKey, TValue>
                                {
                                    eventType = eventType
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            dirtyEvents.Add(new NetworkedDictionaryEvent <TKey, TValue>
                                {
                                    eventType = eventType
                                });
                        }
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Value:
                    {
                        TKey   key   = (TKey)reader.ReadObjectPacked(typeof(TKey));
                        TValue value = (TValue)reader.ReadObjectPacked(typeof(TValue));

                        dictionary[key] = value;

                        if (OnDictionaryChanged != null)
                        {
                            OnDictionaryChanged(new NetworkedDictionaryEvent <TKey, TValue>
                                {
                                    eventType = eventType,
                                    key       = key,
                                    value     = value
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            dirtyEvents.Add(new NetworkedDictionaryEvent <TKey, TValue>()
                                {
                                    eventType = eventType,
                                    key       = key,
                                    value     = value
                                });
                        }
                    }
                    break;
                    }
                }
            }
        }