Unity Package Structure

This commit is contained in:
2022-12-15 19:24:01 +03:00
parent f84502ceb4
commit 36ec79c262
43 changed files with 44 additions and 3 deletions

View File

@@ -0,0 +1,49 @@
using Syntriax.Modules.Trigger;
using UnityEngine;
namespace Syntriax.Modules.Movement.Implementations
{
[RequireComponent(typeof(Rigidbody2D))]
public class AirMovement1D : MovementBase1D
{
protected override float moveValue { get; set; } = 0f;
protected IGroundTrigger groundTrigger = null;
protected Rigidbody2D rigid = null;
protected override void Start()
{
base.Start();
rigid = GetComponent<Rigidbody2D>();
groundTrigger = GetComponentInChildren<IGroundTrigger>();
if (groundTrigger != null)
{
groundTrigger.OnTriggered += OnGroundTrigger;
CanTakeOver = false;
}
}
private void OnGroundTrigger(bool isGrounded)
=> CanTakeOver = !isGrounded;
public override void ApplyMovement()
{
Vector2 velocity = rigid.velocity;
velocity.x += moveValue * Time.fixedDeltaTime;
if (moveValue != 0f)
{
if (Mathf.Abs(velocity.x) > Mathf.Abs(moveValue))
velocity.x = moveValue;
else if (Mathf.Abs(velocity.x - moveValue) > Mathf.Abs(moveValue))
velocity.x += moveValue * Time.fixedDeltaTime;
}
rigid.velocity = velocity;
}
protected override void OnDeactivated() { }
protected override void OnActivated() { }
}
}

View File

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

View File

@@ -0,0 +1,13 @@
using UnityEngine;
namespace Syntriax.Modules.Movement.Implementations
{
public class DefaultMovement : MovementBase
{
public override void ApplyMovement() { }
public override void Move(float x = 0, float y = 0, float z = 0) { }
protected override void OnActivated()
=> Debug.LogWarning("Default Movement is activated, this movement has no implementation, please add a Movement that you can use as a fallback with it's \"CanTakeOver\" value set to true if this was not intentional");
protected override void OnDeactivated() { }
}
}

View File

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

View File

@@ -0,0 +1,42 @@
using Syntriax.Modules.Trigger;
using UnityEngine;
namespace Syntriax.Modules.Movement.Implementations
{
[RequireComponent(typeof(Rigidbody2D))]
public class GroundMovement1D : MovementBase1D
{
protected override float moveValue { get; set; } = 0f;
protected IGroundTrigger groundTrigger = null;
protected Rigidbody2D rigid = null;
private void Awake() => CanTakeOver = true;
protected override void Start()
{
base.Start();
rigid = GetComponent<Rigidbody2D>();
groundTrigger = GetComponentInChildren<IGroundTrigger>();
if (groundTrigger != null)
{
groundTrigger.OnTriggered += OnGroundTrigger;
CanTakeOver = false;
}
}
private void OnGroundTrigger(bool isGrounded)
=> CanTakeOver = isGrounded;
public override void ApplyMovement()
{
Vector2 velocity = rigid.velocity;
velocity.x = moveValue;
rigid.velocity = velocity;
}
protected override void OnDeactivated() { }
protected override void OnActivated() { }
}
}

View File

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