64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
using System;
|
|
using Syntriax.Modules.ToggleState;
|
|
using UnityEngine;
|
|
|
|
namespace Syntriax.Modules.Movement
|
|
{
|
|
public abstract class MovementBase : MonoBehaviour, IMovement
|
|
{
|
|
protected IToggleState toggleState = null;
|
|
protected IMovementController movementController = null;
|
|
|
|
public float BaseSpeed { get; set; } = 1f;
|
|
public float MovementMultiplier { get; set; } = 1f;
|
|
|
|
public Action<bool> OnTakeOverStateChanged { get; set; } = null;
|
|
private bool _canTakeOver = false;
|
|
public bool CanTakeOver
|
|
{
|
|
get => _canTakeOver;
|
|
protected set
|
|
{
|
|
bool oldValue = _canTakeOver;
|
|
|
|
_canTakeOver = value;
|
|
|
|
if (oldValue != value)
|
|
OnTakeOverStateChanged?.Invoke(value);
|
|
}
|
|
}
|
|
|
|
public IToggleState ToggleState { get; protected set; } = null;
|
|
public abstract void ApplyMovement();
|
|
|
|
public abstract void Move(float x = 0, float y = 0, float z = 0);
|
|
|
|
protected abstract void OnActivated();
|
|
|
|
protected abstract void OnDeactivated();
|
|
|
|
protected virtual void Start()
|
|
{
|
|
toggleState = GetComponent<IToggleState>();
|
|
movementController = GetComponent<IMovementController>();
|
|
|
|
movementController.OnMovementActivated += OnActivated;
|
|
movementController.OnMovementDeactivated += OnDeactivated;
|
|
}
|
|
|
|
private void OnActivated(IMovement movement)
|
|
{
|
|
if ((object)movement != this)
|
|
return;
|
|
OnActivated();
|
|
}
|
|
|
|
private void OnDeactivated(IMovement movement)
|
|
{
|
|
if ((object)movement != this)
|
|
return;
|
|
OnDeactivated();
|
|
}
|
|
}
|
|
}
|