scene_ex.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. *场景逻辑扩展
  3. *删除选中的节点以及节点所绑定的脚本
  4. */
  5. 'use strict';
  6. var path = require('path');
  7. var fs = require('fs');
  8. var md5 = require('md5');
  9. const fe = Editor.require('packages://simple-code/tools/tools.js');
  10. module.exports = {
  11. /************* 事件 *************/
  12. messages:
  13. {
  14. // 删除选中的节点以及节点所绑定的脚本
  15. 'removeNodeAndScript'(event,args,parent)
  16. {
  17. let hitnText = ""
  18. let chidlren = parent.getSelectdNodes()
  19. let nodeUuids = []
  20. let jsInfos = []
  21. chidlren.forEach((node)=>
  22. {
  23. let jsComp = parent.isHasJsFile(node)
  24. if (jsComp) {
  25. let info = Editor.remote.assetdb.assetInfoByUuid(jsComp.__scriptUuid)
  26. if (info){
  27. jsInfos.push(info)
  28. hitnText += info.url+"\n"
  29. }
  30. // 移除组件绑定
  31. // Editor.Ipc.sendToPanel('scene', 'scene:remove-component', node.uuid,jsComp.uuid);//移除不了脚本
  32. }
  33. nodeUuids.push(node.uuid)
  34. // node.removeFromParent(true)
  35. })
  36. if (!confirm("确定删除选中的节点以及节点所绑定的脚本? 该删除操作不可撤销或重做!删除的脚本将备份到:"+ Editor.remote.assetdb.assetBackupPath+"\n将删除以下脚本:\n"+hitnText)){
  37. return
  38. }
  39. // 删除节点s
  40. Editor.Ipc.sendToPanel('scene', 'scene:delete-nodes', nodeUuids);
  41. // 备份文件
  42. let files = []
  43. jsInfos.forEach((info)=>{
  44. let pathB = info.url.replace("db:/","")
  45. let move_to_path = Editor.remote.assetdb.assetBackupPath+pathB.replace(/\//g,path.sep)
  46. files.push(info.url)
  47. // 备份
  48. fe.createDir(move_to_path)
  49. fe.copyFile(info.path,move_to_path+"_"+(new Date).getTime());
  50. Editor.log("移除文件到备份目录:",info.path,move_to_path)
  51. });
  52. // 删除文件
  53. Editor.remote.assetdb.delete(files);
  54. },
  55. 'get-active-uuid'(event,args,parent){
  56. // Editor.log("scene test")
  57. }
  58. }
  59. };