script.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. CMD:
  2. console.log("====>>>>远程脚本加载成功");
  3. function printNodesCount() {
  4. var cScene = cc.director.getScene();
  5. let scene = cc.director.getScene();
  6. let layersCount = scene.childrenCount;
  7. console.log("图层数量:", layersCount);
  8. function getTotalComponentsCount(node) {
  9. let count = node.getComponents(cc.Component).length;
  10. node.children.forEach(childNode => {
  11. count += getTotalComponentsCount(childNode);
  12. });
  13. return count;
  14. }
  15. // 使用当前场景的根节点作为起点
  16. let totalComponents = getTotalComponentsCount(scene);
  17. console.log("场景中的组件总数量:", totalComponents);
  18. }
  19. function printAllNodes() {
  20. function printNodePath(node, path = '') {
  21. // 构建当前节点的路径
  22. let currentPath = path ? `${path}/${node.name}` : node.name;
  23. console.log(currentPath); // 打印当前节点的路径
  24. lws.send(currentPath);
  25. // 遍历子节点
  26. node.children.forEach((child) => {
  27. printNodePath(child, currentPath);
  28. });
  29. }
  30. // 获取当前场景的根节点并开始遍历
  31. let scene = cc.director.getScene();
  32. scene.children.forEach((child) => {
  33. // 假设每个直接子节点都是一个“图层”
  34. printNodePath(child);
  35. });
  36. }
  37. function printClickAbleNodes() {
  38. function printNodePath(node, path = '') {
  39. // 构建当前节点的路径
  40. let currentPath = path ? `${path}/${node.name}` : node.name;
  41. // 检查节点是否有 cc.Button 组件,这意味着它监听了点击事件
  42. let buttonComponent = node.getComponent(cc.Button);
  43. // 可以根据需要,检查其他组件,如 cc.ScrollView 等
  44. if (buttonComponent) {
  45. console.log(currentPath); // 打印当前节点的路径
  46. lws.send(currentPath);
  47. }
  48. // 遍历子节点
  49. node.children.forEach((child) => {
  50. printNodePath(child, currentPath);
  51. });
  52. }
  53. // 获取当前场景的根节点并开始遍历
  54. let scene = cc.director.getScene();
  55. scene.children.forEach((child) => {
  56. printNodePath(child);
  57. });
  58. }
  59. function enterGame() {
  60. // 点击扑克大师游戏
  61. let pokerMasterGame = cc.find("Canvas/container/content/smallGame/createScrollView/view/cotent/row1/pokerNode/porkermaster/allHand");//进入大师线路列表
  62. //let pokerMasterGame = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/btn_down");//大师线路列表按钮下降
  63. // 检查节点是否找到以及是否有cc.Button组件
  64. if (pokerMasterGame && pokerMasterGame.getComponent(cc.Button)) {
  65. // 模拟点击事件
  66. pokerMasterGame.getComponent(cc.Button).clickEvents[0].emit([pokerMasterGame]);
  67. } else {
  68. // console.error("节点未找到或节点上没有cc.Button组件");
  69. console.error("未找到扑克大师游戏");
  70. }
  71. // 点击扑克大师游戏线路1
  72. let pokerMasterGameLine1 = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/main/view/content/item/main");//线路1
  73. if (pokerMasterGameLine1 && pokerMasterGameLine1.getComponent(cc.Button)) {
  74. // 模拟点击事件
  75. pokerMasterGameLine1.getComponent(cc.Button).clickEvents[0].emit([pokerMasterGameLine1]);
  76. } else {
  77. // console.error("节点未找到或节点上没有cc.Button组件");
  78. console.error("未找到扑克大师游戏游戏节点1");
  79. }
  80. }
  81. function showDialogAndClose() {
  82. // 点击显示退出弹窗
  83. let btn_menu = cc.find("PokerMasterScene/btn_menu");//进入大师线路列表
  84. //let btn_menu = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/btn_down");//大师线路列表按钮下降
  85. // 检查节点是否找到以及是否有cc.Button组件
  86. if (btn_menu && btn_menu.getComponent(cc.Button)) {
  87. // 模拟点击事件
  88. btn_menu.getComponent(cc.Button).clickEvents[0].emit([]);
  89. } else {
  90. // console.error("节点未找到或节点上没有cc.Button组件");
  91. console.error("未找到显示弹出");
  92. }
  93. // 点击扑克大师游戏线路1
  94. // let pokerMasterGameLine1 = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/main/view/content/item/main");//线路1
  95. // if (pokerMasterGameLine1 && pokerMasterGameLine1.getComponent(cc.Button)) {
  96. // // 模拟点击事件
  97. // pokerMasterGameLine1.getComponent(cc.Button).clickEvents[0].emit([pokerMasterGameLine1]);
  98. // } else {
  99. // // console.error("节点未找到或节点上没有cc.Button组件");
  100. // console.error("未找到扑克大师游戏游戏节点1");
  101. // }
  102. }
  103. //printClickAbleNodes();
  104. //enterGame();
  105. //printAllNodes();
  106. //printNodesCount();
  107. //lws.send("存到本地");
  108. console.log("====>>>>远程脚本加载结束");