@@ -26,16 +26,6 @@ public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReade
2626 }
2727 }
2828
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-
3929 internal struct AnimationTriggerMessage : INetworkSerializable
4030 {
4131 public int Hash ;
@@ -49,51 +39,22 @@ public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReade
4939 }
5040
5141 [ SerializeField ] private Animator m_Animator ;
52- [ SerializeField ] private uint m_ParameterSendBits ;
53- [ SerializeField ] private float m_SendRate = 0.1f ;
5442
5543 public Animator Animator
5644 {
5745 get { return m_Animator ; }
5846 set
5947 {
6048 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 ) ) ;
8249 }
8350 }
8451
85- public bool GetParameterAutoSend ( int index )
86- {
87- return ( m_ParameterSendBits & ( uint ) ( 1 << index ) ) != 0 ;
88- }
89-
9052 private bool m_SendMessagesAllowed = false ;
9153
9254 // Animators only support up to 32 params
9355 public static int K_MaxAnimationParams = 32 ;
9456
9557 private int m_TransitionHash ;
96- private double m_NextSendTime = 0.0f ;
9758
9859 private int m_AnimationHash ;
9960 public int AnimationHash { get => m_AnimationHash ; }
@@ -105,7 +66,7 @@ private unsafe struct AnimatorParamCache
10566 public fixed byte Value [ 4 ] ; // this is a max size of 4 bytes
10667 }
10768
108- // 128bytes per Animator
69+ // 128 bytes per Animator
10970 private FastBufferWriter m_ParameterWriter = new FastBufferWriter ( K_MaxAnimationParams * sizeof ( float ) , Allocator . Persistent ) ;
11071 private NativeArray < AnimatorParamCache > m_CachedAnimatorParameters ;
11172
@@ -124,17 +85,6 @@ static AnimationParamEnumWrapper()
12485 }
12586 }
12687
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-
13888 public override void OnDestroy ( )
13989 {
14090 if ( m_CachedAnimatorParameters . IsCreated )
@@ -162,14 +112,17 @@ public override void OnNetworkSpawn()
162112
163113 if ( m_Animator . IsParameterControlledByCurve ( parameter . nameHash ) )
164114 {
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
166117 continue ;
167118 }
168119
169- var cacheParam = new AnimatorParamCache ( ) ;
120+ var cacheParam = new AnimatorParamCache
121+ {
122+ Type = UnsafeUtility . EnumToInt ( parameter . type ) ,
123+ Hash = parameter . nameHash
124+ } ;
170125
171- cacheParam . Type = UnsafeUtility . EnumToInt ( parameter . type ) ;
172- cacheParam . Hash = parameter . nameHash ;
173126 unsafe
174127 {
175128 switch ( parameter . type )
@@ -213,49 +166,24 @@ private void FixedUpdate()
213166 float normalizedTime ;
214167 if ( ! CheckAnimStateChanged ( out stateHash , out normalizedTime ) )
215168 {
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-
220169 return ;
221170 }
222171
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+ } ;
226177
227178 m_ParameterWriter . Seek ( 0 ) ;
228179 m_ParameterWriter . Truncate ( ) ;
229180
230- WriteParameters ( m_ParameterWriter , false ) ;
181+ WriteParameters ( m_ParameterWriter ) ;
231182 animMsg . Parameters = m_ParameterWriter . ToArray ( ) ;
232183
233184 SendAnimStateClientRpc ( animMsg ) ;
234185 }
235186
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-
259187 private bool CheckAnimStateChanged ( out int stateHash , out float normalizedTime )
260188 {
261189 stateHash = 0 ;
@@ -297,20 +225,10 @@ the read side of this function doesn't have similar logic which would cause
297225 there needs to be logic to track which indexes changed in order for there
298226 to be proper value change checking. Will revist in 1.1.0.
299227 */
300- private unsafe bool WriteParameters ( FastBufferWriter writer , bool autoSend )
228+ private unsafe void WriteParameters ( FastBufferWriter writer )
301229 {
302- if ( m_CachedAnimatorParameters == null )
303- {
304- return false ;
305- }
306-
307230 for ( int i = 0 ; i < m_CachedAnimatorParameters . Length ; i ++ )
308231 {
309- if ( autoSend && ! GetParameterAutoSend ( i ) )
310- {
311- continue ;
312- }
313-
314232 ref var cacheValue = ref UnsafeUtility . ArrayElementAsRef < AnimatorParamCache > ( m_CachedAnimatorParameters . GetUnsafePtr ( ) , i ) ;
315233 var hash = cacheValue . Hash ;
316234
@@ -343,24 +261,12 @@ private unsafe bool WriteParameters(FastBufferWriter writer, bool autoSend)
343261 }
344262 }
345263 }
346-
347- // If we do not write any values to the writer then we should not send any data
348- return writer . Length > 0 ;
349264 }
350265
351- private unsafe void ReadParameters ( FastBufferReader reader , bool autoSend )
266+ private unsafe void ReadParameters ( FastBufferReader reader )
352267 {
353- if ( m_CachedAnimatorParameters == null )
354- {
355- return ;
356- }
357-
358268 for ( int i = 0 ; i < m_CachedAnimatorParameters . Length ; i ++ )
359269 {
360- if ( autoSend && ! GetParameterAutoSend ( i ) )
361- {
362- continue ;
363- }
364270 ref var cacheValue = ref UnsafeUtility . ArrayElementAsRef < AnimatorParamCache > ( m_CachedAnimatorParameters . GetUnsafePtr ( ) , i ) ;
365271 var hash = cacheValue . Hash ;
366272
@@ -394,20 +300,6 @@ private unsafe void ReadParameters(FastBufferReader reader, bool autoSend)
394300 }
395301 }
396302
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-
411303 [ ClientRpc ]
412304 private unsafe void SendAnimStateClientRpc ( AnimationMessage animSnapshot , ClientRpcParams clientRpcParams = default )
413305 {
@@ -423,7 +315,7 @@ private unsafe void SendAnimStateClientRpc(AnimationMessage animSnapshot, Client
423315 fixed ( byte * parameters = animSnapshot . Parameters )
424316 {
425317 var reader = new FastBufferReader ( parameters , Allocator . None , animSnapshot . Parameters . Length ) ;
426- ReadParameters ( reader , false ) ;
318+ ReadParameters ( reader ) ;
427319 }
428320 }
429321 }
0 commit comments