Unity Package Structure (0.1.0)

This commit is contained in:
2022-12-16 23:24:02 +03:00
parent 8ee5c680f5
commit 7d409495b1
18 changed files with 66 additions and 10 deletions

79
Samples/PlatformerJump.cs Normal file
View 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;
}
}
}

View File

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

View 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
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ce4428cb56d508648a73c9d80a821fd8
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: