using BITFALL.Player.Movement; using BITKit.Entities; using BITKit.StateMachine; using Lightbug.CharacterControllerPro.Core; using UnityEngine; namespace BITFALL.Entities.Player.Movement.States { public abstract class PlayerCharacterState : IEntityMovementState { [SerializeField] protected PlayerCharacterController characterController; [SerializeField] protected CharacterActor actor; private IEntityMovementState entryState; public bool Enabled { get; set; } public virtual void Initialize() { characterController.UnityEntity.Inject(this); } public virtual void OnStateEntry(IState old) { entryState=old is IPlayerRunState or IPlayerSprintState ? old as IEntityMovementState: null; } public virtual void OnStateUpdate(float deltaTime) { } public virtual void OnStateExit(IState old, IState newState) { } public virtual void UpdateVelocity(ref Vector3 currentVelocity,float deltaTime) { } public virtual void UpdateRotation(ref Quaternion currentRotation,float deltaTime) { } public virtual void BeforeUpdateMovement(float deltaTime) { } public virtual void AfterUpdateMovement(float deltaTime) { } public virtual void ExecuteCommand(T command) { } protected virtual void Exit() { if ( entryState is not null) { if ( entryState is IPlayerWalkState or IPlayerRunState or IPlayerSprintState && characterController.topBlocked ) { characterController.TransitionState(); } else { characterController.TransitionState(entryState); } } else { if (characterController.topBlocked) { characterController.TransitionState(); } else { characterController.TransitionState(); } } } } }