using System; using Syntriax.Modules.State; using UnityEngine; namespace Syntriax.Modules.Movement { public abstract class MovementBase : MonoBehaviour, IMovement { protected IStateEnable stateEnable = null; protected IMovementController movementController = null; [SerializeField] private float _baseSpeed = 1f; public float BaseSpeed { get => _baseSpeed; set => _baseSpeed = value; } [SerializeField] private float _movementMultiplier = 1f; public float MovementMultiplier { get => _movementMultiplier; set => _movementMultiplier = value; } public Action OnTakeOverStateChanged { get; set; } = null; private bool _canTakeOver = false; public bool CanTakeOver { get => _canTakeOver; protected set { if (value == _canTakeOver) return; _canTakeOver = value; OnTakeOverStateChanged?.Invoke(value); } } /// public abstract void ApplyMovement(); public abstract void Move(float x = 0, float y = 0, float z = 0); /// /// Called when this is activated. /// protected abstract void OnActivated(); /// /// Called when this is deactivated. /// protected abstract void OnDeactivated(); protected virtual void Start() { stateEnable = GetComponent(); movementController = GetComponent(); movementController.OnMovementActivated += OnActivated; movementController.OnMovementDeactivated += OnDeactivated; } /// /// Called when the activates one of it's s. /// private void OnActivated(IMovement movement) { if ((object)movement != this) return; OnActivated(); } /// /// Called when the activates one of it's s. /// private void OnDeactivated(IMovement movement) { if ((object)movement != this) return; OnDeactivated(); } } }