/// --------------------------------------------- /// Ultimate Character Controller /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.UltimateCharacterController.Character.Abilities { using Opsive.Shared.Events; using Opsive.Shared.Game; using Opsive.UltimateCharacterController.Utility; using UnityEngine; /// /// Plays a full body animation in response to a melee counter attack. /// [DefaultStartType(AbilityStartType.Manual)] [DefaultStopType(AbilityStopType.Manual)] [DefaultUseRootMotionPosition(AbilityBoolOverride.True)] [DefaultAbilityIndex(13)] public class MeleeCounterAttackResponse : Ability { [Tooltip("Specifies if the ability should stop when the OnAnimatorMeleeCounterAttackResponseComplete event is received or wait the specified amount of time before ending the ability.")] [SerializeField] protected AnimationEventTrigger m_StopEvent = new AnimationEventTrigger(true, 0.2f); public AnimationEventTrigger StopEvent { get { return m_StopEvent; } set { m_StopEvent = value; } } private int m_ResponseID; public override int AbilityIntData { get { return m_ResponseID; } } /// /// Initialize the default values. /// public override void Awake() { base.Awake(); EventHandler.RegisterEvent(m_GameObject, "OnAnimatorMeleeCounterAttackResponseComplete", OnComplete); } /// /// The character has been counter attacked. Play a response animation. /// /// The ID of the counter attack. public void StartResponse(int id) { m_ResponseID = id; StartAbility(); } /// /// The ability has started. /// protected override void AbilityStarted() { base.AbilityStarted(); if (!m_StopEvent.WaitForAnimationEvent) { Scheduler.ScheduleFixed(m_StopEvent.Duration, OnComplete); } } /// /// Called when another ability is attempting to start and the current ability is active. /// Returns true or false depending on if the new ability should be blocked from starting. /// /// The ability that is starting. /// True if the ability should be blocked. public override bool ShouldBlockAbilityStart(Ability startingAbility) { return true; } /// /// Called when the current ability is attempting to start and another ability is active. /// Returns true or false depending on if the active ability should be stopped. /// /// The ability that is currently active. /// True if the ability should be stopped. public override bool ShouldStopActiveAbility(Ability activeAbility) { if (activeAbility is Items.Use) { return true; } return base.ShouldStopActiveAbility(activeAbility); } /// /// The animation is done playing - stop the ability. /// private void OnComplete() { StopAbility(); } /// /// The object has been destroyed. /// public override void OnDestroy() { base.OnDestroy(); EventHandler.UnregisterEvent(m_GameObject, "OnAnimatorMeleeCounterAttackResponseComplete", OnComplete); } } }