2022-11-13 18:07:54 +03:00
|
|
|
using System;
|
2022-11-14 13:04:09 +03:00
|
|
|
using Syntriax.Modules.ToggleState;
|
2022-03-08 10:13:27 +03:00
|
|
|
using UnityEngine;
|
|
|
|
|
2022-11-14 12:41:11 +03:00
|
|
|
namespace Syntriax.Modules.Movement
|
2022-03-08 10:13:27 +03:00
|
|
|
{
|
2022-11-14 12:41:11 +03:00
|
|
|
public abstract class MovementBase : MonoBehaviour, IMovement
|
2022-03-08 10:13:27 +03:00
|
|
|
{
|
|
|
|
protected IToggleState toggleState = null;
|
2022-03-13 20:59:45 +03:00
|
|
|
protected IMovementController movementController = null;
|
2022-03-08 10:13:27 +03:00
|
|
|
|
|
|
|
public float BaseSpeed { get; set; } = 1f;
|
|
|
|
public float MovementMultiplier { get; set; } = 1f;
|
|
|
|
|
2022-11-13 18:07:54 +03:00
|
|
|
public Action<bool> OnTakeOverStateChanged { get; set; } = null;
|
2022-11-15 13:08:37 +03:00
|
|
|
private bool _canTakeOver = false;
|
2022-03-08 10:13:27 +03:00
|
|
|
public bool CanTakeOver
|
|
|
|
{
|
|
|
|
get => _canTakeOver;
|
|
|
|
protected set
|
|
|
|
{
|
2022-12-02 00:09:54 +03:00
|
|
|
if (value == _canTakeOver)
|
|
|
|
return;
|
2022-03-08 10:13:27 +03:00
|
|
|
|
|
|
|
_canTakeOver = value;
|
2022-12-02 00:09:54 +03:00
|
|
|
OnTakeOverStateChanged?.Invoke(value);
|
2022-03-08 10:13:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public IToggleState ToggleState { get; protected set; } = null;
|
2022-11-20 13:32:06 +03:00
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2022-11-14 12:41:11 +03:00
|
|
|
public abstract void ApplyMovement();
|
|
|
|
|
|
|
|
public abstract void Move(float x = 0, float y = 0, float z = 0);
|
|
|
|
|
2022-11-20 13:32:06 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Called when this <see cref="IMovement"/> is activated.
|
|
|
|
/// </summary>
|
2022-11-14 12:41:11 +03:00
|
|
|
protected abstract void OnActivated();
|
|
|
|
|
2022-11-20 13:32:06 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Called when this <see cref="IMovement"/> is deactivated.
|
|
|
|
/// </summary>
|
2022-11-14 12:41:11 +03:00
|
|
|
protected abstract void OnDeactivated();
|
2022-03-08 10:13:27 +03:00
|
|
|
|
|
|
|
protected virtual void Start()
|
|
|
|
{
|
2022-11-14 13:04:09 +03:00
|
|
|
toggleState = GetComponent<IToggleState>();
|
2022-03-13 20:59:45 +03:00
|
|
|
movementController = GetComponent<IMovementController>();
|
|
|
|
|
2022-11-13 18:07:54 +03:00
|
|
|
movementController.OnMovementActivated += OnActivated;
|
|
|
|
movementController.OnMovementDeactivated += OnDeactivated;
|
2022-03-13 20:59:45 +03:00
|
|
|
}
|
2022-11-15 13:08:37 +03:00
|
|
|
|
2022-11-20 13:32:06 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Called when the <see cref="IMovementController"/> activates one of it's <see cref="IMovement"/>s.
|
|
|
|
/// </summary>
|
2022-11-14 12:41:11 +03:00
|
|
|
private void OnActivated(IMovement movement)
|
2022-03-13 20:59:45 +03:00
|
|
|
{
|
|
|
|
if ((object)movement != this)
|
|
|
|
return;
|
2022-11-14 12:41:11 +03:00
|
|
|
OnActivated();
|
2022-03-13 20:59:45 +03:00
|
|
|
}
|
2022-11-15 13:08:37 +03:00
|
|
|
|
2022-11-20 13:32:06 +03:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Called when the <see cref="IMovementController"/> activates one of it's <see cref="IMovement"/>s.
|
|
|
|
/// </summary>
|
2022-11-14 12:41:11 +03:00
|
|
|
private void OnDeactivated(IMovement movement)
|
2022-03-13 20:59:45 +03:00
|
|
|
{
|
|
|
|
if ((object)movement != this)
|
|
|
|
return;
|
2022-11-14 12:41:11 +03:00
|
|
|
OnDeactivated();
|
2022-03-08 10:13:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|