@@ -26,16 +26,6 @@ public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReade
26
26
}
27
27
}
28
28
29
- internal struct AnimationParametersMessage : INetworkSerializable
30
- {
31
- public byte [ ] Parameters ;
32
-
33
- public void NetworkSerialize < T > ( BufferSerializer < T > serializer ) where T : IReaderWriter
34
- {
35
- serializer . SerializeValue ( ref Parameters ) ;
36
- }
37
- }
38
-
39
29
internal struct AnimationTriggerMessage : INetworkSerializable
40
30
{
41
31
public int Hash ;
@@ -49,51 +39,22 @@ public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReade
49
39
}
50
40
51
41
[ SerializeField ] private Animator m_Animator ;
52
- [ SerializeField ] private uint m_ParameterSendBits ;
53
- [ SerializeField ] private float m_SendRate = 0.1f ;
54
42
55
43
public Animator Animator
56
44
{
57
45
get { return m_Animator ; }
58
46
set
59
47
{
60
48
m_Animator = value ;
61
- ResetParameterOptions ( ) ;
62
- }
63
- }
64
-
65
- /*
66
- * AutoSend is the ability to select which parameters linked to this animator
67
- * get replicated on a regular basis regardless of a state change. The thinking
68
- * behind this is that many of the parameters people use are usually booleans
69
- * which result in a state change and thus would cause a full sync of state.
70
- * Thus if you really care about a parameter syncing then you need to be explicit
71
- * by selecting it in the inspector when an NetworkAnimator is selected.
72
- */
73
- public void SetParameterAutoSend ( int index , bool value )
74
- {
75
- if ( value )
76
- {
77
- m_ParameterSendBits |= ( uint ) ( 1 << index ) ;
78
- }
79
- else
80
- {
81
- m_ParameterSendBits &= ( uint ) ( ~ ( 1 << index ) ) ;
82
49
}
83
50
}
84
51
85
- public bool GetParameterAutoSend ( int index )
86
- {
87
- return ( m_ParameterSendBits & ( uint ) ( 1 << index ) ) != 0 ;
88
- }
89
-
90
52
private bool m_SendMessagesAllowed = false ;
91
53
92
54
// Animators only support up to 32 params
93
55
public static int K_MaxAnimationParams = 32 ;
94
56
95
57
private int m_TransitionHash ;
96
- private double m_NextSendTime = 0.0f ;
97
58
98
59
private int m_AnimationHash ;
99
60
public int AnimationHash { get => m_AnimationHash ; }
@@ -105,7 +66,7 @@ private unsafe struct AnimatorParamCache
105
66
public fixed byte Value [ 4 ] ; // this is a max size of 4 bytes
106
67
}
107
68
108
- // 128bytes per Animator
69
+ // 128 bytes per Animator
109
70
private FastBufferWriter m_ParameterWriter = new FastBufferWriter ( K_MaxAnimationParams * sizeof ( float ) , Allocator . Persistent ) ;
110
71
private NativeArray < AnimatorParamCache > m_CachedAnimatorParameters ;
111
72
@@ -124,17 +85,6 @@ static AnimationParamEnumWrapper()
124
85
}
125
86
}
126
87
127
- internal void ResetParameterOptions ( )
128
- {
129
-
130
- if ( NetworkLog . CurrentLogLevel <= LogLevel . Developer )
131
- {
132
- NetworkLog . LogInfoServer ( "ResetParameterOptions" ) ;
133
- }
134
-
135
- m_ParameterSendBits = 0 ;
136
- }
137
-
138
88
public override void OnDestroy ( )
139
89
{
140
90
if ( m_CachedAnimatorParameters . IsCreated )
@@ -162,14 +112,17 @@ public override void OnNetworkSpawn()
162
112
163
113
if ( m_Animator . IsParameterControlledByCurve ( parameter . nameHash ) )
164
114
{
165
- //we are ignoring parameters that are controlled by animation curves - syncing the layer states indirectly syncs the values that are driven by the animation curves
115
+ // we are ignoring parameters that are controlled by animation curves - syncing the layer
116
+ // states indirectly syncs the values that are driven by the animation curves
166
117
continue ;
167
118
}
168
119
169
- var cacheParam = new AnimatorParamCache ( ) ;
120
+ var cacheParam = new AnimatorParamCache
121
+ {
122
+ Type = UnsafeUtility . EnumToInt ( parameter . type ) ,
123
+ Hash = parameter . nameHash
124
+ } ;
170
125
171
- cacheParam . Type = UnsafeUtility . EnumToInt ( parameter . type ) ;
172
- cacheParam . Hash = parameter . nameHash ;
173
126
unsafe
174
127
{
175
128
switch ( parameter . type )
@@ -213,49 +166,24 @@ private void FixedUpdate()
213
166
float normalizedTime ;
214
167
if ( ! CheckAnimStateChanged ( out stateHash , out normalizedTime ) )
215
168
{
216
- // We only want to check and send if we don't have any other state to since
217
- // as we will sync all params as part of the state sync
218
- CheckAndSend ( ) ;
219
-
220
169
return ;
221
170
}
222
171
223
- var animMsg = new AnimationMessage ( ) ;
224
- animMsg . StateHash = stateHash ;
225
- animMsg . NormalizedTime = normalizedTime ;
172
+ var animMsg = new AnimationMessage
173
+ {
174
+ StateHash = stateHash ,
175
+ NormalizedTime = normalizedTime
176
+ } ;
226
177
227
178
m_ParameterWriter . Seek ( 0 ) ;
228
179
m_ParameterWriter . Truncate ( ) ;
229
180
230
- WriteParameters ( m_ParameterWriter , false ) ;
181
+ WriteParameters ( m_ParameterWriter ) ;
231
182
animMsg . Parameters = m_ParameterWriter . ToArray ( ) ;
232
183
233
184
SendAnimStateClientRpc ( animMsg ) ;
234
185
}
235
186
236
- private void CheckAndSend ( )
237
- {
238
- var networkTime = NetworkManager . ServerTime . Time ;
239
- if ( m_SendMessagesAllowed && m_SendRate != 0 && m_NextSendTime < networkTime )
240
- {
241
- m_NextSendTime = networkTime + m_SendRate ;
242
-
243
- m_ParameterWriter . Seek ( 0 ) ;
244
- m_ParameterWriter . Truncate ( ) ;
245
-
246
- if ( WriteParameters ( m_ParameterWriter , true ) )
247
- {
248
- // we then sync the params we care about
249
- var animMsg = new AnimationParametersMessage ( )
250
- {
251
- Parameters = m_ParameterWriter . ToArray ( )
252
- } ;
253
-
254
- SendParamsClientRpc ( animMsg ) ;
255
- }
256
- }
257
- }
258
-
259
187
private bool CheckAnimStateChanged ( out int stateHash , out float normalizedTime )
260
188
{
261
189
stateHash = 0 ;
@@ -297,20 +225,10 @@ the read side of this function doesn't have similar logic which would cause
297
225
there needs to be logic to track which indexes changed in order for there
298
226
to be proper value change checking. Will revist in 1.1.0.
299
227
*/
300
- private unsafe bool WriteParameters ( FastBufferWriter writer , bool autoSend )
228
+ private unsafe void WriteParameters ( FastBufferWriter writer )
301
229
{
302
- if ( m_CachedAnimatorParameters == null )
303
- {
304
- return false ;
305
- }
306
-
307
230
for ( int i = 0 ; i < m_CachedAnimatorParameters . Length ; i ++ )
308
231
{
309
- if ( autoSend && ! GetParameterAutoSend ( i ) )
310
- {
311
- continue ;
312
- }
313
-
314
232
ref var cacheValue = ref UnsafeUtility . ArrayElementAsRef < AnimatorParamCache > ( m_CachedAnimatorParameters . GetUnsafePtr ( ) , i ) ;
315
233
var hash = cacheValue . Hash ;
316
234
@@ -343,24 +261,12 @@ private unsafe bool WriteParameters(FastBufferWriter writer, bool autoSend)
343
261
}
344
262
}
345
263
}
346
-
347
- // If we do not write any values to the writer then we should not send any data
348
- return writer . Length > 0 ;
349
264
}
350
265
351
- private unsafe void ReadParameters ( FastBufferReader reader , bool autoSend )
266
+ private unsafe void ReadParameters ( FastBufferReader reader )
352
267
{
353
- if ( m_CachedAnimatorParameters == null )
354
- {
355
- return ;
356
- }
357
-
358
268
for ( int i = 0 ; i < m_CachedAnimatorParameters . Length ; i ++ )
359
269
{
360
- if ( autoSend && ! GetParameterAutoSend ( i ) )
361
- {
362
- continue ;
363
- }
364
270
ref var cacheValue = ref UnsafeUtility . ArrayElementAsRef < AnimatorParamCache > ( m_CachedAnimatorParameters . GetUnsafePtr ( ) , i ) ;
365
271
var hash = cacheValue . Hash ;
366
272
@@ -394,20 +300,6 @@ private unsafe void ReadParameters(FastBufferReader reader, bool autoSend)
394
300
}
395
301
}
396
302
397
- [ ClientRpc ]
398
- private unsafe void SendParamsClientRpc ( AnimationParametersMessage animSnapshot , ClientRpcParams clientRpcParams = default )
399
- {
400
- if ( animSnapshot . Parameters != null )
401
- {
402
- // We use a fixed value here to avoid the copy of data from the byte buffer since we own the data
403
- fixed ( byte * parameters = animSnapshot . Parameters )
404
- {
405
- var reader = new FastBufferReader ( parameters , Allocator . None , animSnapshot . Parameters . Length ) ;
406
- ReadParameters ( reader , true ) ;
407
- }
408
- }
409
- }
410
-
411
303
[ ClientRpc ]
412
304
private unsafe void SendAnimStateClientRpc ( AnimationMessage animSnapshot , ClientRpcParams clientRpcParams = default )
413
305
{
@@ -423,7 +315,7 @@ private unsafe void SendAnimStateClientRpc(AnimationMessage animSnapshot, Client
423
315
fixed ( byte * parameters = animSnapshot . Parameters )
424
316
{
425
317
var reader = new FastBufferReader ( parameters , Allocator . None , animSnapshot . Parameters . Length ) ;
426
- ReadParameters ( reader , false ) ;
318
+ ReadParameters ( reader ) ;
427
319
}
428
320
}
429
321
}
0 commit comments