Action/ActionBaseWithDeactivation.cs

29 lines
764 B
C#
Raw Normal View History

2022-11-20 21:56:53 +03:00
using System;
2022-11-20 18:45:36 +03:00
using Syntriax.Modules.ToggleState;
namespace Syntriax.Modules.Action
{
2022-11-20 21:56:53 +03:00
public abstract class ActionBaseWithDeactivation : ActionBase, IActionWithDeactivation
2022-11-20 18:45:36 +03:00
{
2022-11-20 21:56:53 +03:00
public Action<IAction> OnDeactivated { get; set; } = null;
protected override void Awake()
{
base.Awake();
OnDeactivated += (_) => OnActionDeactivated();
}
/// <summary>
/// Called when the current <see cref="ActionBase"/> gets deactivated
/// </summary>
protected abstract void OnActionDeactivated();
2022-11-20 18:45:36 +03:00
public virtual void Deactivate()
{
if (!ToggleState.IsToggledNullChecked())
return;
2022-11-20 21:56:53 +03:00
OnDeactivated?.Invoke(this);
2022-11-20 18:45:36 +03:00
}
}
}