From 42c81ada1dee0cd2c6c3642a31a278bcefaa9523 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Mon, 20 Mar 2023 23:46:17 +0300 Subject: [PATCH 1/2] BREAKING CHANGE: State 0.2.0 --- README.md | 2 +- Runtime/ActionBase.cs | 10 ++++------ Runtime/ActionBaseWithDeactivation.cs | 4 ++-- Runtime/IAction.cs | 6 +++--- Samples/PlatformerJump.cs | 21 ++++++++++++--------- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 4503f93..1915f87 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Action ## Dependencies -1. [ToggleState Module](https://git.syntriax.com/Syntriax/ToggleState) +1. [State Module](https://git.syntriax.com/Syntriax/State) Make sure to separately clone these modules along with this one too. diff --git a/Runtime/ActionBase.cs b/Runtime/ActionBase.cs index f4ad3db..8db49fa 100644 --- a/Runtime/ActionBase.cs +++ b/Runtime/ActionBase.cs @@ -1,20 +1,18 @@ using System; -using Syntriax.Modules.ToggleState; +using Syntriax.Modules.State; using UnityEngine; namespace Syntriax.Modules.Action { public abstract class ActionBase : MonoBehaviour, IAction { - public IToggleState MemberToggleState { get; protected set; } = null; + public IStateEnable StateEnable { get; protected set; } = null; public Action OnActivated { get; set; } = null; - protected IToggleState toggleState = null; protected virtual void Awake() { - toggleState = GetComponent(); - MemberToggleState = new ToggleStateMember(true); + StateEnable = new StateEnableMember(true); OnActivated += (_) => OnActionActivated(); } @@ -24,7 +22,7 @@ namespace Syntriax.Modules.Action protected abstract void OnActionActivated(); public virtual void Activate() { - if (!MemberToggleState.IsToggledNullChecked() || !toggleState.IsToggledNullChecked()) + if (!StateEnable.IsEnabledNullChecked()) return; OnActivated?.Invoke(this); diff --git a/Runtime/ActionBaseWithDeactivation.cs b/Runtime/ActionBaseWithDeactivation.cs index 5a0599d..62e3f10 100644 --- a/Runtime/ActionBaseWithDeactivation.cs +++ b/Runtime/ActionBaseWithDeactivation.cs @@ -1,5 +1,5 @@ using System; -using Syntriax.Modules.ToggleState; +using Syntriax.Modules.State; namespace Syntriax.Modules.Action { @@ -19,7 +19,7 @@ namespace Syntriax.Modules.Action protected abstract void OnActionDeactivated(); public virtual void Deactivate() { - if (!MemberToggleState.IsToggledNullChecked() || !toggleState.IsToggledNullChecked()) + if (!StateEnable.IsEnabledNullChecked()) return; OnDeactivated?.Invoke(this); diff --git a/Runtime/IAction.cs b/Runtime/IAction.cs index 6ca81e1..286f6c5 100644 --- a/Runtime/IAction.cs +++ b/Runtime/IAction.cs @@ -1,14 +1,14 @@ using System; -using Syntriax.Modules.ToggleState; +using Syntriax.Modules.State; namespace Syntriax.Modules.Action { public interface IAction { /// - /// The member the Action uses to check if it's active or not + /// The member the Action uses to check if it's active or not /// - IToggleState MemberToggleState { get; } + IStateEnable StateEnable { get; } /// /// Called when the is Activated diff --git a/Samples/PlatformerJump.cs b/Samples/PlatformerJump.cs index 1c663a7..618ad18 100644 --- a/Samples/PlatformerJump.cs +++ b/Samples/PlatformerJump.cs @@ -1,10 +1,10 @@ -using Syntriax.Modules.ToggleState; +using Syntriax.Modules.State; using UnityEngine; namespace Syntriax.Modules.Action.Samples { [RequireComponent(typeof(Rigidbody2D))] - public class PlatformerJump : ActionBaseWithDeactivation + public class PlatformerJump : ActionWithDeactivation { [SerializeField] private float jumpSpeed = 10f; public float JumpSpeed { get => jumpSpeed; set => jumpSpeed = value; } @@ -25,22 +25,25 @@ namespace Syntriax.Modules.Action.Samples set => suspensionMultiplier = value * Time.fixedDeltaTime; } - protected IToggleState gameObjectToggleState = null; + protected IStateEnable gameObjectStateEnable = null; protected bool airSuspension = false; protected Rigidbody2D rigid = null; protected virtual void Start() { rigid = GetComponent(); - gameObjectToggleState = GetComponent(); + gameObjectStateEnable = GetComponent(); FallMultiplier = fallMultiplier; SuspensionMultiplier = suspensionMultiplier; + + OnActivated += _ => OnActionDeactivated(); + OnDeactivated += _ => OnActionActivated(); } protected virtual void FixedUpdate() { - if (!MemberToggleState.IsToggledNullChecked() || !gameObjectToggleState.IsToggledNullChecked()) + if (!StateEnable.IsEnabledNullChecked() || !gameObjectStateEnable.IsEnabledNullChecked()) return; if (rigid.velocity.y < FallThreshold) @@ -59,17 +62,17 @@ namespace Syntriax.Modules.Action.Samples rigid.velocity = velocity; } - protected override void OnActionDeactivated() + protected void OnActionDeactivated() { - if (!gameObjectToggleState.IsToggledNullChecked()) + if (!gameObjectStateEnable.IsEnabledNullChecked()) return; airSuspension = false; } - protected override void OnActionActivated() + protected void OnActionActivated() { - if (!gameObjectToggleState.IsToggledNullChecked()) + if (!gameObjectStateEnable.IsEnabledNullChecked()) return; Jump(); From d45811ea77e887a1845ca31e98b717e86a0cbd49 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Mon, 20 Mar 2023 23:47:15 +0300 Subject: [PATCH 2/2] BREAKING CHANGE: Turned ActionBase and ActionBaseWithDeactivations To Non-Abstract Classes --- Runtime/Action.cs | 29 +++++++++++++++++ .../{ActionBase.cs.meta => Action.cs.meta} | 2 +- Runtime/ActionBase.cs | 31 ------------------- Runtime/ActionBaseWithDeactivation.cs | 28 ----------------- Runtime/ActionWithDeactivation.cs | 18 +++++++++++ ...cs.meta => ActionWithDeactivation.cs.meta} | 2 +- 6 files changed, 49 insertions(+), 61 deletions(-) create mode 100644 Runtime/Action.cs rename Runtime/{ActionBase.cs.meta => Action.cs.meta} (83%) delete mode 100644 Runtime/ActionBase.cs delete mode 100644 Runtime/ActionBaseWithDeactivation.cs create mode 100644 Runtime/ActionWithDeactivation.cs rename Runtime/{ActionBaseWithDeactivation.cs.meta => ActionWithDeactivation.cs.meta} (83%) 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