8#include <nlohmann/json.hpp>
96 void setFloat(
const std::string& name,
float value);
97 void setBool(
const std::string& name,
bool value);
101 int stateCount()
const {
return static_cast<int>(m_states.size()); }
110 int paramCount()
const {
return static_cast<int>(m_params.size()); }
140 void enterState(
int index);
144 void notifyDataChanged();
146 void applyCurrentFrame();
152 SHIT_META(({.displayName =
"Animator Data", .tooltip =
"状态机序列化载体(JSON),由编辑器维护"}))
153 std::string m_animatorData;
157 std::vector<AnimatorState> m_states;
159 std::vector<AnimatorParameter> m_params;
161 std::vector<AnimatorTransition> m_transitions;
164 int m_currentState = -1;
166 std::unique_ptr<Animation> m_currentAnimation;
168 float m_animTime = 0.0f;
170 bool m_isPlaying =
false;
173 uint64_t m_dataGeneration = 0;
176 SHIT_META(({.displayName =
"Current State", .readOnly =
true}))
177 std::string m_currentStateDisplay;
178 SHIT_META(({.displayName =
"Playing", .readOnly =
true}))
179 bool m_playingDisplay =
false;
#define SHIT_API
定义 Core.h:14
#define SHIT_REFLECT_BODY(Type)
定义 Macros.h:89
#define SHIT_REFLECT(Mode)
定义 Macros.h:86
#define SHIT_META(...)
定义 Macros.h:95
void onStart() override
首次 update 前执行一次
const AnimatorState * stateAt(int index) const
uint64_t getDataGeneration() const
数据代数,每次状态/参数/转换变更后递增(编辑器用于判断是否需要重建状态机图)
定义 Animator.h:136
bool isPlaying() const
定义 Animator.h:134
const AnimatorParameter * paramAt(int index) const
int currentStateIndex() const
定义 Animator.h:103
bool removeState(int index)
连带清理引用该状态的转换
int stateCount() const
定义 Animator.h:101
int addState(const std::string &name)
bool setTransition(int index, const AnimatorTransition &transition)
bool evaluateTransitions()
立即求值一次转换(编辑器/运行共用;onUpdate 自动调用)
const std::string & currentStateName() const
int paramCount() const
定义 Animator.h:110
void setCurrentState(int index)
强制切到指定状态(编辑器预览/调试用)
void onAfterDeserialize() override
反序列化完成后回调(Prefab::apply 逐组件调用一次,字段已写入)。 用于重建"直写字段绕过了 setter、无法自动触发的引擎状态"(如精灵纹理加载)。
void setTrigger(const std::string &name)
void syncData()
把当前 states/params/transitions 同步到 m_animatorData(编辑器修改后调用)
int addParam(const std::string &name, AnimatorParamType type)
void setFloat(const std::string &name, float value)
bool removeParam(int index)
void setBool(const std::string &name, bool value)
void onFieldChanged(const std::string &fieldName) override
检查器直接写反射字段后回调(字段名)。用于绕过 setter 的直写完成后 重新同步引擎状态(如 Box2D 刚体/形状)。默认无操作。
int transitionCount() const
定义 Animator.h:123
bool setState(int index, const AnimatorState &state)
const AnimatorTransition * transitionAt(int index) const
void onUpdate() override
每帧执行
bool setParam(int index, const AnimatorParameter ¶m)
void onDestroy() override
int findParam(const std::string &name) const
bool removeTransition(int index)
int addTransition(int fromState, int toState)
AnimatorParamType
动画参数类型(状态机条件变量);以 int 存 JSON 载体,无需反射
定义 Animator.h:19
@ Float
浮点(比较 threshold)
定义 Animator.h:20
@ Bool
布尔(比较 boolValue)
定义 Animator.h:21
@ Trigger
触发器(一次性触发,转换求值后消耗)
定义 Animator.h:22
AnimatorConditionType
条件类型(转换求值);以 int 存 JSON 载体,无需反射
定义 Animator.h:34
@ FloatLt
float < threshold
定义 Animator.h:36
@ FloatEq
|float - threshold| < 0.001
定义 Animator.h:37
@ FloatGt
float > threshold
定义 Animator.h:35
动画剪辑(可序列化数据,P28)
定义 AnimationClip.h:31
动画参数(可序列化)
定义 Animator.h:26
std::string name
定义 Animator.h:27
AnimatorParamType type
定义 Animator.h:28
bool boolValue
Bool 当前值 / Trigger 触发标志
定义 Animator.h:30
float floatValue
Float 当前值
定义 Animator.h:29
状态机节点(可序列化)
定义 Animator.h:51
float graphY
状态机图节点 Y(编辑器布局用,随 .scene 保存)
定义 Animator.h:57
float graphX
状态机图节点 X(编辑器布局用,随 .scene 保存)
定义 Animator.h:56
bool isEntry
是否入口状态(onStart 优先进入)
定义 Animator.h:55
std::string assetPath
引用的 .anim 资产路径(序列化字段;空 = 旧场景内嵌 clip,向后兼容)
定义 Animator.h:54
std::string name
状态名
定义 Animator.h:52
AnimationClip clip
运行时剪辑缓存(从 .anim 文件加载,不入序列化)
定义 Animator.h:53
转换的单个条件(引用参数名)
定义 Animator.h:43
float threshold
Float 阈值
定义 Animator.h:46
AnimatorConditionType type
定义 Animator.h:45
std::string parameter
参数名
定义 Animator.h:44
bool boolValue
Bool 期望值
定义 Animator.h:47
状态间转换(可序列化;同一状态可有多条,按序求值)
定义 Animator.h:61
int fromState
源状态索引(-1 = 任意)
定义 Animator.h:62
int toState
目标状态索引
定义 Animator.h:63
std::vector< AnimatorTransitionCondition > conditions
全部满足才切换
定义 Animator.h:64
float exitTime
保留:切换延迟(秒),当前实现立即切换
定义 Animator.h:65