Action Bases

This commit is contained in:
2022-11-20 18:45:36 +03:00
parent 7e154d34e5
commit d9b1b18328
5 changed files with 82 additions and 13 deletions

View File

@@ -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;
}
}