// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //

#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.

using UnityEngine;

namespace Animancer.Samples.StateMachines
{
    /// <summary>A <see cref="CharacterState"/> which activates itself when the character takes damage.</summary>
    /// 
    /// <remarks>
    /// <strong>Sample:</strong>
    /// <see href="https://kybernetik.com.au/animancer/docs/samples/fsm/interruptions">
    /// Interruptions</see>
    /// </remarks>
    /// 
    /// https://kybernetik.com.au/animancer/api/Animancer.Samples.StateMachines/FlinchState
    /// 
    [AddComponentMenu(Strings.SamplesMenuPrefix + "Interruptions - Flinch State")]
    [AnimancerHelpUrl(typeof(FlinchState))]
    public class FlinchState : CharacterState
    {
        /************************************************************************************************************************/

        [SerializeField] private ClipTransition _Animation;

        /************************************************************************************************************************/

        protected virtual void Awake()
        {
            _Animation.Events.OnEnd = Character.StateMachine.ForceSetDefaultState;

            Character.Health.OnHitReceived += () => Character.StateMachine.TryResetState(this);
        }

        /************************************************************************************************************************/

        protected virtual void OnEnable()
        {
            Character.Animancer.Play(_Animation);
        }

        /************************************************************************************************************************/

        public override CharacterStatePriority Priority => CharacterStatePriority.High;

        public override bool CanInterruptSelf => true;

        /************************************************************************************************************************/
    }
}
