BITFALL/Assets/Artists/Scripts/Player/CharacterControllerPro/PlayerCharacterState.cs

64 lines
1.4 KiB
C#
Raw Normal View History

2023-10-20 19:31:12 +08:00
using BITFALL.Player.Movement;
2023-08-23 01:59:40 +08:00
using BITKit.Entities;
using BITKit.StateMachine;
2023-08-27 02:58:19 +08:00
using Lightbug.CharacterControllerPro.Core;
2023-08-23 01:59:40 +08:00
using UnityEngine;
2023-08-27 02:58:19 +08:00
namespace BITFALL.Entities.Player.Movement.States
2023-08-23 01:59:40 +08:00
{
public abstract class PlayerCharacterState : IEntityMovementState
{
2023-08-27 02:58:19 +08:00
[SerializeField] protected PlayerCharacterController characterController;
[SerializeField] protected CharacterActor actor;
2023-10-20 19:31:12 +08:00
private IEntityMovementState entryState;
2023-08-23 01:59:40 +08:00
public bool Enabled { get; set; }
public virtual void Initialize()
{
2023-10-30 01:25:53 +08:00
characterController.UnityEntity.Inject(this);
2023-08-23 01:59:40 +08:00
}
public virtual void OnStateEntry(IState old)
{
2023-10-20 19:31:12 +08:00
entryState=old is IPlayerRunState or IPlayerSprintState ? old as IEntityMovementState: null;
2023-08-23 01:59:40 +08:00
}
2023-08-27 02:58:19 +08:00
public virtual void OnStateUpdate(float deltaTime)
2023-08-23 01:59:40 +08:00
{
}
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>(T command)
{
}
2023-10-20 19:31:12 +08:00
protected virtual void Exit()
{
if (entryState is not null && entryState is IEntityMovementState state)
{
characterController.TransitionState(state);
}
else
{
characterController.TransitionState<Walk>();
}
}
2023-08-23 01:59:40 +08:00
}
}