1
1
using Unity . Collections ;
2
2
using Unity . Collections . LowLevel . Unsafe ;
3
+
3
4
using UnityEngine ;
4
5
5
6
namespace Unity . Netcode . Components
@@ -38,11 +39,12 @@ public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReade
38
39
internal struct AnimationTriggerMessage : INetworkSerializable
39
40
{
40
41
public int Hash ;
42
+ public bool Reset ;
41
43
42
44
public void NetworkSerialize < T > ( BufferSerializer < T > serializer ) where T : IReaderWriter
43
45
{
44
46
serializer . SerializeValue ( ref Hash ) ;
45
-
47
+ serializer . SerializeValue ( ref Reset ) ;
46
48
}
47
49
}
48
50
@@ -286,6 +288,12 @@ private bool CheckAnimStateChanged(out int stateHash, out float normalizedTime)
286
288
return false ;
287
289
}
288
290
291
+ /* $AS TODO: Right now we are not checking for changed values this is because
292
+ the read side of this function doesn't have similar logic which would cause
293
+ an overflow read because it doesn't know if the value is there or not. So
294
+ there needs to be logic to track which indexes changed in order for there
295
+ to be proper value change checking. Will revist in 1.1.0.
296
+ */
289
297
private unsafe bool WriteParameters ( FastBufferWriter writer , bool autoSend )
290
298
{
291
299
if ( m_CachedAnimatorParameters == null )
@@ -308,39 +316,27 @@ private unsafe bool WriteParameters(FastBufferWriter writer, bool autoSend)
308
316
var valueInt = m_Animator . GetInteger ( hash ) ;
309
317
fixed ( void * value = cacheValue . Value )
310
318
{
311
- var oldValue = UnsafeUtility . AsRef < int > ( value ) ;
312
- if ( valueInt != oldValue )
313
- {
314
- UnsafeUtility . WriteArrayElement ( value , 0 , valueInt ) ;
315
- BytePacker . WriteValuePacked ( writer , ( uint ) valueInt ) ;
316
- }
319
+ UnsafeUtility . WriteArrayElement ( value , 0 , valueInt ) ;
320
+ BytePacker . WriteValuePacked ( writer , ( uint ) valueInt ) ;
317
321
}
318
322
}
319
323
else if ( cacheValue . Type == AnimationParamEnumWrapper . AnimatorControllerParameterBool )
320
324
{
321
325
var valueBool = m_Animator . GetBool ( hash ) ;
322
326
fixed ( void * value = cacheValue . Value )
323
327
{
324
- var oldValue = UnsafeUtility . AsRef < bool > ( value ) ;
325
- if ( valueBool != oldValue )
326
- {
327
- UnsafeUtility . WriteArrayElement ( value , 0 , valueBool ) ;
328
- writer . WriteValueSafe ( valueBool ) ;
329
- }
328
+ UnsafeUtility . WriteArrayElement ( value , 0 , valueBool ) ;
329
+ writer . WriteValueSafe ( valueBool ) ;
330
330
}
331
331
}
332
332
else if ( cacheValue . Type == AnimationParamEnumWrapper . AnimatorControllerParameterFloat )
333
333
{
334
334
var valueFloat = m_Animator . GetFloat ( hash ) ;
335
335
fixed ( void * value = cacheValue . Value )
336
336
{
337
- var oldValue = UnsafeUtility . AsRef < float > ( value ) ;
338
- if ( valueFloat != oldValue )
339
- {
340
- UnsafeUtility . WriteArrayElement ( value , 0 , valueFloat ) ;
341
337
342
- writer . WriteValueSafe ( valueFloat ) ;
343
- }
338
+ UnsafeUtility . WriteArrayElement ( value , 0 , valueFloat ) ;
339
+ writer . WriteValueSafe ( valueFloat ) ;
344
340
}
345
341
}
346
342
}
@@ -432,23 +428,41 @@ private unsafe void SendAnimStateClientRpc(AnimationMessage animSnapshot, Client
432
428
[ ClientRpc ]
433
429
private void SendAnimTriggerClientRpc ( AnimationTriggerMessage animSnapshot , ClientRpcParams clientRpcParams = default )
434
430
{
435
- m_Animator . SetTrigger ( animSnapshot . Hash ) ;
431
+ if ( animSnapshot . Reset )
432
+ {
433
+ m_Animator . ResetTrigger ( animSnapshot . Hash ) ;
434
+ }
435
+ else
436
+ {
437
+ m_Animator . SetTrigger ( animSnapshot . Hash ) ;
438
+ }
436
439
}
437
440
438
441
public void SetTrigger ( string triggerName )
439
442
{
440
443
SetTrigger ( Animator . StringToHash ( triggerName ) ) ;
441
444
}
442
445
443
- public void SetTrigger ( int hash )
446
+ public void SetTrigger ( int hash , bool reset = false )
444
447
{
445
448
var animMsg = new AnimationTriggerMessage ( ) ;
446
449
animMsg . Hash = hash ;
450
+ animMsg . Reset = reset ;
447
451
448
452
if ( IsServer )
449
453
{
450
454
SendAnimTriggerClientRpc ( animMsg ) ;
451
455
}
452
456
}
457
+
458
+ public void ResetTrigger ( string triggerName )
459
+ {
460
+ ResetTrigger ( Animator . StringToHash ( triggerName ) ) ;
461
+ }
462
+
463
+ public void ResetTrigger ( int hash )
464
+ {
465
+ SetTrigger ( hash , true ) ;
466
+ }
453
467
}
454
468
}
0 commit comments