diff --git a/Runtime/Action.cs b/Runtime/Action.cs new file mode 100644 index 0000000..5f48240 --- /dev/null +++ b/Runtime/Action.cs @@ -0,0 +1,29 @@ +using System; +using Syntriax.Modules.State; +using UnityEngine; + +namespace Syntriax.Modules.Action +{ + public class Action : MonoBehaviour, IAction + { + private IStateEnable _stateEnable = null; + public IStateEnable StateEnable + { + get + { + _stateEnable = _stateEnable ?? GetComponent() ?? gameObject.AddComponent(); + return _stateEnable; + } + } + + public Action OnActivated { get; set; } = null; + + public void Activate() + { + if (!StateEnable.IsEnabledNullChecked()) + return; + + OnActivated?.Invoke(this); + } + } +} diff --git a/Runtime/ActionBase.cs.meta b/Runtime/Action.cs.meta similarity index 83% rename from Runtime/ActionBase.cs.meta rename to Runtime/Action.cs.meta index b35e7fd..291f06b 100644 --- a/Runtime/ActionBase.cs.meta +++ b/Runtime/Action.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d07cd6f6a7a635c41add4964a6aba382 +guid: f0778370286865d42a8453967944ab67 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/ActionBase.cs b/Runtime/ActionBase.cs deleted file mode 100644 index 8db49fa..0000000 --- a/Runtime/ActionBase.cs +++ /dev/null @@ -1,31 +0,0 @@ -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 OnActivated { get; set; } = null; - - - protected virtual void Awake() - { - StateEnable = new StateEnableMember(true); - OnActivated += (_) => OnActionActivated(); - } - - /// - /// Called when the current gets activated - /// - protected abstract void OnActionActivated(); - public virtual void Activate() - { - if (!StateEnable.IsEnabledNullChecked()) - return; - - OnActivated?.Invoke(this); - } - } -} diff --git a/Runtime/ActionBaseWithDeactivation.cs b/Runtime/ActionBaseWithDeactivation.cs deleted file mode 100644 index 62e3f10..0000000 --- a/Runtime/ActionBaseWithDeactivation.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using Syntriax.Modules.State; - -namespace Syntriax.Modules.Action -{ - public abstract class ActionBaseWithDeactivation : ActionBase, IActionWithDeactivation - { - public Action OnDeactivated { get; set; } = null; - - protected override void Awake() - { - base.Awake(); - OnDeactivated += (_) => OnActionDeactivated(); - } - - /// - /// Called when the current gets deactivated - /// - protected abstract void OnActionDeactivated(); - public virtual void Deactivate() - { - if (!StateEnable.IsEnabledNullChecked()) - return; - - OnDeactivated?.Invoke(this); - } - } -} diff --git a/Runtime/ActionWithDeactivation.cs b/Runtime/ActionWithDeactivation.cs new file mode 100644 index 0000000..6bc8065 --- /dev/null +++ b/Runtime/ActionWithDeactivation.cs @@ -0,0 +1,18 @@ +using System; +using Syntriax.Modules.State; + +namespace Syntriax.Modules.Action +{ + public class ActionWithDeactivation : Action, IActionWithDeactivation + { + public Action OnDeactivated { get; set; } = null; + + public void Deactivate() + { + if (!StateEnable.IsEnabledNullChecked()) + return; + + OnDeactivated?.Invoke(this); + } + } +} diff --git a/Runtime/ActionBaseWithDeactivation.cs.meta b/Runtime/ActionWithDeactivation.cs.meta similarity index 83% rename from Runtime/ActionBaseWithDeactivation.cs.meta rename to Runtime/ActionWithDeactivation.cs.meta index 043bd8c..1d20728 100644 --- a/Runtime/ActionBaseWithDeactivation.cs.meta +++ b/Runtime/ActionWithDeactivation.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7bce8bd8b35a51f4785a3933e3526ddf +guid: c41fb1050f19d6c479295ba680295261 MonoImporter: externalObjects: {} serializedVersion: 2