Added New Bases and removed Air and Ground Movement Implementations Temporarily
This commit is contained in:
parent
a2d64a2eef
commit
99f5cf4fa4
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 15528ebd51d27d54398c55826710f23e
|
guid: feeeff74b53207d469a4fc708c0bdd34
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
|
@ -2,12 +2,10 @@ using System;
|
||||||
using Syntriax.Modules.Movement.State;
|
using Syntriax.Modules.Movement.State;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.Implementations.TwoDimensional
|
namespace Syntriax.Modules.Movement
|
||||||
{
|
{
|
||||||
[RequireComponent(typeof(Rigidbody2D))]
|
public abstract class MovementBase : MonoBehaviour, IMovement
|
||||||
public abstract class TwoDimensionalMovementBase : MonoBehaviour, IMovement
|
|
||||||
{
|
{
|
||||||
protected Rigidbody2D rigid = null;
|
|
||||||
protected IToggleState toggleState = null;
|
protected IToggleState toggleState = null;
|
||||||
protected IMovementController movementController = null;
|
protected IMovementController movementController = null;
|
||||||
private bool _canTakeOver = false;
|
private bool _canTakeOver = false;
|
||||||
|
@ -31,34 +29,33 @@ namespace Syntriax.Modules.Movement.Implementations.TwoDimensional
|
||||||
}
|
}
|
||||||
|
|
||||||
public IToggleState ToggleState { get; protected set; } = null;
|
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()
|
protected virtual void Start()
|
||||||
{
|
{
|
||||||
rigid = GetComponent<Rigidbody2D>();
|
|
||||||
toggleState = GetComponent<ToggleState>();
|
toggleState = GetComponent<ToggleState>();
|
||||||
movementController = GetComponent<IMovementController>();
|
movementController = GetComponent<IMovementController>();
|
||||||
|
|
||||||
movementController.OnMovementActivated += OnActivated;
|
movementController.OnMovementActivated += OnActivated;
|
||||||
movementController.OnMovementDeactivated += OnDeactivated;
|
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)
|
private void OnActivated(IMovement movement)
|
||||||
{
|
{
|
||||||
if ((object)movement != this)
|
if ((object)movement != this)
|
||||||
return;
|
return;
|
||||||
OnActivated();
|
OnActivated();
|
||||||
}
|
}
|
||||||
|
private void OnDeactivated(IMovement movement)
|
||||||
public abstract void Move(float x = 0, float y = 0, float z = 0);
|
{
|
||||||
public abstract void ApplyMovement();
|
if ((object)movement != this)
|
||||||
|
return;
|
||||||
|
OnDeactivated();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 51ee606e68723324b92b9d16835c1625
|
guid: d471aae4aaf4636459646d73603689e0
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
|
@ -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; }
|
protected abstract float moveValue { get; set; }
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: b4a8f74afcbe280448862bac89545353
|
guid: 938515a22b53ad6468e4152f1328b6ce
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 9c73429b47407634daead7ee1b52629d
|
guid: 408740142766625499af221fe7c964ac
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 2f38efc38cadfd94ba8698189577f60f
|
guid: 2c60740cee0555543b46e6417ce6daca
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 247a7892cc48fa54c971733d8e0213db
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -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<IGroundTrigger>();
|
|
||||||
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() { }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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<IGroundTrigger>();
|
|
||||||
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() { }
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue