新增角色状态机框架,包含空闲、移动、跳跃、攻击等状态 添加输入路由组件,统一处理键盘和手柄输入 引入动作库管理角色动作定义,支持PVF脚本配置 重构角色对象,整合运动器、状态机和输入处理 修复Actor子节点排序时的迭代安全问题
60 lines
2.2 KiB
C++
60 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include "character/CharacterActionLibrary.h"
|
|
|
|
namespace frostbite2D {
|
|
|
|
class CharacterObject;
|
|
|
|
/// 角色主状态机。输入先变成意图,再由状态机决定当前大状态和动作推进。
|
|
class CharacterStateMachine {
|
|
public:
|
|
void Reset();
|
|
void Update(CharacterObject& owner,
|
|
CharacterCommandBuffer& commandBuffer,
|
|
const CharacterIntent& intent,
|
|
float deltaTime);
|
|
void ForceHurt(const CharacterActionDefinition* hurtAction);
|
|
|
|
CharacterStateId GetState() const { return currentState_; }
|
|
const std::string& GetCurrentActionId() const { return currentActionId_; }
|
|
const CharacterActionDefinition* GetCurrentActionDefinition() const {
|
|
return currentAction_;
|
|
}
|
|
|
|
bool CanAcceptGroundActions() const;
|
|
bool CanBeInterrupted() const;
|
|
bool IsMovementLocked() const;
|
|
bool CanTurn() const;
|
|
|
|
private:
|
|
void ChangeState(CharacterObject& owner, CharacterStateId nextState);
|
|
void EnterAction(CharacterObject& owner, const CharacterActionDefinition* action);
|
|
void UpdateGroundState(CharacterObject& owner,
|
|
CharacterCommandBuffer& commandBuffer,
|
|
const CharacterIntent& intent);
|
|
void UpdateAirState(CharacterObject& owner,
|
|
CharacterCommandBuffer& commandBuffer,
|
|
const CharacterIntent& intent);
|
|
void UpdateActionState(CharacterObject& owner,
|
|
CharacterCommandBuffer& commandBuffer,
|
|
const CharacterIntent& intent,
|
|
float deltaTime);
|
|
void UpdateHurtState(CharacterObject& owner, float deltaTime);
|
|
bool TryStartAction(CharacterObject& owner,
|
|
CharacterCommandBuffer& commandBuffer,
|
|
CharacterCommandType commandType,
|
|
const std::string& actionId);
|
|
void ApplyFrameEvents(CharacterObject& owner, int previousFrame, int currentFrame);
|
|
|
|
CharacterStateId currentState_ = CharacterStateId::Idle;
|
|
std::string currentActionId_;
|
|
const CharacterActionDefinition* currentAction_ = nullptr;
|
|
float stateTime_ = 0.0f;
|
|
float actionFrameProgress_ = 0.0f;
|
|
int actionFrame_ = 0;
|
|
float landingTimer_ = 0.0f;
|
|
};
|
|
|
|
} // namespace frostbite2D
|