"use strict"; cc._RF.push(module, 'd8e414s0vVKOpdfY2LEw+kL', 'cmp.plot.trigger'); // Scripts/mod/plot/triggers/cmp.plot.trigger.js "use strict"; /****************************************************************** * 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 onLoad() { // 触发器注册 this.regist(); }, // 显示 onEnable: function onEnable() { var _this = this; // 开启事件 if (nx.dt.strNEmpty(this.openKey)) { this.scheduleOnce(function () { nx.bridge.plot.postKey(_this.openKey); }, 0.01); } // 剧情触发 this.tryFire(); }, // 关闭 onDisable: function onDisable() { // 关闭事件 if (nx.dt.strNEmpty(this.closeKey)) { nx.bridge.plot.postKey(this.closeKey); } }, // 销毁 onDestroy: function onDestroy() { // 触发器注销 if (window.nx && nx.dt.strNEmpty(this.pID)) { nx.bridge.plot.unregUnit(this.pID); } }, // 触发器注册 regist: function regist() { var _this2 = this; if (nx.dt.strEmpty(this.pID)) { return; } this.refNode = this.refNode || this.node; nx.bridge.plot.regUnit(this.pID, this.refNode, function (_args) { _this2.doTouch(_args); }); }, // 剧情触发 tryFire: function tryFire() { if (nx.dt.arrEmpty(this.fireIds)) { return; } var ids = nx.dt.objClone(this.fireIds); var pop = function pop() { if (nx.dt.arrEmpty(ids)) { return; } nx.bridge.plot.fire(ids.shift(), function (_ret, _data) { if (!_ret) { pop(); } }); }; this.scheduleOnce(function () { pop(); }, 0.05); }, // 执行点击 doTouch: function doTouch() { // 执行方法 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); } } }); cc._RF.pop();