完成大致的版本

This commit is contained in:
xuyanfeng 2021-04-05 19:31:34 +08:00
parent 36a81db153
commit 3ea0aa9379
5 changed files with 122 additions and 207 deletions

View File

@ -50,65 +50,6 @@ export default class NodeBaseProperty extends Vue {
} }
} }
changeSizeActionWidth(step: number) {
let w = parseFloat(this.itemData.width);
// this.itemData.width = w + step;
this.changeSize();
}
changeSizeActionHeight(step: number) {
let h = parseFloat(this.itemData.height);
// this.itemData.height = h + step;
this.changeSize();
}
changePositionActionX(step: number) {
let x = parseFloat(this.itemData.x);
// this.itemData.x = x + step;
this.changePosition();
}
changePositionActionY(step: number) {
let y = parseFloat(this.itemData.y);
// this.itemData.y = y + step;
this.changePosition();
}
changePosition() {
this._evalCode(
"window.ccinspector.pluginSetNodePosition(" +
"'" + this.itemData.uuid + "'," +
"'" + this.itemData.x + "'," +
"'" + this.itemData.y + "'" +
")");
this._freshNode();
}
changeSize() {
this._evalCode(
"window.ccinspector.pluginSetNodeSize(" +
"'" + this.itemData.uuid + "'," +
"'" + this.itemData.width + "'," +
"'" + this.itemData.height + "'" +
")");
this._freshNode();
}
changeRotation() {
console.log("change rotation:" + this.itemData.rotation);
this._evalCode(
"window.ccinspector.pluginSetNodeRotation('" +
this.itemData.uuid + "','" +
this.itemData.rotation + "')");
this._freshNode();
}
changeColor() { changeColor() {
let color = this.itemData.color; let color = this.itemData.color;
@ -120,27 +61,6 @@ export default class NodeBaseProperty extends Vue {
this._freshNode(); this._freshNode();
} }
onBtnClickNodeHide() {
let uuid = this.itemData.uuid;
if (uuid !== undefined) {
let code = "window.ccinspector.pluginSetNodeActive('" + uuid + "', 0);";
this._evalCode(code);
this._freshNode();
}
}
onBtnClickNodeShow() {
let uuid = this.itemData.uuid;
if (uuid !== undefined) {
let code = "window.ccinspector.pluginSetNodeActive('" + uuid + "', 1);";
this._evalCode(code);
this._freshNode();
}
}
_freshNode() { _freshNode() {
let uuid = this.itemData.uuid; let uuid = this.itemData.uuid;
let code2 = "window.ccinspector.getNodeInfo('" + uuid + "')"; let code2 = "window.ccinspector.getNodeInfo('" + uuid + "')";
@ -155,8 +75,6 @@ export default class NodeBaseProperty extends Vue {
console.log(code); console.log(code);
} }
} }
} }
</script> </script>

View File

