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

80 lines
1.6 KiB
C#
Raw Normal View History

2023-10-20 19:31:12 +08:00
using BITFALL.Player.Movement;
2024-04-19 21:43:30 +08:00
using BITKit;
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
{
2024-04-19 21:43:30 +08:00
[Inject] public PlayerCharacterController self;
2023-08-27 02:58:19 +08:00
[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()
{
2024-04-19 21:43:30 +08:00
2023-08-23 01:59:40 +08:00
}
public virtual void OnStateEntry(IState old)
{
2024-01-27 04:09:57 +08:00
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()
{
2024-04-06 16:33:57 +08:00
if ( entryState is not null)
2023-10-20 19:31:12 +08:00
{
2024-04-19 21:43:30 +08:00
if ( entryState is IPlayerWalkState or IPlayerRunState or IPlayerSprintState && self.topBlocked )
2024-04-06 16:33:57 +08:00
{
2024-04-19 21:43:30 +08:00
self.TransitionState<Crouch>();
2024-04-06 16:33:57 +08:00
}
else
{
2024-04-19 21:43:30 +08:00
self.TransitionState(entryState);
2024-04-06 16:33:57 +08:00
}
2023-10-20 19:31:12 +08:00
}
else
{
2024-04-19 21:43:30 +08:00
if (self.topBlocked)
2024-04-06 16:33:57 +08:00
{
2024-04-19 21:43:30 +08:00
self.TransitionState<Crouch>();
2024-04-06 16:33:57 +08:00
}
else
{
2024-04-19 21:43:30 +08:00
self.TransitionState<Walk>();
2024-04-06 16:33:57 +08:00
}
2023-10-20 19:31:12 +08:00
}
}
2023-08-23 01:59:40 +08:00
}
}