![]() |
ShitEngine 1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
|
动画状态机 / Animator(P28) 更多...
#include <Animator.h>
Public 成员函数 | |
| Animator () | |
| ~Animator () override | |
| void | onAttach () override |
| void | onStart () override |
| 首次 update 前执行一次 | |
| void | onUpdate () override |
| 每帧执行 | |
| void | onDestroy () override |
| void | onAfterDeserialize () override |
| 反序列化完成后回调(Prefab::apply 逐组件调用一次,字段已写入)。 用于重建"直写字段绕过了 setter、无法自动触发的引擎状态"(如精灵纹理加载)。 | |
| void | onFieldChanged (const std::string &fieldName) override |
| 检查器直接写反射字段后回调(字段名)。用于绕过 setter 的直写完成后 重新同步引擎状态(如 Box2D 刚体/形状)。默认无操作。 | |
| void | setFloat (const std::string &name, float value) |
| void | setBool (const std::string &name, bool value) |
| void | setTrigger (const std::string &name) |
| int | stateCount () const |
| const AnimatorState * | stateAt (int index) const |
| int | currentStateIndex () const |
| const std::string & | currentStateName () const |
| void | setCurrentState (int index) |
| 强制切到指定状态(编辑器预览/调试用) | |
| bool | evaluateTransitions () |
| 立即求值一次转换(编辑器/运行共用;onUpdate 自动调用) | |
| int | paramCount () const |
| const AnimatorParameter * | paramAt (int index) const |
| int | addParam (const std::string &name, AnimatorParamType type) |
| bool | setParam (int index, const AnimatorParameter ¶m) |
| bool | removeParam (int index) |
| int | findParam (const std::string &name) const |
| int | addState (const std::string &name) |
| bool | setState (int index, const AnimatorState &state) |
| bool | removeState (int index) |
| 连带清理引用该状态的转换 | |
| int | transitionCount () const |
| const AnimatorTransition * | transitionAt (int index) const |
| int | addTransition (int fromState, int toState) |
| bool | setTransition (int index, const AnimatorTransition &transition) |
| bool | removeTransition (int index) |
| void | syncData () |
| 把当前 states/params/transitions 同步到 m_animatorData(编辑器修改后调用) | |
| bool | isPlaying () const |
| uint64_t | getDataGeneration () const |
| 数据代数,每次状态/参数/转换变更后递增(编辑器用于判断是否需要重建状态机图) | |
| Public 成员函数 继承自 Behavior | |
| Behavior ()=default | |
| ~Behavior () override=default | |
| void | onCreate () override |
| void | onAttach () override |
| virtual void | onFixedUpdate (float fixedDt) |
| 固定步长执行(与物理同拍;Scene 固定步循环驱动) | |
| virtual void | onCollisionEnter (GameObject *other) |
| 与 other 开始接触(每对象对一次) | |
| virtual void | onCollisionStay (GameObject *other) |
| 与 other 持续接触(每帧一次) | |
| virtual void | onCollisionExit (GameObject *other) |
| 与 other 结束接触 | |
| void | onDetach () override |
| void | onDestroy () override |
| bool | isStarted () const |
| onStart 是否已执行过 | |
| void | setStarted (bool isStarted) |
| Public 成员函数 继承自 Component | |
| Component () | |
| virtual | ~Component ()=default |
| Component (const Component &)=delete | |
| Component & | operator= (const Component &)=delete |
| Component (Component &&)=delete | |
| Component & | operator= (Component &&)=delete |
| GameObject * | getOwner () const |
| bool | isRegistered () const |
| uint64_t | getUuid () const |
| 组件持久 ID(随 .scene 序列化,是 ComponentRef<T> 引用字段的寻址依据) | |
| void | setUuid (uint64_t uuid) |
| 直接设置组件 ID(仅引擎反序列化/索引维护使用;正常流程由构造函数随机分配) | |
额外继承的成员函数 | |
| Protected 成员函数 继承自 Component | |
| void | setRegistered (bool registered) |
| Protected 属性 继承自 Behavior | |
| bool | m_isStarted = false |
| Protected 属性 继承自 Component | |
| GameObject * | m_owner = nullptr |
| bool | m_isRegistered = false |
| uint64_t | m_uuid = 0 |
| 持久 ID(构造时随机分配;0 仅在序列化前尚未赋值时短暂存在) | |
动画状态机 / Animator(P28)
继承 Behavior,由 BehaviorSystem 每帧调用 onUpdate:
条件用参数(setFloat / setBool / setTrigger)驱动——典型场景:角色 idle/run/jump 剪辑 依 speed(float)、grounded(bool)、jump(trigger)切换。
序列化:状态/参数/转换以反射字符串载体 m_animatorData(JSON)随 .scene 落盘, onAfterDeserialize / onFieldChanged 解析重建;编辑器经 addState/setState/... 修改后 syncData()。
| Animator | ( | ) |
|
override |
| int addParam | ( | const std::string & | name, |
| AnimatorParamType | type ) |
| int addState | ( | const std::string & | name | ) |
| int addTransition | ( | int | fromState, |
| int | toState ) |
|
inline |
| const std::string & currentStateName | ( | ) | const |
| bool evaluateTransitions | ( | ) |
立即求值一次转换(编辑器/运行共用;onUpdate 自动调用)
| int findParam | ( | const std::string & | name | ) | const |
|
inline |
数据代数,每次状态/参数/转换变更后递增(编辑器用于判断是否需要重建状态机图)
|
inline |
|
overridevirtual |
反序列化完成后回调(Prefab::apply 逐组件调用一次,字段已写入)。 用于重建"直写字段绕过了 setter、无法自动触发的引擎状态"(如精灵纹理加载)。
重载 Component .
|
overridevirtual |
重载 Component .
|
overridevirtual |
重载 Component .
|
overridevirtual |
检查器直接写反射字段后回调(字段名)。用于绕过 setter 的直写完成后 重新同步引擎状态(如 Box2D 刚体/形状)。默认无操作。
重载 Component .
|
overridevirtual |
首次 update 前执行一次
重载 Behavior .
|
overridevirtual |
每帧执行
重载 Behavior .
| const AnimatorParameter * paramAt | ( | int | index | ) | const |
|
inline |
| bool removeParam | ( | int | index | ) |
| bool removeState | ( | int | index | ) |
连带清理引用该状态的转换
| bool removeTransition | ( | int | index | ) |
| void setBool | ( | const std::string & | name, |
| bool | value ) |
| void setCurrentState | ( | int | index | ) |
强制切到指定状态(编辑器预览/调试用)
| void setFloat | ( | const std::string & | name, |
| float | value ) |
| bool setParam | ( | int | index, |
| const AnimatorParameter & | param ) |
| bool setState | ( | int | index, |
| const AnimatorState & | state ) |
| bool setTransition | ( | int | index, |
| const AnimatorTransition & | transition ) |
| void setTrigger | ( | const std::string & | name | ) |
| const AnimatorState * stateAt | ( | int | index | ) | const |
|
inline |
| void syncData | ( | ) |
把当前 states/params/transitions 同步到 m_animatorData(编辑器修改后调用)
| const AnimatorTransition * transitionAt | ( | int | index | ) | const |
|
inline |