Action Bases
This commit is contained in:
parent
7e154d34e5
commit
d9b1b18328
|
@ -0,0 +1,21 @@
|
|||
using Syntriax.Modules.ToggleState;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Action
|
||||
{
|
||||
public abstract class ActionBase : MonoBehaviour, IActionActivate
|
||||
{
|
||||
public IToggleState ToggleState { get; protected set; } = null;
|
||||
|
||||
protected virtual void Awake() => ToggleState = new ToggleStateMember(true);
|
||||
|
||||
protected abstract void OnActivated();
|
||||
public virtual void Activate()
|
||||
{
|
||||
if (!ToggleState.IsToggledNullChecked())
|
||||
return;
|
||||
|
||||
OnActivated();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d07cd6f6a7a635c41add4964a6aba382
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,16 @@
|
|||
using Syntriax.Modules.ToggleState;
|
||||
|
||||
namespace Syntriax.Modules.Action
|
||||
{
|
||||
public abstract class ActionBaseWithDeactivation : ActionBase, IActionDeactivate
|
||||
{
|
||||
protected abstract void OnDeactivated();
|
||||
public virtual void Deactivate()
|
||||
{
|
||||
if (!ToggleState.IsToggledNullChecked())
|
||||
return;
|
||||
|
||||
OnDeactivated();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7bce8bd8b35a51f4785a3933e3526ddf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue