扩展包遍历多个场景并依次操作和保存只保存最后一个场景

v2.0.2 扩展包遍历多个场景并依次操作和保存只保存最后一个场景
https://docs.cocos.com/creator/manual/zh/extension/asset-management.html


NewProject.zip (576.5 KB)

每次遍历场景时用 Editor.Ipc.sendToPanel(‘scene’, ‘scene:stash-and-save’); 来保存,发现只保存最后一个场景。
以下为demo,点击 扩展->test_plugin->hello 会触发 scene-walker.js的get-canvas-children消息
@jare
上传中…

目前需要的功能:遍历预制和场景,批量修改并保存。

真想吐槽一下,做插件开发,文档少而不全,api得自己去找或者在别人的插件里找,在痛苦的边缘中挣扎。

只有场景激活的状态下,才能更新场景数据,所以必须等待scene:stash-and-save成功返回后,才能继续操作。

  var uuids = [];
  results.forEach(function(result) {
    uuids.push(result.uuid);
  });

  var callFunc = function() {
    if (uuids.length <= 0) return;

    var uuid = uuids.shift();
    _Scene.loadSceneByUuid(uuid, function(error) {
      let canvas = cc.find("Canvas");

      let node = new cc.Node();
      node.name = "newNode";
      node.parent = canvas;
      Editor.Ipc.sendToPanel("scene", "scene:stash-and-save", function() {
        setTimeout(callFunc, 1);
        console.log("-------");
      });
    });
  };

  callFunc();
});

这个保存场景的回调回来好慢啊,有什么方式能加快吗:joy: