Movement/2D/TwoDimensionalMovementBase.cs

49 lines
1.4 KiB
C#
Raw Normal View History

using Syntriax.Modules.Movement.State;
using UnityEngine;
using UnityEngine.Events;
namespace Syntriax.Modules.Movement
{
[RequireComponent(typeof(Rigidbody2D))]
public abstract class TwoDimensionalMovementBase : MonoBehaviour, IMovement
{
protected Rigidbody2D rigid = null;
protected IToggleState toggleState = null;
private bool _canTakeOver = false;
public float BaseSpeed { get; set; } = 1f;
public float MovementMultiplier { get; set; } = 1f;
public UnityEvent<bool> OnTakeOverStateChanged { get; protected set; } = null;
public bool CanTakeOver
{
get => _canTakeOver;
protected set
{
bool isNewValue = _canTakeOver != value;
_canTakeOver = value;
if (isNewValue)
OnTakeOverStateChanged.Invoke(value);
}
}
public IToggleState ToggleState { get; protected set; } = null;
protected virtual void Awake()
{
OnTakeOverStateChanged = new UnityEvent<bool>();
}
protected virtual void Start()
{
rigid = GetComponent<Rigidbody2D>();
toggleState = GetComponent<ToggleState>();
}
public abstract void Move(float x = 0, float y = 0, float z = 0);
public abstract void ApplyMovement();
}
}