Action Bases
This commit is contained in:
@@ -4,20 +4,22 @@ using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Action
|
||||
{
|
||||
[RequireComponent(typeof(Rigidbody2D))]
|
||||
public class PlatformerJump : MonoBehaviour, IActionActivate, IActionDeactivate
|
||||
{
|
||||
private float jumpSpeed = 10f;
|
||||
public float JumpSpeed { get => jumpSpeed; set => jumpSpeed = value; }
|
||||
public IToggleState ToggleState { get; protected set; } = null;
|
||||
|
||||
public float FallThreshold { get; set; } = 0f;
|
||||
[RequireComponent(typeof(Rigidbody2D))]
|
||||
public class PlatformerJump : ActionBaseWithDeactivation
|
||||
{
|
||||
[SerializeField] private float jumpSpeed = 10f;
|
||||
public float JumpSpeed { get => jumpSpeed; set => jumpSpeed = value; }
|
||||
[SerializeField] private float fallThreshold = 0f;
|
||||
public float FallThreshold { get => fallThreshold; set => fallThreshold = value; }
|
||||
|
||||
[SerializeField] private float fallMultiplier = 1.5f;
|
||||
public float FallMultiplier
|
||||
{
|
||||
get => fallMultiplier;
|
||||
set => fallMultiplier = value * Time.fixedDeltaTime;
|
||||
}
|
||||
|
||||
[SerializeField] private float suspensionMultiplier = 1f;
|
||||
public float SuspensionMultiplier
|
||||
{
|
||||
@@ -25,17 +27,19 @@ namespace Syntriax.Modules.Action
|
||||
set => suspensionMultiplier = value * Time.fixedDeltaTime;
|
||||
}
|
||||
|
||||
protected IToggleState gameObjectToggleState = null;
|
||||
protected bool airSuspension = false;
|
||||
protected IGroundTrigger groundCheck = null;
|
||||
protected IToggleState gameObjectToggleState = null;
|
||||
protected Rigidbody2D rigid = null;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
rigid = GetComponent<Rigidbody2D>();
|
||||
groundCheck = GetComponentInChildren<IGroundTrigger>();
|
||||
ToggleState = new ToggleStateMember(true);
|
||||
gameObjectToggleState = GetComponent<IToggleState>();
|
||||
|
||||
FallMultiplier = fallMultiplier;
|
||||
SuspensionMultiplier = suspensionMultiplier;
|
||||
}
|
||||
|
||||
protected virtual void FixedUpdate()
|
||||
@@ -59,9 +63,17 @@ namespace Syntriax.Modules.Action
|
||||
rigid.velocity = velocity;
|
||||
}
|
||||
|
||||
public virtual void Activate()
|
||||
protected override void OnDeactivated()
|
||||
{
|
||||
if (!ToggleState.IsToggledNullChecked() || !gameObjectToggleState.IsToggledNullChecked())
|
||||
if (!gameObjectToggleState.IsToggledNullChecked())
|
||||
return;
|
||||
|
||||
airSuspension = false;
|
||||
}
|
||||
|
||||
protected override void OnActivated()
|
||||
{
|
||||
if (!gameObjectToggleState.IsToggledNullChecked())
|
||||
return;
|
||||
|
||||
if (groundCheck.IsTrigerred)
|
||||
@@ -69,7 +81,5 @@ namespace Syntriax.Modules.Action
|
||||
|
||||
airSuspension = true;
|
||||
}
|
||||
|
||||
public virtual void Deactivate() => airSuspension = false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user