@ -7,6 +7,9 @@ export enum DataType {
Enum, Enum,
Bool, Bool,
Color, Color,
NullOrUndefined,
Array, // 暂时在控制台打印下
Object,
} }
class Info { class Info {
@ -21,6 +24,28 @@ export class TextData extends Info {
} }
} }
export class ArrayData extends Info {
constructor() {
super();
this.type = DataType.Array;
}
}
export class ObjectData extends Info {
constructor() {
super();
this.type = DataType.Object;
}
}
export class NullOrUndefinedData extends Info {
constructor() {
super();
this.type = DataType.NullOrUndefined;
}
}
export class ColorData extends Info { export class ColorData extends Info {
constructor(color: string) { constructor(color: string) {
super(); super();

View File

@ -4,6 +4,7 @@ import "element-ui/lib/theme-chalk/index.css"
import "./global.less" import "./global.less"
import index from "./index.vue"; import index from "./index.vue";
import './register-panel'; import './register-panel';
Vue.use(ElementUI, {size: "mini"}); Vue.use(ElementUI, {size: "mini"});
new Vue({ new Vue({
el: "#app", el: "#app",

View File

@ -11,6 +11,9 @@ if (chrome && chrome.devtools) {
chrome.devtools.panels.create("Cocos", "icons/48.png", Manifest.devtools_page, (panel: chrome.devtools.panels.ExtensionPanel) => { chrome.devtools.panels.create("Cocos", "icons/48.png", Manifest.devtools_page, (panel: chrome.devtools.panels.ExtensionPanel) => {
console.log("[CC-Inspector] Dev Panel Created!"); console.log("[CC-Inspector] Dev Panel Created!");
let conn = chrome.runtime.connect({name: PluginMsg.Page.DevToolsPanel}); let conn = chrome.runtime.connect({name: PluginMsg.Page.DevToolsPanel});
conn.onDisconnect.addListener(() => {
console.log(`%c[Connect-Dis]`, 'color:red;')
})
conn.onMessage.addListener((event, sender) => { conn.onMessage.addListener((event, sender) => {
console.log(`[Message] ${JSON.stringify(event)}`); console.log(`[Message] ${JSON.stringify(event)}`);
}); });

View File

@ -1,14 +1,20 @@
// eval 注入脚本的代码,变量尽量使用var,后来发现在import之后,let会自动变为var // eval 注入脚本的代码,变量尽量使用var,后来发现在import之后,let会自动变为var
const PluginMsg = require("./core/plugin-msg"); const PluginMsg = require("./core/plugin-msg");
import {BoolData, ColorData, Group, NumberData, Property, StringData, Vec2Data, Vec3Data} from "./devtools/data"; import {
ArrayData,
BoolData,
ColorData,
Group,
NullOrUndefinedData,
NumberData, ObjectData,
Property,
StringData,
Vec2Data,
Vec3Data
} from "./devtools/data";
let cc_inspector = { let cc_inspector = {
inspectorGameMemoryStorage: {}, inspectorGameMemoryStorage: {},
msgType: {
nodeInfo: 2,//节点信息
nodeListInfo: 1,// 节点列表信息
notSupport: 0,// 不支持的游戏
},
postData: { postData: {
scene: { scene: {
name: "", name: "",
@ -45,66 +51,33 @@ let cc_inspector = {
let node = sceneChildren[i]; let node = sceneChildren[i];
this.getNodeChildren(node, sendData.children); this.getNodeChildren(node, sendData.children);
} }
// console.log(postData);
this.sendMsgToDevTools(PluginMsg.Msg.ListInfo, sendData); this.sendMsgToDevTools(PluginMsg.Msg.ListInfo, sendData);
} else { } else {
this.sendMsgToDevTools(PluginMsg.Msg.Support, {support: false, msg: "未发现游戏场景,不支持调试游戏!"}); this.sendMsgToDevTools(PluginMsg.Msg.Support, {support: false, msg: "未发现游戏场景,不支持调试游戏!"});
} }
} }
}, },
// 收集节点信息
getNodeChildren(node, data) {
let nodeData = {
uuid: node.uuid,
name: node.name,
children: [],
};
this.inspectorGameMemoryStorage[node.uuid] = node;
let nodeChildren = node.getChildren();
for (let i = 0; i < nodeChildren.length; i++) {
let childItem = nodeChildren[i];
this.getNodeChildren(childItem, nodeData.children);
}
data.push(nodeData);
},
// 检测是否包含cc变量 // 检测是否包含cc变量
checkIsGamePage() { checkIsGamePage() {
let isCocosGame = typeof cc !== "undefined"; let isCocosGame = typeof cc !== "undefined";
this.sendMsgToDevTools(PluginMsg.Msg.Support, {support: isCocosGame}); this.sendMsgToDevTools(PluginMsg.Msg.Support, {support: isCocosGame});
return isCocosGame; return isCocosGame;
}, },
testMsg2() {
chrome.runtime.connect({name: "inject"});
},
// 收集组件信息
getNodeComponentsInfo(node) {
let ret = [];
let nodeComp = node._components;
for (let i = 0; i < nodeComp.length; i++) {
let itemComp = nodeComp[i];
this.inspectorGameMemoryStorage[itemComp.uuid] = itemComp;
ret.push({
uuid: itemComp.uuid,
type: itemComp.constructor.name,
name: itemComp.name,
});
}
return ret;
},
pluginSetNodeColor(uuid, colorHex) {
let node = this.inspectorGameMemoryStorage[uuid];
if (node) {
node.color = cc.hexToColor(colorHex);
}
},
pluginSetNodeRotation(uuid, rotation) {
let node = this.inspectorGameMemoryStorage[uuid];
if (node) {
node.rotation = rotation;
}
},
pluginSetNodePosition(uuid, x, y) {
let node = this.inspectorGameMemoryStorage[uuid];
if (node) {
node.x = x;
node.y = y;
}
},
pluginSetNodeSize(uuid, width, height) {
let node = this.inspectorGameMemoryStorage[uuid];
if (node) {
node.width = width;
node.height = height;
}
},
// 设置节点是否可视
pluginSetNodeActive(uuid, isActive) { pluginSetNodeActive(uuid, isActive) {
let node = this.inspectorGameMemoryStorage[uuid]; let node = this.inspectorGameMemoryStorage[uuid];
if (node) { if (node) {
@ -117,7 +90,7 @@ let cc_inspector = {
}, },
_getNodeKeys(node) { _getNodeKeys(node) {
let keys = []; let keys = [];
let excludeProperty = ["children", "quat"]; let excludeProperty = ["children", "quat", "node"];
for (let key in node) { for (let key in node) {
if (!key.startsWith("_") && if (!key.startsWith("_") &&
!excludeProperty.includes(key) && !excludeProperty.includes(key) &&
@ -134,7 +107,7 @@ let cc_inspector = {
size: ["width", "height"], size: ["width", "height"],
position: ["x", "y", "z"], position: ["x", "y", "z"],
scale: ["scaleX", "scaleY", "scaleZ"], scale: ["scaleX", "scaleY", "scaleZ"],
designResolution: ["width", "height"], // 这个比较特殊在key下边其他的都不是在key下
}; };
for (let value in pairProperty) { for (let value in pairProperty) {
let pair = pairProperty[value]; let pair = pairProperty[value];
@ -157,8 +130,12 @@ let cc_inspector = {
info = new StringData(propertyValue); info = new StringData(propertyValue);
break; break;
default: default:
if (Array.isArray(propertyValue)) { if (propertyValue == null || typeof propertyValue === "undefined") {
info = new NullOrUndefinedData();
} else if (Array.isArray(propertyValue)) {
info = new ArrayData();
} else if (propertyValue instanceof Object) {
info = new ObjectData();
} else if (propertyValue instanceof cc.Color) { } else if (propertyValue instanceof cc.Color) {
let hex = propertyValue.toHEX(); let hex = propertyValue.toHEX();
info = new ColorData(`#${hex}`); info = new ColorData(`#${hex}`);
@ -171,12 +148,8 @@ let cc_inspector = {
} }
return info; return info;
}, },
// 获取节点信息 _getGroupData(node) {
getNodeInfo(uuid) { let nodeGroup = new Group(node.constructor.name);
debugger
let node = this.inspectorGameMemoryStorage[uuid];
if (node) {
let nodeGroup = new Group("Node");
let keys = this._getNodeKeys(node); let keys = this._getNodeKeys(node);
for (let i = 0; i < keys.length; i++) { for (let i = 0; i < keys.length; i++) {
let key = keys[i]; let key = keys[i];
@ -219,37 +192,32 @@ let cc_inspector = {
} }
} }
} }
return nodeGroup;
},
let nodeComp = this.getNodeComponentsInfo(node); // 获取节点信息
let nodeData = { getNodeInfo(uuid) {
type: node.constructor.name, debugger
components: nodeComp let node = this.inspectorGameMemoryStorage[uuid];
}; if (node) {
this.sendMsgToDevTools(PluginMsg.Msg.NodeInfo, nodeGroup); let groupData = [];
// 收集节点信息
let nodeGroup = this._getGroupData(node);
groupData.push(nodeGroup);
// 收集组件信息
let nodeComp = node._components;
for (let i = 0; i < nodeComp.length; i++) {
let itemComp = nodeComp[i];
this.inspectorGameMemoryStorage[itemComp.uuid] = itemComp;
let compGroup = this._getGroupData(itemComp);
groupData.push(compGroup);
}
this.sendMsgToDevTools(PluginMsg.Msg.NodeInfo, groupData);
} else { } else {
// 未获取到节点数据 // 未获取到节点数据
console.log("未获取到节点数据"); console.log("未获取到节点数据");
} }
}, },
// 收集节点信息
getNodeChildren(node, data) {
// console.log("nodeName: " + node.name);
let nodeData = {
uuid: node.uuid,
name: node.name,
children: [],
};
this.inspectorGameMemoryStorage[node.uuid] = node;
let nodeChildren = node.getChildren();
for (let i = 0; i < nodeChildren.length; i++) {
let childItem = nodeChildren[i];
// console.log("childName: " + childItem.name);
this.getNodeChildren(childItem, nodeData.children);
}
data.push(nodeData);
},
sendMsgToDevTools(msg, data) { sendMsgToDevTools(msg, data) {
// 发送给content.js处理 // 发送给content.js处理
window.postMessage({msg: msg, data: data}, "*"); window.postMessage({msg: msg, data: data}, "*");