From fc22863f570ada2211808cbaf891a444f9b33093 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Thu, 1 Dec 2022 23:30:02 +0300 Subject: [PATCH] Controller Improvements --- IMovementController.cs | 12 ++++++++++++ IMovementControllerExtensions.cs | 4 ++-- MovementController.cs | 18 +++++++++++------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/IMovementController.cs b/IMovementController.cs index 5b18f69..28bf228 100644 --- a/IMovementController.cs +++ b/IMovementController.cs @@ -1,10 +1,16 @@ using System; using System.Collections.Generic; +using Syntriax.Modules.ToggleState; namespace Syntriax.Modules.Movement { public interface IMovementController { + /// + /// Member Toggle State + /// + IToggleState ToggleState { get; } + /// /// Currently active /// @@ -27,6 +33,12 @@ namespace Syntriax.Modules.Movement /// Actived Action OnMovementActivated { get; set; } + /// + /// Called when is called + /// + /// The x, y, z values of + Action OnMoveCalled { get; set; } + /// /// Updates the list /// diff --git a/IMovementControllerExtensions.cs b/IMovementControllerExtensions.cs index 5f10f11..27994e9 100644 --- a/IMovementControllerExtensions.cs +++ b/IMovementControllerExtensions.cs @@ -8,12 +8,12 @@ namespace Syntriax.Modules.Movement /// Calls with a 's values accordingly, leaving the z parameter 0 /// public static void Move(this IMovementController movementController, Vector2 moveVector) - => movementController.ActiveMovement?.Move(moveVector.x, moveVector.y, 0f); + => movementController.Move(moveVector.x, moveVector.y, 0f); /// /// Calls with a 's values accordingly /// public static void Move(this IMovementController movementController, Vector3 moveVector) - => movementController.ActiveMovement?.Move(moveVector.x, moveVector.y, moveVector.z); + => movementController.Move(moveVector.x, moveVector.y, moveVector.z); } } diff --git a/MovementController.cs b/MovementController.cs index 82f77f5..672a140 100644 --- a/MovementController.cs +++ b/MovementController.cs @@ -7,6 +7,8 @@ namespace Syntriax.Modules.Movement { public class MovementController : MonoBehaviour, IMovementController { + public Action OnMoveCalled { get; set; } = null; + public Action OnMovementDeactivated { get; set; } = null; public Action OnMovementActivated { get; set; } = null; @@ -29,12 +31,11 @@ namespace Syntriax.Modules.Movement } } - public List Movements { get; protected set; } = null; + public List Movements { get; protected set; } = new List(32); - protected IToggleState toggleState = null; + public IToggleState ToggleState { get; protected set; } = new ToggleStateMember(true); - protected virtual void Awake() - => Movements = new List(32); + protected IToggleState toggleStateOnGameObject = null; protected virtual void Start() { @@ -42,12 +43,12 @@ namespace Syntriax.Modules.Movement gameObject.AddComponent(); RecacheMovements(); - toggleState = GetComponent(); + toggleStateOnGameObject = GetComponent(); } protected virtual void FixedUpdate() { - if (!toggleState.IsToggledNullChecked()) + if (!ToggleState.IsToggledNullChecked() || !toggleStateOnGameObject.IsToggledNullChecked()) return; ActiveMovement?.ApplyMovement(); @@ -79,6 +80,9 @@ namespace Syntriax.Modules.Movement } public void Move(float x = 0, float y = 0, float z = 0) - => ActiveMovement?.Move(x, y, z); + { + ActiveMovement?.Move(x, y, z); + OnMoveCalled?.Invoke(x, y, z); + } } }