Default Movement Added

This commit is contained in:
Syntriax 2022-11-15 16:26:26 +03:00
parent b0442c2af9
commit 92d4871184
5 changed files with 38 additions and 8 deletions

View File

@ -16,7 +16,12 @@ namespace Syntriax.Modules.Movement.Implementations
rigid = GetComponent<Rigidbody2D>();
groundTrigger = GetComponentInChildren<IGroundTrigger>();
if (groundTrigger != null)
{
groundTrigger.OnTriggered += OnGroundTrigger;
CanTakeOver = false;
}
}
private void OnGroundTrigger(bool isGrounded)

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

@ -10,6 +10,8 @@ namespace Syntriax.Modules.Movement.Implementations
protected IGroundTrigger groundTrigger = null;
protected Rigidbody2D rigid = null;
private void Awake() => CanTakeOver = true;
protected override void Start()
{
base.Start();
@ -18,9 +20,10 @@ namespace Syntriax.Modules.Movement.Implementations
groundTrigger = GetComponentInChildren<IGroundTrigger>();
if (groundTrigger != null)
{
groundTrigger.OnTriggered += OnGroundTrigger;
else
CanTakeOver = true;
CanTakeOver = false;
}
}
private void OnGroundTrigger(bool isGrounded)

View File

@ -38,6 +38,9 @@ namespace Syntriax.Modules.Movement
protected virtual void Start()
{
if (GetComponent<Implementations.DefaultMovement>() == null)
gameObject.AddComponent<Implementations.DefaultMovement>();
RecacheMovements();
toggleState = GetComponent<IToggleState>();
}
@ -73,11 +76,6 @@ namespace Syntriax.Modules.Movement
ActiveMovement = movement;
return;
}
Debug.LogWarning("No IMovement found with \"CanTakeOver\" value set to true, setting the last IMovement as the ActiveMovement. Please have an IMovement that you can use as a fallback with it's \"CanTakeOver\" value always set to true.", this);
try { ActiveMovement = Movements[Movements.Count - 1]; }
catch (System.Exception) { Debug.LogWarning("Movement Controller component needs at least one Monobehaviour attached that implements IMovement interface", this); }
}
public void Move(float x = 0, float y = 0, float z = 0)