@@ -393,10 +393,8 @@ public TValue this[TKey key]
393393 key = key ,
394394 value = value
395395 } ;
396- dirtyEvents . Add ( dictionaryEvent ) ;
397396
398- if ( NetworkingManager . Singleton . IsServer && OnDictionaryChanged != null )
399- OnDictionaryChanged ( dictionaryEvent ) ;
397+ HandleAddDictionaryEvent ( dictionaryEvent ) ;
400398 }
401399 }
402400
@@ -424,10 +422,8 @@ public void Add(TKey key, TValue value)
424422 key = key ,
425423 value = value
426424 } ;
427- dirtyEvents . Add ( dictionaryEvent ) ;
428425
429- if ( NetworkingManager . Singleton . IsServer && OnDictionaryChanged != null )
430- OnDictionaryChanged ( dictionaryEvent ) ;
426+ HandleAddDictionaryEvent ( dictionaryEvent ) ;
431427 }
432428
433429 /// <inheritdoc />
@@ -442,10 +438,8 @@ public void Add(KeyValuePair<TKey, TValue> item)
442438 key = item . Key ,
443439 value = item . Value
444440 } ;
445- dirtyEvents . Add ( dictionaryEvent ) ;
446441
447- if ( NetworkingManager . Singleton . IsServer && OnDictionaryChanged != null )
448- OnDictionaryChanged ( dictionaryEvent ) ;
442+ HandleAddDictionaryEvent ( dictionaryEvent ) ;
449443 }
450444
451445 /// <inheritdoc />
@@ -458,10 +452,8 @@ public void Clear()
458452 {
459453 eventType = NetworkedDictionaryEvent < TKey , TValue > . NetworkedListEventType . Clear
460454 } ;
461- dirtyEvents . Add ( dictionaryEvent ) ;
462455
463- if ( NetworkingManager . Singleton . IsServer && OnDictionaryChanged != null )
464- OnDictionaryChanged ( dictionaryEvent ) ;
456+ HandleAddDictionaryEvent ( dictionaryEvent ) ;
465457 }
466458
467459 /// <inheritdoc />
@@ -503,10 +495,8 @@ public bool Remove(TKey key)
503495 key = key ,
504496 value = value
505497 } ;
506- dirtyEvents . Add ( dictionaryEvent ) ;
507498
508- if ( NetworkingManager . Singleton . IsServer && OnDictionaryChanged != null )
509- OnDictionaryChanged ( dictionaryEvent ) ;
499+ HandleAddDictionaryEvent ( dictionaryEvent ) ;
510500
511501 return true ;
512502 }
@@ -524,11 +514,8 @@ public bool Remove(KeyValuePair<TKey, TValue> item)
524514 key = item . Key ,
525515 value = item . Value
526516 } ;
527- dirtyEvents . Add ( dictionaryEvent ) ;
528-
529- if ( NetworkingManager . Singleton . IsServer && OnDictionaryChanged != null )
530- OnDictionaryChanged ( dictionaryEvent ) ;
531517
518+ HandleAddDictionaryEvent ( dictionaryEvent ) ;
532519 return true ;
533520 }
534521
@@ -537,6 +524,23 @@ IEnumerator IEnumerable.GetEnumerator()
537524 {
538525 return dictionary . GetEnumerator ( ) ;
539526 }
527+
528+ private void HandleAddDictionaryEvent ( NetworkedDictionaryEvent < TKey , TValue > dictionaryEvent )
529+ {
530+ if ( NetworkingManager . Singleton . IsServer )
531+ {
532+ if ( NetworkingManager . Singleton . ConnectedClients . Count > 0 )
533+ {
534+ dirtyEvents . Add ( dictionaryEvent ) ;
535+ }
536+
537+ OnDictionaryChanged ? . Invoke ( dictionaryEvent ) ;
538+ }
539+ else
540+ {
541+ dirtyEvents . Add ( dictionaryEvent ) ;
542+ }
543+ }
540544 }
541545
542546 /// <summary>
@@ -547,7 +551,7 @@ IEnumerator IEnumerable.GetEnumerator()
547551 public struct NetworkedDictionaryEvent < TKey , TValue >
548552 {
549553 /// <summary>
550- /// Enum representing the different operations available for triggering an event.
554+ /// Enum representing the different operations available for triggering an event.
551555 /// </summary>
552556 public enum NetworkedListEventType
553557 {
0 commit comments