75 lines
1.8 KiB
JavaScript
75 lines
1.8 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '50f727/9A9K15JhCZzFb/Ot', 'bridge.component');
|
|
// Scripts/zbridge/ui/bridge.component.js
|
|
|
|
"use strict";
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* 老版本桥接过渡 --- 给cc.Component增加一些兼容特性
|
|
*
|
|
*
|
|
******************************************************************************/
|
|
|
|
cc.Class({
|
|
"extends": cc.Component,
|
|
properties: {},
|
|
// 载入
|
|
onLoad: function onLoad() {
|
|
// 事件监听句柄
|
|
this.eHandlers = [];
|
|
},
|
|
// 销毁
|
|
onDestroy: function onDestroy() {
|
|
// 监听事件释放
|
|
this.unbindGEvents();
|
|
|
|
// 视图监听释放
|
|
this.vunbind();
|
|
},
|
|
// 关闭前
|
|
onPreClosed: function onPreClosed() {},
|
|
// 全局事件监听
|
|
bindGEvent: function bindGEvent(_id, _cb) {
|
|
this.eHandlers = this.eHandlers || [];
|
|
|
|
// 重复性检查
|
|
if (CC_DEBUG) {
|
|
for (var i in this.eHandlers) {
|
|
var binder = this.eHandlers[i];
|
|
if (binder && binder.id == _id) {
|
|
nx.error("[BridgeComponent]重复监听事件:", _id);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
var tag = gcore.GlobalEvent.bind(_id, _cb);
|
|
this.eHandlers.push({
|
|
id: _id,
|
|
tag: tag
|
|
});
|
|
},
|
|
// 全局监听解除(一次性)
|
|
unbindGEvents: function unbindGEvents() {
|
|
if (window.nx && nx.dt.arrNEmpty(this.eHandlers)) {
|
|
this.eHandlers.forEach(function (_binder) {
|
|
gcore.GlobalEvent.unbind(_binder.tag);
|
|
});
|
|
this.eHandlers = [];
|
|
}
|
|
},
|
|
// 桥接视图监听
|
|
vbind: function vbind(_lst) {
|
|
if (nx.bridge && nx.dt.arrNEmpty(_lst)) {
|
|
nx.bridge.vbind(this, _lst);
|
|
}
|
|
},
|
|
// 桥接监听视图解除
|
|
vunbind: function vunbind() {
|
|
if (window.nx && nx.bridge) {
|
|
nx.bridge.vunbind(this);
|
|
}
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |