RUStateTransition.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // RUStateTransition.hpp
  3. // RoleTool
  4. //
  5. // Created by 徐炼新 on 2023/4/19.
  6. //
  7. #ifndef RUStateTransition_hpp
  8. #define RUStateTransition_hpp
  9. #include "cocos2d.h"
  10. #include "RUDefine.h"
  11. #include "RUStateMachine.h"
  12. NS_RU_BEGIN
  13. class StateTransition : public cocos2d::Ref {
  14. public:
  15. static StateTransition* create(StateMachine*, const FsmTransition*, std::function<void(StateTransition*, std::function<void(void)>, bool)> cf);
  16. void setEvent(const std::string& eventName, const std::map<std::string, std::string>& eventParams, std::function<void(void)> handleEventCb);
  17. /// 终止状态转移
  18. void interrupt();
  19. /// 执行状态转移
  20. void execute();
  21. private:
  22. StateTransition() = default;
  23. std::function<void(StateTransition*, std::function<void(void)>, bool)> _cf = nullptr;
  24. StateMachine* _machine = nullptr;
  25. const FsmTransition* _transition = nullptr;
  26. void* _param = nullptr;
  27. std::string _eventName;
  28. std::map<std::string, std::string> _eventParams;
  29. std::function<void(void)> _cf4Event = nullptr;
  30. bool _bIsInterrupted = false;
  31. };
  32. NS_RU_END
  33. #endif /* RUStateTransition_hpp */