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
12
12
/// The channel to send changes on.
13
13
/// </summary>
14
14
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 ;
15
22
}
16
23
}
Original file line number Diff line number Diff line change @@ -11,19 +11,25 @@ internal class SyncedVarContainer
11
11
internal object fieldInstance ;
12
12
internal object value ;
13
13
internal bool isDirty ;
14
+ internal float lastSyncedTime ;
14
15
15
16
internal bool IsDirty ( )
16
17
{
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 ) ) )
21
19
{
22
- isDirty = true ;
20
+ lastSyncedTime = NetworkingManager . Singleton . NetworkTime ;
21
+
22
+ object newValue = field . GetValue ( fieldInstance ) ;
23
+ object oldValue = value ;
23
24
24
- value = newValue ;
25
+ if ( newValue != oldValue || isDirty )
26
+ {
27
+ isDirty = true ;
25
28
26
- return true ;
29
+ value = newValue ;
30
+
31
+ return true ;
32
+ }
27
33
}
28
34
29
35
return false ;
You can’t perform that action at this time.
0 commit comments