OutputComponent/scene-obtain.js

89 lines
3.4 KiB
JavaScript
Raw Normal View History

2022-03-31 00:58:55 +00:00
"use strict";
module.exports = {
/**
* 獲取場景節點下的配置信息
* @param event event
* @param data 這邊把panel的Node帶進來
*/
"get-scene-info": function (event, data) {
var node = cc.find(data.node._name);
if (!node) {
var can = cc.find("Canvas");
node = this.getAllChildByUuid(can, data.node._nodeID);
}
let objArray = [];
if (node) {
Editor.log("Node:" + node.name);
let singleInfo = this.setObjInfo(node, 0, can);
objArray = (singleInfo);
} else {
Editor.log("沒有找到節點");
}
let json = JSON.stringify(objArray);
if (event.reply) {
event.reply(null, json);
}
},
/**
* 把節點需要輸出的資料設置到每個json
* @param Node 需要取得資料的節點
*/
setObjInfo(Node) {
let PhysicsPolygonCollider = Node.getComponent(cc.PhysicsPolygonCollider);
let Points = JSON.parse("[]");
let count = 0;
if (PhysicsPolygonCollider) {
for (let i = 0; i < PhysicsPolygonCollider.points.length; i++) {
Points[count] = JSON.parse("[]");
Points[count][0] = PhysicsPolygonCollider.points[i].x;
Points[count][1] = PhysicsPolygonCollider.points[i].y;
count++;
}
Editor.log("Points: " + JSON.stringify(Points));
} else {
Editor.log("沒有PhysicsPolygonCollider這個Component!!");
Node.addComponent(cc.PhysicsPolygonCollider);
Editor.log("已增加PhysicsPolygonCollider!!");
PhysicsPolygonCollider = Node.getComponent(cc.PhysicsPolygonCollider);
for (let i = 0; i < PhysicsPolygonCollider.points.length; i++) {
Points[count] = JSON.parse("[]");
Points[count][0] = PhysicsPolygonCollider.points[i].x;
Points[count][1] = PhysicsPolygonCollider.points[i].y;
count++;
}
Editor.log("Points: " + JSON.stringify(Points));
}
return Points;
},
/**
* 根據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;
},
};