2022-03-08 10:13:27 +03:00
|
|
|
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;
|
2022-03-13 20:59:45 +03:00
|
|
|
protected IMovementController movementController = null;
|
2022-03-08 10:13:27 +03:00
|
|
|
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>();
|
2022-03-13 20:59:45 +03:00
|
|
|
movementController = GetComponent<IMovementController>();
|
|
|
|
|
|
|
|
movementController.OnMovementActivated.AddListener(OnActivated);
|
|
|
|
movementController.OnMovementDeactivated.AddListener(OnDeactivated);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected abstract void OnDeactivated();
|
|
|
|
private void OnDeactivated(IMovement movement)
|
|
|
|
{
|
|
|
|
if ((object)movement != this)
|
|
|
|
return;
|
|
|
|
OnDeactivated();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected abstract void OnActivated();
|
|
|
|
private void OnActivated(IMovement movement)
|
|
|
|
{
|
|
|
|
if ((object)movement != this)
|
|
|
|
return;
|
|
|
|
OnActivated();
|
2022-03-08 10:13:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public abstract void Move(float x = 0, float y = 0, float z = 0);
|
|
|
|
public abstract void ApplyMovement();
|
|
|
|
}
|
|
|
|
}
|