scene-info.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. 'use strict';
  2. let eventFuncs =
  3. {
  4. 'setActive'(event){
  5. let nodes = Editor.Selection.getSelected('node');
  6. if (nodes && nodes.length != 0)
  7. {
  8. let active = this.findNode(nodes[0]).active;
  9. for (let i = 0; i < nodes.length; i++)
  10. {
  11. const id = nodes[i];
  12. let node = this.findNode(id)
  13. if(node){
  14. // node.active = active;
  15. this.setNodeActive(node.uuid,!active)
  16. }
  17. }
  18. // Editor.Ipc.sendToAll('scene:undo-commit');
  19. Editor.Message.send('scene','snapshot')
  20. }
  21. },
  22. // 显示选择node同时隐藏同层node
  23. 'setActiveRadio'(event){
  24. let nodes = Editor.Selection.getSelected('node');
  25. if (nodes && nodes.length != 0)
  26. {
  27. let node = this.findNode(nodes[0]);
  28. if(node.parent){
  29. for (let i = 0; i < node.parent.children.length; i++)
  30. {
  31. const childrenNode = node.parent.children[i];
  32. if(!childrenNode._objFlags){
  33. // childrenNode.active = childrenNode != node ? !active : active;
  34. const isSelectUuid = nodes.includes(childrenNode.uuid)
  35. this.setNodeActive(childrenNode.uuid,isSelectUuid ? true : false)
  36. }
  37. }
  38. // Editor.Ipc.sendToAll('scene:undo-commit');
  39. Editor.Message.send('scene','snapshot')
  40. }
  41. }
  42. },
  43. setNodeActive(uuid,active){
  44. Editor.Message.send('scene', 'set-property',{
  45. uuid: uuid,
  46. path: 'active',//要修改的属性
  47. dump: {
  48. type: typeof active, // "bool",
  49. isArray: false,//是否数组
  50. value: active // uuid
  51. }
  52. });
  53. },
  54. // 检测场景是否存在该子节点并返回相关信息
  55. findNode(select_uuid)
  56. {
  57. var canvas = cc.director.getScene();
  58. var ret_node
  59. if (canvas && select_uuid) {
  60. this.getNodeChildren(canvas,(node)=>{
  61. if (node.uuid == select_uuid){
  62. ret_node = node;
  63. return ret_node;
  64. }
  65. })
  66. }
  67. return ret_node;
  68. },
  69. // 遍历所有深层子节点
  70. getNodeChildren(node,callFunc)
  71. {
  72. if (!node) return;
  73. let nodes = node.children;
  74. nodes.forEach((v)=>{
  75. this.getNodeChildren(v,callFunc)
  76. });
  77. callFunc(node)
  78. },
  79. };
  80. // 模块加载的时候触发的函数
  81. exports.load = function() {};
  82. // 模块卸载的时候触发的函数
  83. exports.unload = function() {};
  84. exports.methods = eventFuncs;