--code:zpengcheng
--Date:2020/11/20
local Warn = function(content)
print("Warn: "..content)
end
----------------------------------Event:事件对象--------------------------------------
local Event = {}
function Event:init()
self.eventName = nil
self.callBack = nil
self.target = nil
self.isOnce = false
end
function Event:create(eventName, callBack, target, isOnce)
self:init()
self.eventName = eventName
self.callBack = callBack
self.target = target
self.isOnce = isOnce
end
function Event:execute(...)
self.callBack(...)
end
----------------------------------EventMgr:事件管理器--------------------------------------
local EventMgr = {}
function EventMgr:init()
self.isDispatching = false
self.eventsMap = {} --正式列表
self.eventsReadyAdd = {} --即将要添加到正式列表的临时列表
self.eventsReadyRemove = {} --即将要从正式列表删除的临时列表
end
--[[
*外部调用方法*
注册事件:同一个事件名可以有多个界面监听,所以这里用target将不同界面分开管理,同个事件名+同个界面也可以有多个函数在
cocos2dx-lua 高效的 事件分发器(EventDispatcher)
最新推荐文章于 2023-03-08 17:55:12 发布