/// --------------------------------------------- /// Ultimate Character Controller /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.UltimateCharacterController.Demo.Character.Abilities { using Opsive.Shared.Events; using Opsive.UltimateCharacterController.Character.Abilities; using UnityEngine; /// /// Sets the int data parameter to the specified value when move towards is not active. /// public class IntDataSetter : Ability { [Tooltip("The value to set the int data value to.")] [SerializeField] protected int m_IntDataValue = 1; [Tooltip("Should the ability stop when the Move Towards ability is active?")] [SerializeField] protected bool m_StopWhenMoveTowardsActive = true; public int IntDataValue { get { return m_IntDataValue; } set { m_IntDataValue = value; } } public bool StopWhenMoveTowardsActive { get { return m_StopWhenMoveTowardsActive; } set { m_StopWhenMoveTowardsActive = value; } } public override bool IsConcurrent { get { return true; } } public override int AbilityIntData { get { return m_IntDataValue; } set { m_IntDataValue = value; } } /// /// Initialize the default values. /// public override void Awake() { base.Awake(); EventHandler.RegisterEvent(m_GameObject, "OnCharacterAbilityActive", OnAbilityActive); } /// /// Called when the ablity is tried to be started. If false is returned then the ability will not be started. /// /// True if the ability can be started. public override bool CanStartAbility() { return m_CharacterLocomotion.MoveTowardsAbility == null || !m_CharacterLocomotion.MoveTowardsAbility.IsActive; } /// /// The character's ability has been started or stopped. /// /// The ability which was started or stopped. /// True if the ability was started, false if it was stopped. private void OnAbilityActive(Ability ability, bool active) { if (m_StopWhenMoveTowardsActive && active && ability is MoveTowards) { StopAbility(); } } /// /// The character has been destroyed. /// public override void OnDestroy() { EventHandler.UnregisterEvent(m_GameObject, "OnCharacterAbilityActive", OnAbilityActive); } } }