Action/Runtime/ActionBase.cs

32 lines
835 B
C#

using System;
using Syntriax.Modules.State;
using UnityEngine;
namespace Syntriax.Modules.Action
{
public abstract class ActionBase : MonoBehaviour, IAction
{
public IStateEnable StateEnable { get; protected set; } = null;
public Action<IAction> OnActivated { get; set; } = null;
protected virtual void Awake()
{
StateEnable = new StateEnableMember(true);
OnActivated += (_) => OnActionActivated();
}
/// <summary>
/// Called when the current <see cref="ActionBase"/> gets activated
/// </summary>
protected abstract void OnActionActivated();
public virtual void Activate()
{
if (!StateEnable.IsEnabledNullChecked())
return;
OnActivated?.Invoke(this);
}
}
}