状态机实现
环境: quick-cocos
简述:提供状态列表设置的接口setupState(),状态列表中包含状态名称及相关调用函数,提供执行状态函数doEvent()
1. 在状态的execute函数内编写状态切换判断的逻辑,该函数在对象重写并传入到对象的内建状态机。
2. myStateMachine继承自quick的Component类(含有事件派发机制)
代码:basestate
local BaseState = class("BaseState")
function BaseState:ctor(str)
self.name = str
self.stateFuncList = {}
end
local _stateFuncList = {
["Enter"] = {callFunc = function () print("need init Enter") end},
["Execute"] = {callFunc = function () print("need init Execute") end},
["Exit"] = {callFunc = function () print("need init Exit") end},