2022-11-20 21:56:53 +03:00
|
|
|
using System;
|
2022-11-20 18:45:36 +03:00
|
|
|
using Syntriax.Modules.ToggleState;
|
|
|
|
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
|
|
|
{
|
|
|
|
public IToggleState ToggleState { 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-11-20 21:56:53 +03:00
|
|
|
protected virtual void Awake()
|
|
|
|
{
|
|
|
|
ToggleState = new ToggleStateMember(true);
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
if (!ToggleState.IsToggledNullChecked())
|
|
|
|
return;
|
|
|
|
|
2022-11-20 21:56:53 +03:00
|
|
|
OnActivated?.Invoke(this);
|
2022-11-20 18:45:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|