diff --git a/Implementations.meta b/Bases.meta similarity index 77% rename from Implementations.meta rename to Bases.meta index c14cbc9..310b719 100644 --- a/Implementations.meta +++ b/Bases.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 15528ebd51d27d54398c55826710f23e +guid: feeeff74b53207d469a4fc708c0bdd34 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Implementations/2D/TwoDimensionalMovementBase.cs b/Bases/MovementBase.cs similarity index 85% rename from Implementations/2D/TwoDimensionalMovementBase.cs rename to Bases/MovementBase.cs index 1a5c407..6dea418 100644 --- a/Implementations/2D/TwoDimensionalMovementBase.cs +++ b/Bases/MovementBase.cs @@ -2,12 +2,10 @@ using System; using Syntriax.Modules.Movement.State; using UnityEngine; -namespace Syntriax.Modules.Movement.Implementations.TwoDimensional +namespace Syntriax.Modules.Movement { - [RequireComponent(typeof(Rigidbody2D))] - public abstract class TwoDimensionalMovementBase : MonoBehaviour, IMovement + public abstract class MovementBase : MonoBehaviour, IMovement { - protected Rigidbody2D rigid = null; protected IToggleState toggleState = null; protected IMovementController movementController = null; private bool _canTakeOver = false; @@ -31,34 +29,33 @@ namespace Syntriax.Modules.Movement.Implementations.TwoDimensional } public IToggleState ToggleState { get; protected set; } = null; + public abstract void ApplyMovement(); + + public abstract void Move(float x = 0, float y = 0, float z = 0); + + protected abstract void OnActivated(); + + protected abstract void OnDeactivated(); protected virtual void Start() { - rigid = GetComponent(); toggleState = GetComponent(); movementController = GetComponent(); movementController.OnMovementActivated += OnActivated; movementController.OnMovementDeactivated += OnDeactivated; } - - protected abstract void OnDeactivated(); - private void OnDeactivated(IMovement movement) - { - if ((object)movement != this) - return; - OnDeactivated(); - } - - protected abstract void OnActivated(); private void OnActivated(IMovement movement) { if ((object)movement != this) return; OnActivated(); } - - public abstract void Move(float x = 0, float y = 0, float z = 0); - public abstract void ApplyMovement(); + private void OnDeactivated(IMovement movement) + { + if ((object)movement != this) + return; + OnDeactivated(); + } } } diff --git a/Implementations/2D/OneDirectional2DMovementBase.cs.meta b/Bases/MovementBase.cs.meta similarity index 83% rename from Implementations/2D/OneDirectional2DMovementBase.cs.meta rename to Bases/MovementBase.cs.meta index 24940ac..f439935 100644 --- a/Implementations/2D/OneDirectional2DMovementBase.cs.meta +++ b/Bases/MovementBase.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 51ee606e68723324b92b9d16835c1625 +guid: d471aae4aaf4636459646d73603689e0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Implementations/2D/OneDirectional2DMovementBase.cs b/Bases/MovementBase1D.cs similarity index 58% rename from Implementations/2D/OneDirectional2DMovementBase.cs rename to Bases/MovementBase1D.cs index 3af4d9a..e0a3975 100644 --- a/Implementations/2D/OneDirectional2DMovementBase.cs +++ b/Bases/MovementBase1D.cs @@ -1,6 +1,6 @@ -namespace Syntriax.Modules.Movement.Implementations.TwoDimensional +namespace Syntriax.Modules.Movement { - public abstract class OneDirectional2DMovementBase : TwoDimensionalMovementBase + public abstract class MovementBase1D : MovementBase { protected abstract float moveValue { get; set; } diff --git a/Implementations/2D/TwoDimensionalMovementBase.cs.meta b/Bases/MovementBase1D.cs.meta similarity index 83% rename from Implementations/2D/TwoDimensionalMovementBase.cs.meta rename to Bases/MovementBase1D.cs.meta index 8c1b357..17234be 100644 --- a/Implementations/2D/TwoDimensionalMovementBase.cs.meta +++ b/Bases/MovementBase1D.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b4a8f74afcbe280448862bac89545353 +guid: 938515a22b53ad6468e4152f1328b6ce MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Bases/MovementBase2D.cs b/Bases/MovementBase2D.cs new file mode 100644 index 0000000..ec8aebd --- /dev/null +++ b/Bases/MovementBase2D.cs @@ -0,0 +1,12 @@ +using UnityEngine; + +namespace Syntriax.Modules.Movement +{ + public abstract class MovementBase2D : MovementBase + { + protected abstract Vector2 moveValue { get; set; } + + public override void Move(float x = 0, float y = 0, float z = 0) + => moveValue = new Vector2(x, y) * BaseSpeed * MovementMultiplier; + } +} diff --git a/Implementations/2D/OneDirectional2DGroundMovement.cs.meta b/Bases/MovementBase2D.cs.meta similarity index 83% rename from Implementations/2D/OneDirectional2DGroundMovement.cs.meta rename to Bases/MovementBase2D.cs.meta index cc344f8..150477c 100644 --- a/Implementations/2D/OneDirectional2DGroundMovement.cs.meta +++ b/Bases/MovementBase2D.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9c73429b47407634daead7ee1b52629d +guid: 408740142766625499af221fe7c964ac MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Bases/MovementBase3D.cs b/Bases/MovementBase3D.cs new file mode 100644 index 0000000..1eb193e --- /dev/null +++ b/Bases/MovementBase3D.cs @@ -0,0 +1,12 @@ +using UnityEngine; + +namespace Syntriax.Modules.Movement +{ + public abstract class MovementBase3D : MovementBase + { + protected abstract Vector3 moveValue { get; set; } + + public override void Move(float x = 0, float y = 0, float z = 0) + => moveValue = new Vector3(x, y, z) * BaseSpeed * MovementMultiplier; + } +} diff --git a/Implementations/2D/OneDirectional2DAirMovement.cs.meta b/Bases/MovementBase3D.cs.meta similarity index 83% rename from Implementations/2D/OneDirectional2DAirMovement.cs.meta rename to Bases/MovementBase3D.cs.meta index 81dfb1f..e666836 100644 --- a/Implementations/2D/OneDirectional2DAirMovement.cs.meta +++ b/Bases/MovementBase3D.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2f38efc38cadfd94ba8698189577f60f +guid: 2c60740cee0555543b46e6417ce6daca MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Implementations/2D.meta b/Implementations/2D.meta deleted file mode 100644 index 15f8372..0000000 --- a/Implementations/2D.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 247a7892cc48fa54c971733d8e0213db -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Implementations/2D/OneDirectional2DAirMovement.cs b/Implementations/2D/OneDirectional2DAirMovement.cs deleted file mode 100644 index 51b2a13..0000000 --- a/Implementations/2D/OneDirectional2DAirMovement.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Syntriax.Modules.Movement.ColliderTrigger; -using UnityEngine; - -namespace Syntriax.Modules.Movement.Implementations.TwoDimensional -{ - public class OneDirectional2DAirMovement : OneDirectional2DMovementBase - { - protected override float moveValue { get; set; } = 0f; - protected IGroundTrigger groundTrigger = null; - - protected override void Start() - { - base.Start(); - groundTrigger = GetComponentInChildren(); - groundTrigger.OnTriggered += OnGroundTrigger; - } - - private void OnGroundTrigger(bool isGrounded) - => CanTakeOver = !isGrounded; - - public override void ApplyMovement() - { - Vector2 velocity = rigid.velocity; - velocity.x += moveValue * Time.fixedDeltaTime; - - if (moveValue != 0f) - { - if (Mathf.Abs(velocity.x) > Mathf.Abs(moveValue)) - velocity.x = moveValue; - else if (Mathf.Abs(velocity.x - moveValue) > Mathf.Abs(moveValue)) - velocity.x += moveValue * Time.fixedDeltaTime; - } - - rigid.velocity = velocity; - } - - protected override void OnDeactivated() { } - protected override void OnActivated() { } - } -} diff --git a/Implementations/2D/OneDirectional2DGroundMovement.cs b/Implementations/2D/OneDirectional2DGroundMovement.cs deleted file mode 100644 index a6ca5fc..0000000 --- a/Implementations/2D/OneDirectional2DGroundMovement.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Syntriax.Modules.Movement.ColliderTrigger; -using UnityEngine; - -namespace Syntriax.Modules.Movement.Implementations.TwoDimensional -{ - public class OneDirectional2DGroundMovement : OneDirectional2DMovementBase - { - protected override float moveValue { get; set; } = 0f; - protected IGroundTrigger groundTrigger = null; - - protected override void Start() - { - base.Start(); - groundTrigger = GetComponentInChildren(); - groundTrigger.OnTriggered += OnGroundTrigger; - } - - private void OnGroundTrigger(bool isGrounded) - => CanTakeOver = isGrounded; - - public override void ApplyMovement() - { - Vector2 velocity = rigid.velocity; - velocity.x = moveValue; - rigid.velocity = velocity; - } - - protected override void OnDeactivated() { } - protected override void OnActivated() { } - } -}