@@ -225,35 +225,17 @@ public void ReadDelta(Stream stream, bool keepDirtyDelta)
225225 }
226226
227227 /// <inheritdoc />
228- public void ReadField ( Stream stream , bool keepDirtyState )
228+ public void ReadField ( Stream stream )
229229 {
230230 using ( PooledBitReader reader = PooledBitReader . Get ( stream ) )
231231 {
232- if ( keepDirtyState )
233- {
234- dirtyEvents . Add ( new NetworkedDictionaryEvent < TKey , TValue > ( )
235- {
236- eventType = NetworkedDictionaryEvent < TKey , TValue > . NetworkedListEventType . Clear
237- } ) ;
238- }
239-
240232 dictionary . Clear ( ) ;
241233 ushort entryCount = reader . ReadUInt16Packed ( ) ;
242234 for ( int i = 0 ; i < entryCount ; i ++ )
243235 {
244236 TKey key = ( TKey ) reader . ReadObjectPacked ( typeof ( TKey ) ) ;
245237 TValue value = ( TValue ) reader . ReadObjectPacked ( typeof ( TValue ) ) ;
246238 dictionary . Add ( key , value ) ;
247-
248- if ( keepDirtyState )
249- {
250- dirtyEvents . Add ( new NetworkedDictionaryEvent < TKey , TValue > ( )
251- {
252- eventType = NetworkedDictionaryEvent < TKey , TValue > . NetworkedListEventType . Add ,
253- key = key ,
254- value = value
255- } ) ;
256- }
257239 }
258240 }
259241 }
@@ -391,7 +373,9 @@ public TValue this[TKey key]
391373 }
392374 set
393375 {
394- dictionary [ key ] = value ;
376+ if ( NetworkingManager . singleton . isServer )
377+ dictionary [ key ] = value ;
378+
395379 NetworkedDictionaryEvent < TKey , TValue > dictionaryEvent = new NetworkedDictionaryEvent < TKey , TValue > ( )
396380 {
397381 eventType = NetworkedDictionaryEvent < TKey , TValue > . NetworkedListEventType . Value ,
@@ -400,7 +384,7 @@ public TValue this[TKey key]
400384 } ;
401385 dirtyEvents . Add ( dictionaryEvent ) ;
402386
403- if ( OnDictionaryChanged != null )
387+ if ( NetworkingManager . singleton . isServer && OnDictionaryChanged != null )
404388 OnDictionaryChanged ( dictionaryEvent ) ;
405389 }
406390 }
@@ -420,7 +404,9 @@ public TValue this[TKey key]
420404 /// <inheritdoc />
421405 public void Add ( TKey key , TValue value )
422406 {
423- dictionary . Add ( key , value ) ;
407+ if ( NetworkingManager . singleton . isServer )
408+ dictionary . Add ( key , value ) ;
409+
424410 NetworkedDictionaryEvent < TKey , TValue > dictionaryEvent = new NetworkedDictionaryEvent < TKey , TValue > ( )
425411 {
426412 eventType = NetworkedDictionaryEvent < TKey , TValue > . NetworkedListEventType . Add ,
@@ -429,14 +415,16 @@ public void Add(TKey key, TValue value)
429415 } ;
430416 dirtyEvents . Add ( dictionaryEvent ) ;
431417
432- if ( OnDictionaryChanged != null )
418+ if ( NetworkingManager . singleton . isServer && OnDictionaryChanged != null )
433419 OnDictionaryChanged ( dictionaryEvent ) ;
434420 }
435421
436422 /// <inheritdoc />
437423 public void Add ( KeyValuePair < TKey , TValue > item )
438424 {
439- dictionary . Add ( item ) ;
425+ if ( NetworkingManager . singleton . isServer )
426+ dictionary . Add ( item ) ;
427+
440428 NetworkedDictionaryEvent < TKey , TValue > dictionaryEvent = new NetworkedDictionaryEvent < TKey , TValue > ( )
441429 {
442430 eventType = NetworkedDictionaryEvent < TKey , TValue > . NetworkedListEventType . Add ,
@@ -445,21 +433,23 @@ public void Add(KeyValuePair<TKey, TValue> item)
445433 } ;
446434 dirtyEvents . Add ( dictionaryEvent ) ;
447435
448- if ( OnDictionaryChanged != null )
436+ if ( NetworkingManager . singleton . isServer && OnDictionaryChanged != null )
449437 OnDictionaryChanged ( dictionaryEvent ) ;
450438 }
451439
452440 /// <inheritdoc />
453441 public void Clear ( )
454442 {
455- dictionary . Clear ( ) ;
443+ if ( NetworkingManager . singleton . isServer )
444+ dictionary . Clear ( ) ;
445+
456446 NetworkedDictionaryEvent < TKey , TValue > dictionaryEvent = new NetworkedDictionaryEvent < TKey , TValue > ( )
457447 {
458448 eventType = NetworkedDictionaryEvent < TKey , TValue > . NetworkedListEventType . Clear
459449 } ;
460450 dirtyEvents . Add ( dictionaryEvent ) ;
461451
462- if ( OnDictionaryChanged != null )
452+ if ( NetworkingManager . singleton . isServer && OnDictionaryChanged != null )
463453 OnDictionaryChanged ( dictionaryEvent ) ;
464454 }
465455
@@ -490,43 +480,45 @@ public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
490480 /// <inheritdoc />
491481 public bool Remove ( TKey key )
492482 {
483+ if ( NetworkingManager . singleton . isServer )
484+ dictionary . Remove ( key ) ;
485+
493486 TValue value ;
494487 dictionary . TryGetValue ( key , out value ) ;
495- bool state = dictionary . Remove ( key ) ;
496- if ( state )
488+
489+ NetworkedDictionaryEvent < TKey , TValue > dictionaryEvent = new NetworkedDictionaryEvent < TKey , TValue > ( )
497490 {
498- NetworkedDictionaryEvent < TKey , TValue > dictionaryEvent = new NetworkedDictionaryEvent < TKey , TValue > ( )
499- {
500- eventType = NetworkedDictionaryEvent < TKey , TValue > . NetworkedListEventType . Remove ,
501- key = key ,
502- value = value
503- } ;
504- dirtyEvents . Add ( dictionaryEvent ) ;
491+ eventType = NetworkedDictionaryEvent < TKey , TValue > . NetworkedListEventType . Remove ,
492+ key = key ,
493+ value = value
494+ } ;
495+ dirtyEvents . Add ( dictionaryEvent ) ;
496+
497+ if ( NetworkingManager . singleton . isServer && OnDictionaryChanged != null )
498+ OnDictionaryChanged ( dictionaryEvent ) ;
505499
506- if ( OnDictionaryChanged != null )
507- OnDictionaryChanged ( dictionaryEvent ) ;
508- }
509- return state ;
500+ return true ;
510501 }
502+
511503
512504 /// <inheritdoc />
513505 public bool Remove ( KeyValuePair < TKey , TValue > item )
514506 {
515- bool state = dictionary . Remove ( item ) ;
516- if ( state )
507+ if ( NetworkingManager . singleton . isServer )
508+ dictionary . Remove ( item ) ;
509+
510+ NetworkedDictionaryEvent < TKey , TValue > dictionaryEvent = new NetworkedDictionaryEvent < TKey , TValue > ( )
517511 {
518- NetworkedDictionaryEvent < TKey , TValue > dictionaryEvent = new NetworkedDictionaryEvent < TKey , TValue > ( )
519- {
520- eventType = NetworkedDictionaryEvent < TKey , TValue > . NetworkedListEventType . RemovePair ,
521- key = item . Key ,
522- value = item . Value
523- } ;
524- dirtyEvents . Add ( dictionaryEvent ) ;
512+ eventType = NetworkedDictionaryEvent < TKey , TValue > . NetworkedListEventType . RemovePair ,
513+ key = item . Key ,
514+ value = item . Value
515+ } ;
516+ dirtyEvents . Add ( dictionaryEvent ) ;
525517
526- if ( OnDictionaryChanged != null )
527- OnDictionaryChanged ( dictionaryEvent ) ;
528- }
529- return state ;
518+ if ( NetworkingManager . singleton . isServer && OnDictionaryChanged != null )
519+ OnDictionaryChanged ( dictionaryEvent ) ;
520+
521+ return true ;
530522 }
531523
532524 IEnumerator IEnumerable . GetEnumerator ( )
0 commit comments