"use strict"; let fs = require("fs"); let path = require("path"); let count = 0; let Name = []; module.exports = { /** * 獲取場景節點下的配置信息 * @param event event * @param data 這邊把panel的Node帶進來 */ "get-default-info": function (event, request) { let self = this; // Editor.log(`example: ${JSON.stringify(args[2])}`); var response = null; let node = cc.find("Canvas"); let node_uuid = ""; if (node) { node_uuid = node.uuid; } response = JSON.stringify({ node_uuid: node_uuid }) if (event.reply) { event.reply(null, response); } }, /** * 獲取場景節點下的配置信息 * @param event event * @param data 這邊把panel的Node帶進來 */ "set-blend": function (event, request) { let Canvas = cc.find("Canvas"); var response = null; var args = request.args; let node = cc.find(args[0]._name); if (!node) { node = this.getAllChildByUuid(Canvas, args[0]._nodeID); } let Blend = args[1]; let Blend_Factor_Old = args[2]; let Blend_Factor_New = args[3]; // Editor.log(`node: ${node.name}`); // Editor.log(`Blend: ${Blend}`); // Editor.log(`Blend_Factor_Old: ${Blend_Factor_Old}`); // Editor.log(`Blend_Factor_New: ${Blend_Factor_New}`); this.SetBlend(node, Blend, +Blend_Factor_Old, +Blend_Factor_New); if (event.reply) { response = `Auto Set Blend OK Count: ${count}, Name:\n`; for (let i = 0; i < Name.length; i++) { response += `${Name[i]}\n`; } count = 0; Name = []; event.reply(null, response); } }, /** * 根據Node去尋找底下每個子節點有沒有符合的UUID * @param Node 需要搜尋的節點 */ SetBlend(Node, Blend, Blend_Factor_Old, Blend_Factor_New) { // Editor.log(`Node: ${Node.name}, childrenCount: ${Node.childrenCount}`); let cc_Sprite = Node.getComponent(cc.Sprite); if (cc_Sprite) { // Editor.log(`Node: ${Node.name}, ${Blend}: ${cc_Sprite[Blend]}`); } if (cc_Sprite && cc_Sprite[Blend] === Blend_Factor_Old) { // Editor.log(`Node: ${Node.name}, ${Blend}_Old: ${cc_Sprite[Blend]}, ${Blend}_New: ${Blend_Factor_New}`); cc_Sprite[Blend] = Blend_Factor_New; count++; Name.push(Node.name); } for (let i = 0; i < Node.childrenCount; i++) { this.SetBlend(Node.children[i], Blend, Blend_Factor_Old, Blend_Factor_New); } }, /** * 根據Node去尋找底下每個子節點有沒有符合的UUID * @param Node 需要搜尋的節點 * @param UUID 目標的UUID */ getAllChildByUuid(Node, UUID) { for (let i = 0; i < Node.childrenCount; i++) { // Editor.log("Node: " + Node.name, "UUID: " + Node.uuid); if (Node.uuid == UUID) { // Editor.log("找到 Node: " + Node.name, "UUID: " + Node.uuid); return Node; } else { // Editor.log("Node: " + Node.children[i].name, "UUID: " + Node.children[i].uuid); if (Node.children[i].uuid == UUID) { return Node.children[i]; } } if (Node.children[i].childrenCount > 0) { // Editor.log(Node.children[i].name + " childrenCount > 0"); let getAllChildByUuid = this.getAllChildByUuid(Node.children[i], UUID); if (getAllChildByUuid) { return getAllChildByUuid; } } } // Editor.log("Node: " + Node.children[1].childrenCount); return null; }, };