- Movement & Controller
- Special Actions
- ToggleState
- ColliderChecker
- and 2D Implementations
This commit is contained in:
2022-03-08 10:13:27 +03:00
parent 91839d2323
commit f0ffc2a8c4
81 changed files with 419 additions and 751 deletions

View File

@@ -1,20 +1,22 @@
using Syntriax.Modules.Movement.ColliderCheck;
using Syntriax.Modules.Movement.ColliderTrigger;
using Syntriax.Modules.Movement.State;
using UnityEngine;
namespace Syntriax.Modules.Movement.SpecialAction
{
[RequireComponent(typeof(Rigidbody2D))]
public class PlatformerJump : MonoBehaviour, ISpecialActionActivate, ISpecialActionDeactivate, IState
public class PlatformerJump : MonoBehaviour, ISpecialActionActivate, ISpecialActionDeactivate
{
public float JumpSpeed { get; set; } = 0f;
public bool StateEnabled { get; set; } = true;
public IToggleState EnabledToggleState { get; private set; } = null;
private bool airSuspension = false;
private float fallMultiplier = 0f;
private float suspensionMultiplier = 0f;
private IGroundCheck groundCheck = null;
private IGroundTrigger groundCheck = null;
private Rigidbody2D rigid = null;
private IToggleState toggleState = null;
private void Awake()
@@ -22,17 +24,19 @@ namespace Syntriax.Modules.Movement.SpecialAction
JumpSpeed = 10f;
fallMultiplier = 1.5f * Time.fixedDeltaTime;
suspensionMultiplier = 1f * Time.fixedDeltaTime;
EnabledToggleState = new MemberToggleState();
}
private void Start()
{
rigid = GetComponent<Rigidbody2D>();
groundCheck = GetComponentInChildren<IGroundCheck>();
groundCheck = GetComponentInChildren<IGroundTrigger>();
toggleState = GetComponent<IToggleState>();
}
private void FixedUpdate()
{
if (!StateEnabled)
if (!EnabledToggleState.Toggled)
return;
if (rigid.velocity.y < 0f)
@@ -53,16 +57,22 @@ namespace Syntriax.Modules.Movement.SpecialAction
rigid.velocity = velocity;
}
public void OnActivation()
public void Activate()
{
if (groundCheck.IsCollided())
if (!toggleState.Toggled)
return;
if (groundCheck.IsTrigerred)
Jump();
airSuspension = true;
}
public void OnDeactivation()
public void Deactivate()
{
if (!toggleState.Toggled)
return;
airSuspension = false;
}
}