Unity Package Structure (0.1.0)
This commit is contained in:
79
Samples/PlatformerJump.cs
Normal file
79
Samples/PlatformerJump.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Syntriax.Modules.ToggleState;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Action.Samples
|
||||
{
|
||||
[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
|
||||
{
|
||||
get => suspensionMultiplier;
|
||||
set => suspensionMultiplier = value * Time.fixedDeltaTime;
|
||||
}
|
||||
|
||||
protected IToggleState gameObjectToggleState = null;
|
||||
protected bool airSuspension = false;
|
||||
protected Rigidbody2D rigid = null;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
rigid = GetComponent<Rigidbody2D>();
|
||||
gameObjectToggleState = GetComponent<IToggleState>();
|
||||
|
||||
FallMultiplier = fallMultiplier;
|
||||
SuspensionMultiplier = suspensionMultiplier;
|
||||
}
|
||||
|
||||
protected virtual void FixedUpdate()
|
||||
{
|
||||
if (!MemberToggleState.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;
|
||||
}
|
||||
|
||||
protected override void OnActionDeactivated()
|
||||
{
|
||||
if (!gameObjectToggleState.IsToggledNullChecked())
|
||||
return;
|
||||
|
||||
airSuspension = false;
|
||||
}
|
||||
|
||||
protected override void OnActionActivated()
|
||||
{
|
||||
if (!gameObjectToggleState.IsToggledNullChecked())
|
||||
return;
|
||||
|
||||
Jump();
|
||||
airSuspension = true;
|
||||
}
|
||||
}
|
||||
}
|
11
Samples/PlatformerJump.cs.meta
Normal file
11
Samples/PlatformerJump.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c55e74ac98f03704bb026843c9b84a1e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
17
Samples/Syntriax.Modules.Action.Samples.asmdef
Normal file
17
Samples/Syntriax.Modules.Action.Samples.asmdef
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "Syntriax.Modules.Action.Samples",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:efa9a9bc94c60c74684aafb7428fbf61",
|
||||
"GUID:7cd17689338eae84183e6b576fc9ae7c"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
7
Samples/Syntriax.Modules.Action.Samples.asmdef.meta
Normal file
7
Samples/Syntriax.Modules.Action.Samples.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce4428cb56d508648a73c9d80a821fd8
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user