2022-11-20 21:56:53 +03:00
|
|
|
using System;
|
2023-03-20 23:46:17 +03:00
|
|
|
using Syntriax.Modules.State;
|
2022-11-20 18:45:36 +03:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace Syntriax.Modules.Action
|
|
|
|
{
|
2022-11-20 21:56:53 +03:00
|
|
|
public abstract class ActionBase : MonoBehaviour, IAction
|
2022-11-20 18:45:36 +03:00
|
|
|
{
|
2023-03-20 23:46:17 +03:00
|
|
|
public IStateEnable StateEnable { get; protected set; } = null;
|
2022-11-20 21:56:53 +03:00
|
|
|
public Action<IAction> OnActivated { get; set; } = null;
|
2022-11-20 18:45:36 +03:00
|
|
|
|
2022-12-16 23:24:02 +03:00
|
|
|
|
2022-11-20 21:56:53 +03:00
|
|
|
protected virtual void Awake()
|
|
|
|
{
|
2023-03-20 23:46:17 +03:00
|
|
|
StateEnable = new StateEnableMember(true);
|
2022-11-20 21:56:53 +03:00
|
|
|
OnActivated += (_) => OnActionActivated();
|
|
|
|
}
|
2022-11-20 18:45:36 +03:00
|
|
|
|
2022-11-20 21:56:53 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Called when the current <see cref="ActionBase"/> gets activated
|
|
|
|
/// </summary>
|
|
|
|
protected abstract void OnActionActivated();
|
2022-11-20 18:45:36 +03:00
|
|
|
public virtual void Activate()
|
|
|
|
{
|
2023-03-20 23:46:17 +03:00
|
|
|
if (!StateEnable.IsEnabledNullChecked())
|
2022-11-20 18:45:36 +03:00
|
|
|
return;
|
|
|
|
|
2022-11-20 21:56:53 +03:00
|
|
|
OnActivated?.Invoke(this);
|
2022-11-20 18:45:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|