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