BREAKING CHANGE: State 0.2.0
This commit is contained in:
parent
7d409495b1
commit
42c81ada1d
@ -1,6 +1,6 @@
|
|||||||
# Action
|
# Action
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
1. [ToggleState Module](https://git.syntriax.com/Syntriax/ToggleState)
|
1. [State Module](https://git.syntriax.com/Syntriax/State)
|
||||||
|
|
||||||
Make sure to separately clone these modules along with this one too.
|
Make sure to separately clone these modules along with this one too.
|
||||||
|
@ -1,20 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
using Syntriax.Modules.ToggleState;
|
using Syntriax.Modules.State;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Action
|
namespace Syntriax.Modules.Action
|
||||||
{
|
{
|
||||||
public abstract class ActionBase : MonoBehaviour, IAction
|
public abstract class ActionBase : MonoBehaviour, IAction
|
||||||
{
|
{
|
||||||
public IToggleState MemberToggleState { get; protected set; } = null;
|
public IStateEnable StateEnable { get; protected set; } = null;
|
||||||
public Action<IAction> OnActivated { get; set; } = null;
|
public Action<IAction> OnActivated { get; set; } = null;
|
||||||
|
|
||||||
protected IToggleState toggleState = null;
|
|
||||||
|
|
||||||
protected virtual void Awake()
|
protected virtual void Awake()
|
||||||
{
|
{
|
||||||
toggleState = GetComponent<IToggleState>();
|
StateEnable = new StateEnableMember(true);
|
||||||
MemberToggleState = new ToggleStateMember(true);
|
|
||||||
OnActivated += (_) => OnActionActivated();
|
OnActivated += (_) => OnActionActivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +22,7 @@ namespace Syntriax.Modules.Action
|
|||||||
protected abstract void OnActionActivated();
|
protected abstract void OnActionActivated();
|
||||||
public virtual void Activate()
|
public virtual void Activate()
|
||||||
{
|
{
|
||||||
if (!MemberToggleState.IsToggledNullChecked() || !toggleState.IsToggledNullChecked())
|
if (!StateEnable.IsEnabledNullChecked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OnActivated?.Invoke(this);
|
OnActivated?.Invoke(this);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using Syntriax.Modules.ToggleState;
|
using Syntriax.Modules.State;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Action
|
namespace Syntriax.Modules.Action
|
||||||
{
|
{
|
||||||
@ -19,7 +19,7 @@ namespace Syntriax.Modules.Action
|
|||||||
protected abstract void OnActionDeactivated();
|
protected abstract void OnActionDeactivated();
|
||||||
public virtual void Deactivate()
|
public virtual void Deactivate()
|
||||||
{
|
{
|
||||||
if (!MemberToggleState.IsToggledNullChecked() || !toggleState.IsToggledNullChecked())
|
if (!StateEnable.IsEnabledNullChecked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OnDeactivated?.Invoke(this);
|
OnDeactivated?.Invoke(this);
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using Syntriax.Modules.ToggleState;
|
using Syntriax.Modules.State;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Action
|
namespace Syntriax.Modules.Action
|
||||||
{
|
{
|
||||||
public interface IAction
|
public interface IAction
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The member <see cref="IToggleState"/> the Action uses to check if it's active or not
|
/// The member <see cref="IStateEnable"/> the Action uses to check if it's active or not
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IToggleState MemberToggleState { get; }
|
IStateEnable StateEnable { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the <see cref="IAction"/> is Activated
|
/// Called when the <see cref="IAction"/> is Activated
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using Syntriax.Modules.ToggleState;
|
using Syntriax.Modules.State;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Action.Samples
|
namespace Syntriax.Modules.Action.Samples
|
||||||
{
|
{
|
||||||
[RequireComponent(typeof(Rigidbody2D))]
|
[RequireComponent(typeof(Rigidbody2D))]
|
||||||
public class PlatformerJump : ActionBaseWithDeactivation
|
public class PlatformerJump : ActionWithDeactivation
|
||||||
{
|
{
|
||||||
[SerializeField] private float jumpSpeed = 10f;
|
[SerializeField] private float jumpSpeed = 10f;
|
||||||
public float JumpSpeed { get => jumpSpeed; set => jumpSpeed = value; }
|
public float JumpSpeed { get => jumpSpeed; set => jumpSpeed = value; }
|
||||||
@ -25,22 +25,25 @@ namespace Syntriax.Modules.Action.Samples
|
|||||||
set => suspensionMultiplier = value * Time.fixedDeltaTime;
|
set => suspensionMultiplier = value * Time.fixedDeltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IToggleState gameObjectToggleState = null;
|
protected IStateEnable gameObjectStateEnable = null;
|
||||||
protected bool airSuspension = false;
|
protected bool airSuspension = false;
|
||||||
protected Rigidbody2D rigid = null;
|
protected Rigidbody2D rigid = null;
|
||||||
|
|
||||||
protected virtual void Start()
|
protected virtual void Start()
|
||||||
{
|
{
|
||||||
rigid = GetComponent<Rigidbody2D>();
|
rigid = GetComponent<Rigidbody2D>();
|
||||||
gameObjectToggleState = GetComponent<IToggleState>();
|
gameObjectStateEnable = GetComponent<IStateEnable>();
|
||||||
|
|
||||||
FallMultiplier = fallMultiplier;
|
FallMultiplier = fallMultiplier;
|
||||||
SuspensionMultiplier = suspensionMultiplier;
|
SuspensionMultiplier = suspensionMultiplier;
|
||||||
|
|
||||||
|
OnActivated += _ => OnActionDeactivated();
|
||||||
|
OnDeactivated += _ => OnActionActivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void FixedUpdate()
|
protected virtual void FixedUpdate()
|
||||||
{
|
{
|
||||||
if (!MemberToggleState.IsToggledNullChecked() || !gameObjectToggleState.IsToggledNullChecked())
|
if (!StateEnable.IsEnabledNullChecked() || !gameObjectStateEnable.IsEnabledNullChecked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (rigid.velocity.y < FallThreshold)
|
if (rigid.velocity.y < FallThreshold)
|
||||||
@ -59,17 +62,17 @@ namespace Syntriax.Modules.Action.Samples
|
|||||||
rigid.velocity = velocity;
|
rigid.velocity = velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnActionDeactivated()
|
protected void OnActionDeactivated()
|
||||||
{
|
{
|
||||||
if (!gameObjectToggleState.IsToggledNullChecked())
|
if (!gameObjectStateEnable.IsEnabledNullChecked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
airSuspension = false;
|
airSuspension = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnActionActivated()
|
protected void OnActionActivated()
|
||||||
{
|
{
|
||||||
if (!gameObjectToggleState.IsToggledNullChecked())
|
if (!gameObjectStateEnable.IsEnabledNullChecked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Jump();
|
Jump();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user