126 lines
2.9 KiB
JavaScript
126 lines
2.9 KiB
JavaScript
|
|
/******************************************************************
|
||
|
|
* Copyright(C) 2019 - 2020 Nx Studio
|
||
|
|
*
|
||
|
|
* 剧情/引导 触发器
|
||
|
|
*
|
||
|
|
*
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
cc.Class( {
|
||
|
|
|
||
|
|
extends: cc.Component,
|
||
|
|
|
||
|
|
properties: {
|
||
|
|
refNode: { default: null, type: cc.Node, displayName: "锚定节点" },
|
||
|
|
pID: { default: "", displayName: "唯一标识" },
|
||
|
|
fireIds: { default: [], type: cc.String, displayName: "触发列表" },
|
||
|
|
openKey: { default: "", displayName: "开启事件" },
|
||
|
|
closeKey: { default: "", displayName: "关闭事件" },
|
||
|
|
fireEvent: { default: [], type: cc.Component.EventHandler, displayName: "触发处理" },
|
||
|
|
},
|
||
|
|
|
||
|
|
// 编辑器特性
|
||
|
|
editor: {
|
||
|
|
// menu 用来将当前组件添加到组件菜单中,方便用户查找
|
||
|
|
menu: "老版桥接/剧情元素",
|
||
|
|
},
|
||
|
|
|
||
|
|
// 载入
|
||
|
|
onLoad: function() {
|
||
|
|
|
||
|
|
// 触发器注册
|
||
|
|
this.regist();
|
||
|
|
},
|
||
|
|
|
||
|
|
// 显示
|
||
|
|
onEnable: function() {
|
||
|
|
|
||
|
|
// 开启事件
|
||
|
|
if( nx.dt.strNEmpty( this.openKey ) ) {
|
||
|
|
this.scheduleOnce( ()=> {
|
||
|
|
nx.bridge.plot.postKey( this.openKey );
|
||
|
|
}, 0.01 );
|
||
|
|
}
|
||
|
|
|
||
|
|
// 剧情触发
|
||
|
|
this.tryFire();
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 关闭
|
||
|
|
onDisable: function() {
|
||
|
|
|
||
|
|
// 关闭事件
|
||
|
|
if( nx.dt.strNEmpty( this.closeKey ) ) {
|
||
|
|
nx.bridge.plot.postKey( this.closeKey );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// 销毁
|
||
|
|
onDestroy: function() {
|
||
|
|
|
||
|
|
// 触发器注销
|
||
|
|
if( window.nx && nx.dt.strNEmpty( this.pID ) ) {
|
||
|
|
nx.bridge.plot.unregUnit( this.pID );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// 触发器注册
|
||
|
|
regist: function() {
|
||
|
|
|
||
|
|
if( nx.dt.strEmpty( this.pID ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.refNode = this.refNode || this.node;
|
||
|
|
nx.bridge.plot.regUnit( this.pID, this.refNode, ( _args ) => {
|
||
|
|
this.doTouch( _args );
|
||
|
|
} );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 剧情触发
|
||
|
|
tryFire: function() {
|
||
|
|
|
||
|
|
if( nx.dt.arrEmpty( this.fireIds ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
let ids = nx.dt.objClone( this.fireIds );
|
||
|
|
let pop = function() {
|
||
|
|
|
||
|
|
if( nx.dt.arrEmpty( ids ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
nx.bridge.plot.fire( ids.shift(), ( _ret, _data ) => {
|
||
|
|
if( !_ret ) {
|
||
|
|
pop();
|
||
|
|
}
|
||
|
|
} )
|
||
|
|
};
|
||
|
|
|
||
|
|
this.scheduleOnce( ()=> {
|
||
|
|
pop();
|
||
|
|
}, 0.05 );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 执行点击
|
||
|
|
doTouch: function() {
|
||
|
|
|
||
|
|
// 执行方法
|
||
|
|
if( nx.dt.arrNEmpty( this.fireEvent ) ) {
|
||
|
|
for( var i = 0; i < this.fireEvent.length; ++i ) {
|
||
|
|
var te = this.fireEvent[ i ];
|
||
|
|
if( te && te.customEventData === "" ) {
|
||
|
|
te.customEventData = this.node;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
cc.Component.EventHandler.emitEvents( this.fireEvent );
|
||
|
|
}
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
} );
|