First Commit

This commit is contained in:
Syntriax 2022-11-20 18:31:16 +03:00
parent c01b98e760
commit 7e154d34e5
8 changed files with 141 additions and 0 deletions

8
Actions.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 341c2035d0254344cad44ff6138adf58
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

75
Actions/PlatformerJump.cs Normal file
View File

@ -0,0 +1,75 @@
using Syntriax.Modules.ToggleState;
using Syntriax.Modules.Trigger;
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;
[SerializeField] private float fallMultiplier = 1.5f;
public float FallMultiplier
{
get => fallMultiplier;
set => fallMultiplier = value * Time.fixedDeltaTime;
}
[SerializeField] private float suspensionMultiplier = 1f;
public float SuspensionMultiplier
{
get => suspensionMultiplier;
set => suspensionMultiplier = value * Time.fixedDeltaTime;
}
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>();
}
protected virtual void FixedUpdate()
{
if (!ToggleState.IsToggledNullChecked() || !gameObjectToggleState.IsToggledNullChecked())
return;
if (rigid.velocity.y < FallThreshold)
ApplySuspension(SuspensionMultiplier);
else if (!airSuspension)
ApplySuspension(FallMultiplier);
}
protected virtual void ApplySuspension(float multiplier)
=> rigid.velocity += Physics2D.gravity * multiplier;
protected virtual void Jump()
{
Vector2 velocity = rigid.velocity;
velocity.y = JumpSpeed;
rigid.velocity = velocity;
}
public virtual void Activate()
{
if (!ToggleState.IsToggledNullChecked() || !gameObjectToggleState.IsToggledNullChecked())
return;
if (groundCheck.IsTrigerred)
Jump();
airSuspension = true;
}
public virtual void Deactivate() => airSuspension = false;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e45c80df261a5714e9a22fd73a2cd39a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
IActionActivate.cs Normal file
View File

@ -0,0 +1,11 @@
using Syntriax.Modules.ToggleState;
namespace Syntriax.Modules.Action
{
public interface IActionActivate
{
IToggleState ToggleState { get; }
void Activate();
}
}

11
IActionActivate.cs.meta Normal file
View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9ff9f1a7b70a47e4aa97dfda371fbf21
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

7
IActionDeactivate.cs Normal file
View File

@ -0,0 +1,7 @@
namespace Syntriax.Modules.Action
{
public interface IActionDeactivate : IActionActivate
{
void Deactivate();
}
}

11
IActionDeactivate.cs.meta Normal file
View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 10a30eb2debabdf40b2f8120a5f1ad01
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

7
README.md.meta Normal file
View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 89a86cb669e56984987cdfabde5bc3bd
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: