feat: Added Sample Scene
This commit is contained in:
49
Samples/2D/Scripts/AirMovement1D.cs
Normal file
49
Samples/2D/Scripts/AirMovement1D.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Syntriax.Modules.Trigger;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Movement.Samples
|
||||
{
|
||||
[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 = GetComponentInParent<Rigidbody2D>();
|
||||
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
||||
|
||||
if (groundTrigger != null)
|
||||
{
|
||||
groundTrigger.OnTriggerStateChanged += 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() { }
|
||||
}
|
||||
}
|
11
Samples/2D/Scripts/AirMovement1D.cs.meta
Normal file
11
Samples/2D/Scripts/AirMovement1D.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69ca5998eb951b64499b111100275018
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
43
Samples/2D/Scripts/GroundMovement1D.cs
Normal file
43
Samples/2D/Scripts/GroundMovement1D.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Syntriax.Modules.Trigger;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Movement.Samples
|
||||
{
|
||||
[System.Serializable]
|
||||
[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 = GetComponentInParent<Rigidbody2D>();
|
||||
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
||||
|
||||
if (groundTrigger != null)
|
||||
{
|
||||
groundTrigger.OnTriggerStateChanged += 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() { }
|
||||
}
|
||||
}
|
11
Samples/2D/Scripts/GroundMovement1D.cs.meta
Normal file
11
Samples/2D/Scripts/GroundMovement1D.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10b59caf08f3e2d4b94eb72b7885346d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
40
Samples/2D/Scripts/MovementInputSample.cs
Normal file
40
Samples/2D/Scripts/MovementInputSample.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using Syntriax.Modules.Trigger;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Movement.Samples
|
||||
{
|
||||
public class MovementInputSample : MonoBehaviour
|
||||
{
|
||||
private IMovementController movementController = null;
|
||||
private Rigidbody2D rigid = null;
|
||||
private IGroundTrigger groundTrigger = null;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
movementController = GetComponent<IMovementController>();
|
||||
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
||||
rigid = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
private Vector3 input = Vector3.zero;
|
||||
private void Update()
|
||||
{
|
||||
input = Vector3.zero;
|
||||
input.x = Input.GetAxis("Horizontal");
|
||||
input.y = Input.GetAxis("Vertical");
|
||||
|
||||
movementController.Move(input);
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space) && groundTrigger.IsTrigerred)
|
||||
Jump();
|
||||
}
|
||||
|
||||
private void Jump()
|
||||
{
|
||||
Vector2 velocity = rigid.velocity;
|
||||
velocity.y = 10f;
|
||||
rigid.velocity = velocity;
|
||||
}
|
||||
}
|
||||
}
|
11
Samples/2D/Scripts/MovementInputSample.cs.meta
Normal file
11
Samples/2D/Scripts/MovementInputSample.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3737b1292e46ab4ba2a2c139a8c2ef2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user