/// ---------------------------------------------
/// Ultimate Character Controller
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.UltimateCharacterController.Items.Actions.Magic.CastActions
{
using Opsive.UltimateCharacterController.StateSystem;
using Opsive.UltimateCharacterController.Utility;
using UnityEngine;
///
/// The Cast Action class performs the magic cast.
///
[AllowDuplicateTypes]
[UnityEngine.Scripting.Preserve]
[System.Serializable]
public abstract class CastAction : StateObject
{
[Tooltip("The delay to start the cast after the item has been used.")]
[HideInInspector] [SerializeField] protected float m_Delay;
public float Delay { get { return m_Delay; } set { m_Delay = value; } }
public uint CastID { get { return m_CastID; } set { m_CastID = value; } }
protected GameObject m_GameObject;
protected MagicItem m_MagicItem;
protected int m_Index;
protected uint m_CastID;
///
/// Initializes the CastAction.
///
/// The character GameObject.
/// The MagicItem that the CastAction belongs to.
/// The index of the CastAction.
public virtual void Initialize(GameObject character, MagicItem magicItem, int index)
{
base.Initialize(character);
m_GameObject = character;
m_MagicItem = magicItem;
m_Index = index;
}
///
/// Awake is called after all of the actions have been initialized.
///
public virtual void Awake() { }
///
/// Is the specified position a valid target position?
///
/// The position that may be a valid target position.
/// The normal of the position.
/// True if the specified position is a valid target position.
public virtual bool IsValidTargetPosition(Vector3 position, Vector3 normal) { return true; }
///
/// Performs the cast.
///
/// The location that the cast should spawn from.
/// The direction of the cast.
/// The target position of the cast.
public abstract void Cast(Transform origin, Vector3 direction, Vector3 targetPosition);
///
/// The cast will be stopped. Start any cleanup.
///
public virtual void WillStop() { }
///
/// Stops the cast.
///
/// The ID of the cast that should be stopped.
public void Stop(uint castID) { m_CastID = castID; Stop(); }
///
/// Stops the cast.
///
public virtual void Stop() { m_CastID = 0; }
///
/// The character has changed perspectives.
///
/// The location that the cast originates from.
public virtual void OnChangePerspectives(Transform origin) { }
///
/// The action has been destroyed.
///
public virtual void OnDestroy() { }
}
}