FlinchState.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
  3. using UnityEngine;
  4. namespace Animancer.Samples.StateMachines
  5. {
  6. /// <summary>A <see cref="CharacterState"/> which activates itself when the character takes damage.</summary>
  7. ///
  8. /// <remarks>
  9. /// <strong>Sample:</strong>
  10. /// <see href="https://kybernetik.com.au/animancer/docs/samples/fsm/interruptions">
  11. /// Interruptions</see>
  12. /// </remarks>
  13. ///
  14. /// https://kybernetik.com.au/animancer/api/Animancer.Samples.StateMachines/FlinchState
  15. ///
  16. [AddComponentMenu(Strings.SamplesMenuPrefix + "Interruptions - Flinch State")]
  17. [AnimancerHelpUrl(typeof(FlinchState))]
  18. public class FlinchState : CharacterState
  19. {
  20. /************************************************************************************************************************/
  21. [SerializeField] private TransitionAsset _Animation;
  22. /************************************************************************************************************************/
  23. protected virtual void Awake()
  24. {
  25. Character.Health.OnHitReceived += () => Character.StateMachine.TryResetState(this);
  26. }
  27. /************************************************************************************************************************/
  28. protected virtual void OnEnable()
  29. {
  30. AnimancerState state = Character.Animancer.Play(_Animation);
  31. state.Events(this).OnEnd ??= Character.StateMachine.ForceSetDefaultState;
  32. }
  33. /************************************************************************************************************************/
  34. public override CharacterStatePriority Priority => CharacterStatePriority.High;
  35. public override bool CanInterruptSelf => true;
  36. /************************************************************************************************************************/
  37. }
  38. }