Cocos Creator Editor 执行场景脚本
package.json
{
"name": "scene-tools",
"version": "1.0.0",
"description": "scene-tools",
"author": "kingBook",
"main": "main.js",
"main-menu": {
"Tools/Execute scene-tools":{
"message":"scene-tools:menu-execute-scene-tools"
}
},
"scene-script":"scene-walker.js"
}
main.js
'use strict';
module.exports={
load(){
//当 package 被正确加载的时候执行
},
unload(){
//当 package 被正确卸载的时候执行
},
messages:{
//执行菜单'Tools/Execute scene-tools'时调用
'scene-tools:menu-execute-scene-tools'(){
module.exports.onExecute();
}
},//end messages
onExecute(){
//调用场景脚本 scene-walker.js 的 'test-scene-walker' 方法,并在回调函数中得到结果
Editor.Scene.callSceneScript("scene-tools","test-scene-walker",{num:9},(result)=>{
Editor.log(result.sceneName+", "+result.sqrt);
});
}
};
scene-walker.js
module.exports={
'test-scene-walker':function(event,data){
let scene=cc.director.getScene();
//回调
if (event.reply) {
let result={};
result.sceneName=scene.name;
result.sqrt=Math.sqrt(data.num);
event.reply(result);
}
}
};
package.json
main.js
scene-walker.js
三个文件都放入 ${项目文件夹}\scene-tools