File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed
Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -12,5 +12,12 @@ public class SyncedVarAttribute : Attribute
1212 /// The channel to send changes on.
1313 /// </summary>
1414 public string Channel = "MLAPI_DEFAULT_MESSAGE" ;
15+
16+ /// <summary>
17+ /// The maximum times per second this var will be synced.
18+ /// A value of 0 will cause the variable to sync as soon as possible after being changed.
19+ /// A value of less than 0 will cause the variable to sync only at once at spawn and not update again.
20+ /// </summary>
21+ public float SendTickrate = 0 ;
1522 }
1623}
Original file line number Diff line number Diff line change @@ -11,19 +11,25 @@ internal class SyncedVarContainer
1111 internal object fieldInstance ;
1212 internal object value ;
1313 internal bool isDirty ;
14+ internal float lastSyncedTime ;
1415
1516 internal bool IsDirty ( )
1617 {
17- object newValue = field . GetValue ( fieldInstance ) ;
18- object oldValue = value ;
19-
20- if ( newValue != oldValue || isDirty )
18+ if ( attribute . SendTickrate >= 0 && ( attribute . SendTickrate == 0 || NetworkingManager . Singleton . NetworkTime - lastSyncedTime >= ( 1f / attribute . SendTickrate ) ) )
2119 {
22- isDirty = true ;
20+ lastSyncedTime = NetworkingManager . Singleton . NetworkTime ;
21+
22+ object newValue = field . GetValue ( fieldInstance ) ;
23+ object oldValue = value ;
2324
24- value = newValue ;
25+ if ( newValue != oldValue || isDirty )
26+ {
27+ isDirty = true ;
2528
26- return true ;
29+ value = newValue ;
30+
31+ return true ;
32+ }
2733 }
2834
2935 return false ;
You can’t perform that action at this time.
0 commit comments