From 2f16d0d334e43c1895de8a5d834d9a69c9892dcd Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sun, 20 Nov 2022 21:56:53 +0300 Subject: [PATCH] Renaming --- ActionBase.cs | 17 +++++++++---- ActionBaseWithDeactivation.cs | 18 +++++++++++--- Actions/PlatformerJump.cs | 4 ++-- IAction.cs | 24 +++++++++++++++++++ IActionActivate.cs.meta => IAction.cs.meta | 2 +- IActionActivate.cs | 17 ------------- IActionDeactivate.cs | 10 -------- IActionWithDeactivation.cs | 18 ++++++++++++++ ...cs.meta => IActionWithDeactivation.cs.meta | 2 +- 9 files changed, 74 insertions(+), 38 deletions(-) create mode 100644 IAction.cs rename IActionActivate.cs.meta => IAction.cs.meta (83%) delete mode 100644 IActionActivate.cs delete mode 100644 IActionDeactivate.cs create mode 100644 IActionWithDeactivation.cs rename IActionDeactivate.cs.meta => IActionWithDeactivation.cs.meta (83%) diff --git a/ActionBase.cs b/ActionBase.cs index 0d0f46d..c55c30e 100644 --- a/ActionBase.cs +++ b/ActionBase.cs @@ -1,21 +1,30 @@ +using System; using Syntriax.Modules.ToggleState; using UnityEngine; namespace Syntriax.Modules.Action { - public abstract class ActionBase : MonoBehaviour, IActionActivate + public abstract class ActionBase : MonoBehaviour, IAction { public IToggleState ToggleState { get; protected set; } = null; + public Action OnActivated { get; set; } = null; - protected virtual void Awake() => ToggleState = new ToggleStateMember(true); + protected virtual void Awake() + { + ToggleState = new ToggleStateMember(true); + OnActivated += (_) => OnActionActivated(); + } - protected abstract void OnActivated(); + /// + /// Called when the current gets activated + /// + protected abstract void OnActionActivated(); public virtual void Activate() { if (!ToggleState.IsToggledNullChecked()) return; - OnActivated(); + OnActivated?.Invoke(this); } } } diff --git a/ActionBaseWithDeactivation.cs b/ActionBaseWithDeactivation.cs index 52a72f6..bb4a0cf 100644 --- a/ActionBaseWithDeactivation.cs +++ b/ActionBaseWithDeactivation.cs @@ -1,16 +1,28 @@ +using System; using Syntriax.Modules.ToggleState; namespace Syntriax.Modules.Action { - public abstract class ActionBaseWithDeactivation : ActionBase, IActionDeactivate + public abstract class ActionBaseWithDeactivation : ActionBase, IActionWithDeactivation { - protected abstract void OnDeactivated(); + 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 (!ToggleState.IsToggledNullChecked()) return; - OnDeactivated(); + OnDeactivated?.Invoke(this); } } } diff --git a/Actions/PlatformerJump.cs b/Actions/PlatformerJump.cs index dcdfe36..8a754a7 100644 --- a/Actions/PlatformerJump.cs +++ b/Actions/PlatformerJump.cs @@ -59,7 +59,7 @@ namespace Syntriax.Modules.Action rigid.velocity = velocity; } - protected override void OnDeactivated() + protected override void OnActionDeactivated() { if (!gameObjectToggleState.IsToggledNullChecked()) return; @@ -67,7 +67,7 @@ namespace Syntriax.Modules.Action airSuspension = false; } - protected override void OnActivated() + protected override void OnActionActivated() { if (!gameObjectToggleState.IsToggledNullChecked()) return; diff --git a/IAction.cs b/IAction.cs new file mode 100644 index 0000000..ef42565 --- /dev/null +++ b/IAction.cs @@ -0,0 +1,24 @@ +using System; +using Syntriax.Modules.ToggleState; + +namespace Syntriax.Modules.Action +{ + public interface IAction + { + /// + /// The the Action uses to check if it's active or not + /// + IToggleState ToggleState { get; } + + /// + /// Called when the is Activated + /// + /// The that Activated + Action OnActivated { get; set; } + + /// + /// Triggers the + /// + void Activate(); + } +} diff --git a/IActionActivate.cs.meta b/IAction.cs.meta similarity index 83% rename from IActionActivate.cs.meta rename to IAction.cs.meta index 9d7d8d9..70c5837 100644 --- a/IActionActivate.cs.meta +++ b/IAction.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9ff9f1a7b70a47e4aa97dfda371fbf21 +guid: 4f1eb00830f616b40afd45bec1425a7f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/IActionActivate.cs b/IActionActivate.cs deleted file mode 100644 index c0ef462..0000000 --- a/IActionActivate.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Syntriax.Modules.ToggleState; - -namespace Syntriax.Modules.Action -{ - public interface IActionActivate - { - /// - /// The the Action uses to check if it's active or not - /// - IToggleState ToggleState { get; } - - /// - /// Triggers the Action - /// - void Activate(); - } -} diff --git a/IActionDeactivate.cs b/IActionDeactivate.cs deleted file mode 100644 index 5073316..0000000 --- a/IActionDeactivate.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Syntriax.Modules.Action -{ - public interface IActionDeactivate : IActionActivate - { - /// - /// Deactivates the action - /// - void Deactivate(); - } -} diff --git a/IActionWithDeactivation.cs b/IActionWithDeactivation.cs new file mode 100644 index 0000000..6b61018 --- /dev/null +++ b/IActionWithDeactivation.cs @@ -0,0 +1,18 @@ +using System; + +namespace Syntriax.Modules.Action +{ + public interface IActionWithDeactivation : IAction + { + /// + /// Called when the is Deactivated + /// + /// The that Deactivated + Action OnDeactivated { get; set; } + + /// + /// Called when the is Deactivated + /// + void Deactivate(); + } +} diff --git a/IActionDeactivate.cs.meta b/IActionWithDeactivation.cs.meta similarity index 83% rename from IActionDeactivate.cs.meta rename to IActionWithDeactivation.cs.meta index 54b93ac..e1fbd6b 100644 --- a/IActionDeactivate.cs.meta +++ b/IActionWithDeactivation.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 10a30eb2debabdf40b2f8120a5f1ad01 +guid: eaf437843a281c74c86f7db482b44077 MonoImporter: externalObjects: {} serializedVersion: 2