85 lines
1.8 KiB
JavaScript
85 lines
1.8 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'ffa70GlJQBG6o3SqYEbaTlc', 'nx.plugin.event');
|
|
// Scripts/nx/plugin/nx.plugin.event.js
|
|
|
|
"use strict";
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* 代理: 事件
|
|
*
|
|
*
|
|
*
|
|
* 2021.12.10
|
|
******************************************************************************/
|
|
|
|
// 功能安装
|
|
var install = function install(_inst) {
|
|
// 对象非法
|
|
if (nx.dt.objEmpty(_inst)) {
|
|
nx.error("[事件插件]安装失败,对象非法!");
|
|
return false;
|
|
}
|
|
|
|
// 重复安装
|
|
if (nx.dt.arrGood(_inst.lstEvent)) {
|
|
nx.error("[事件插件]安装失败,重复安装!");
|
|
return false;
|
|
}
|
|
|
|
// 安装
|
|
_inst.lstEvent = [];
|
|
|
|
// 事件监听
|
|
nx.dt.fnEmptyError(_inst.bindEvent);
|
|
_inst.bindEvent = function (_list) {
|
|
// 重复
|
|
if (nx.dt.arrNEmpty(_inst.lstEvent)) {
|
|
nx.error("[事件插件]重复监听事件.");
|
|
return;
|
|
}
|
|
_inst.lstEvent = _list;
|
|
if (nx.dt.arrNEmpty(_list)) {
|
|
nx.event.bind(_inst, _list);
|
|
}
|
|
};
|
|
|
|
// 事件监听解除
|
|
nx.dt.fnEmptyError(_inst.unbindEvent);
|
|
_inst.unbindEvent = function () {
|
|
_inst.lstEvent = [];
|
|
nx.event.unbind(_inst);
|
|
};
|
|
|
|
// 事件发布
|
|
nx.dt.fnEmptyError(_inst.sendEvent);
|
|
_inst.sendEvent = function (_eid, _args) {
|
|
nx.event.send(_eid, _args);
|
|
};
|
|
return true;
|
|
};
|
|
|
|
// 功能卸载
|
|
var uninstall = function uninstall(_inst) {
|
|
// 对象非法
|
|
if (nx.dt.objEmpty(_inst)) {
|
|
nx.error("[事件插件]安装视图插件失败,对象非法!");
|
|
return false;
|
|
}
|
|
|
|
// 取消监听
|
|
_inst.unbindEvent();
|
|
|
|
// 卸载
|
|
delete _inst.lstEvent;
|
|
delete _inst.bindEvent;
|
|
delete _inst.unbindEvent;
|
|
delete _inst.sendEvent;
|
|
return true;
|
|
};
|
|
module.exports = {
|
|
install: install,
|
|
uninstall: uninstall
|
|
};
|
|
|
|
cc._RF.pop(); |