mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-19 08:28:41 +00:00
优化
This commit is contained in:
parent
ef1346916f
commit
ec8c00ea8f
@ -20,7 +20,6 @@ import Vue from "vue"
|
|||||||
|
|
||||||
import {Component, Prop, Watch} from "vue-property-decorator"
|
import {Component, Prop, Watch} from "vue-property-decorator"
|
||||||
import UiProp from "./ui-prop.vue"
|
import UiProp from "./ui-prop.vue"
|
||||||
import {DataType, testData} from "../data";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {UiProp},
|
components: {UiProp},
|
||||||
@ -28,7 +27,7 @@ import {DataType, testData} from "../data";
|
|||||||
export default class NodeBaseProperty extends Vue {
|
export default class NodeBaseProperty extends Vue {
|
||||||
name: string = "node-base"
|
name: string = "node-base"
|
||||||
|
|
||||||
@Prop({default: () => testData,})
|
@Prop({default: () => [],})
|
||||||
allGroup: Array<Record<string, any>> | undefined;
|
allGroup: Array<Record<string, any>> | undefined;
|
||||||
|
|
||||||
onClickHeader(group: any) {
|
onClickHeader(group: any) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<div class="text">{{ name }}</div>
|
<div class="text">{{ name }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="value">
|
<div class="value">
|
||||||
<el-input v-if="isString()" v-model="value.data"></el-input>
|
<el-input v-if="isString()" v-model="value.data" @change="onChangeValue"></el-input>
|
||||||
<el-input v-if="isText()"
|
<el-input v-if="isText()"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:autosize="{minRows:3,maxRows:5}"
|
:autosize="{minRows:3,maxRows:5}"
|
||||||
@ -118,7 +118,42 @@ export default class UiProp extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onShowValueInConsole() {
|
onShowValueInConsole() {
|
||||||
console.log(this.value.data)
|
if (Array.isArray(this.value.path)) {
|
||||||
|
let uuid = this.value.path[0];
|
||||||
|
let key = this.value.path[1]; // todo 暂时只支持一级key
|
||||||
|
if (uuid && key) {
|
||||||
|
chrome.devtools.inspectedWindow.eval(`window.ccinspector.logValue('${uuid}','${key}')`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onChangeValue() {
|
||||||
|
window.postMessage({a: 1, b: 2}, '*')
|
||||||
|
return
|
||||||
|
if (Array.isArray(this.value.path)) {
|
||||||
|
let uuid = this.value.path[0];
|
||||||
|
let key = this.value.path[1]; // todo 暂时只支持一级key
|
||||||
|
if (uuid && key && this.value.hasOwnProperty('data')) {
|
||||||
|
let cmd = null;
|
||||||
|
let data = this.value.data;
|
||||||
|
switch (this.value.type) {
|
||||||
|
case DataType.Number:
|
||||||
|
cmd = `window.ccinspector.setValue('${uuid}','${key}', ${data})`;
|
||||||
|
break
|
||||||
|
case DataType.Bool:
|
||||||
|
cmd = `window.ccinspector.setValue('${uuid}','${key}', ${data})`;
|
||||||
|
break;
|
||||||
|
case DataType.String:
|
||||||
|
case DataType.Text:
|
||||||
|
cmd = `window.ccinspector.setValue('${uuid}','${key}', '${data}')`;
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (cmd) {
|
||||||
|
chrome.devtools.inspectedWindow.eval(cmd)
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Prop({default: 1})
|
@Prop({default: 1})
|
||||||
@ -183,6 +218,7 @@ export default class UiProp extends Vue {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
min-width: 90px;
|
||||||
|
|
||||||
.text {
|
.text {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
@ -197,6 +233,7 @@ export default class UiProp extends Vue {
|
|||||||
text-align: left;
|
text-align: left;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
min-width: 400px;
|
||||||
|
|
||||||
.color {
|
.color {
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -221,6 +258,14 @@ export default class UiProp extends Vue {
|
|||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
margin-right: 20px;
|
margin-right: 20px;
|
||||||
|
|
||||||
|
.value {
|
||||||
|
min-width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.key {
|
||||||
|
min-width: 20px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ui-prop:last-child {
|
#ui-prop:last-child {
|
||||||
@ -229,7 +274,7 @@ export default class UiProp extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.array-object {
|
.array-object {
|
||||||
flex:1;
|
flex: 1;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -237,7 +282,7 @@ export default class UiProp extends Vue {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
.text {
|
.text {
|
||||||
flex:1;
|
flex: 1;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
@ -15,6 +15,7 @@ export enum DataType {
|
|||||||
class Info {
|
class Info {
|
||||||
public type: DataType = DataType.Number;
|
public type: DataType = DataType.Number;
|
||||||
public data: any;
|
public data: any;
|
||||||
|
public path: Array<string> = [];// 属性对应的路径
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TextData extends Info {
|
export class TextData extends Info {
|
||||||
@ -151,8 +152,9 @@ class CompInfo {
|
|||||||
export const testData = [
|
export const testData = [
|
||||||
{
|
{
|
||||||
name: "group1",
|
name: "group1",
|
||||||
|
uuid: 'node/comp uuid',
|
||||||
data: [
|
data: [
|
||||||
{name: "uuid", value: {type: DataType.String, data: 'abc'}},
|
{name: "uuid", value: {type: DataType.String, data: 'abc', path: 'uuid'}},
|
||||||
{name: "opacity", value: {type: DataType.Number, data: 100}},
|
{name: "opacity", value: {type: DataType.Number, data: 100}},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -11,3 +11,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.el-input{
|
||||||
|
input{
|
||||||
|
text-align: left !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -37,9 +37,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
// import injectScript from '../injectScript.js'
|
|
||||||
// import EvalCode from "./evalCodeString.js";
|
|
||||||
|
|
||||||
import Vue from "vue";
|
import Vue from "vue";
|
||||||
import {Component, Prop} from "vue-property-decorator";
|
import {Component, Prop} from "vue-property-decorator";
|
||||||
import SceneProperty from "@/devtools/ccType/SceneProperty.vue";
|
import SceneProperty from "@/devtools/ccType/SceneProperty.vue";
|
||||||
@ -54,7 +51,7 @@ const PluginMsg = require("../core/plugin-msg");
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
export default class Index extends Vue {
|
export default class Index extends Vue {
|
||||||
private isShowDebug: boolean = true;
|
private isShowDebug: boolean = false;
|
||||||
treeItemData: Array<Record<string, any>> = [];
|
treeItemData: Array<Record<string, any>> = [];
|
||||||
treeData: Array<Record<string, any>> = []
|
treeData: Array<Record<string, any>> = []
|
||||||
bgConn: chrome.runtime.Port | null = null// 与background.js的链接
|
bgConn: chrome.runtime.Port | null = null// 与background.js的链接
|
||||||
@ -213,6 +210,7 @@ export default class Index extends Vue {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
.left {
|
.left {
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -230,7 +228,7 @@ export default class Index extends Vue {
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
min-height: 20px;
|
min-height: 20px;
|
||||||
overflow: scroll;
|
overflow: auto;
|
||||||
width: 300px;
|
width: 300px;
|
||||||
|
|
||||||
|
|
||||||
@ -251,7 +249,19 @@ export default class Index extends Vue {
|
|||||||
.right {
|
.right {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
background: #e5e9f2;
|
background: #e5e9f2;
|
||||||
overflow: scroll;
|
overflow-x: hidden;
|
||||||
|
overflow-y: auto;
|
||||||
|
|
||||||
|
&::-webkit-scrollbar {
|
||||||
|
width: 0;
|
||||||
|
background: #999;
|
||||||
|
border-radius: 2px;
|
||||||
|
height: 6px;
|
||||||
|
}
|
||||||
|
&::-webkit-scrollbar-thumb {
|
||||||
|
background-color: #333;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,11 @@ let cc_inspector = {
|
|||||||
},
|
},
|
||||||
_getNodeKeys(node) {
|
_getNodeKeys(node) {
|
||||||
let keys = [];
|
let keys = [];
|
||||||
let excludeProperty = ["children", "quat", "node"];
|
let excludeProperty = [
|
||||||
|
"children", "quat", "node",
|
||||||
|
// 生命周期函数
|
||||||
|
"onFocusInEditor", "onRestore", "start", "lateUpdate", "update", "resetInEditor", "onLostFocusInEditor",
|
||||||
|
];
|
||||||
for (let key in node) {
|
for (let key in node) {
|
||||||
if (!key.startsWith("_") &&
|
if (!key.startsWith("_") &&
|
||||||
!excludeProperty.includes(key) &&
|
!excludeProperty.includes(key) &&
|
||||||
@ -117,7 +121,7 @@ let cc_inspector = {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
_genInfoData(propertyValue) {
|
_genInfoData(propertyValue, path) {
|
||||||
let info = null;
|
let info = null;
|
||||||
switch (typeof propertyValue) {
|
switch (typeof propertyValue) {
|
||||||
case "boolean":
|
case "boolean":
|
||||||
@ -132,19 +136,22 @@ let cc_inspector = {
|
|||||||
default:
|
default:
|
||||||
if (propertyValue == null || typeof propertyValue === "undefined") {
|
if (propertyValue == null || typeof propertyValue === "undefined") {
|
||||||
info = new NullOrUndefinedData();
|
info = new NullOrUndefinedData();
|
||||||
|
} else if (propertyValue instanceof cc.Color) {
|
||||||
|
let hex = propertyValue.toHEX();
|
||||||
|
info = new ColorData(`#${hex}`);
|
||||||
} else if (Array.isArray(propertyValue)) {
|
} else if (Array.isArray(propertyValue)) {
|
||||||
info = new ArrayData();
|
info = new ArrayData();
|
||||||
} else if (propertyValue instanceof Object) {
|
} else if (propertyValue instanceof Object) {
|
||||||
info = new ObjectData();
|
info = new ObjectData();
|
||||||
} else if (propertyValue instanceof cc.Color) {
|
|
||||||
let hex = propertyValue.toHEX();
|
|
||||||
info = new ColorData(`#${hex}`);
|
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!info) {
|
if (info) {
|
||||||
|
info.path = path;
|
||||||
|
} else {
|
||||||
console.error(`暂不支持的属性值`, propertyValue);
|
console.error(`暂不支持的属性值`, propertyValue);
|
||||||
|
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
},
|
},
|
||||||
@ -173,7 +180,8 @@ let cc_inspector = {
|
|||||||
}
|
}
|
||||||
pairValues.forEach(el => {
|
pairValues.forEach(el => {
|
||||||
if (el in node) {
|
if (el in node) {
|
||||||
let vecData = this._genInfoData(node[el]);
|
let propertyPath = [node.uuid, el];
|
||||||
|
let vecData = this._genInfoData(node[el], propertyPath);
|
||||||
if (vecData) {
|
if (vecData) {
|
||||||
info.add(new Property(el, vecData));
|
info.add(new Property(el, vecData));
|
||||||
}
|
}
|
||||||
@ -186,7 +194,8 @@ let cc_inspector = {
|
|||||||
nodeGroup.addProperty(property);
|
nodeGroup.addProperty(property);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let info = this._genInfoData(propertyValue);
|
let propertyPath = [node.uuid, key];
|
||||||
|
let info = this._genInfoData(propertyValue, propertyPath);
|
||||||
if (info) {
|
if (info) {
|
||||||
nodeGroup.addProperty(new Property(key, info));
|
nodeGroup.addProperty(new Property(key, info));
|
||||||
}
|
}
|
||||||
@ -196,7 +205,6 @@ let cc_inspector = {
|
|||||||
},
|
},
|
||||||
// 获取节点信息
|
// 获取节点信息
|
||||||
getNodeInfo(uuid) {
|
getNodeInfo(uuid) {
|
||||||
debugger
|
|
||||||
let node = this.inspectorGameMemoryStorage[uuid];
|
let node = this.inspectorGameMemoryStorage[uuid];
|
||||||
if (node) {
|
if (node) {
|
||||||
let groupData = [];
|
let groupData = [];
|
||||||
@ -217,7 +225,18 @@ let cc_inspector = {
|
|||||||
console.log("未获取到节点数据");
|
console.log("未获取到节点数据");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
logValue(uuid, key) {
|
||||||
|
let nodeOrComp = this.inspectorGameMemoryStorage[uuid];
|
||||||
|
if (nodeOrComp) {
|
||||||
|
console.log(nodeOrComp[key]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setValue(uuid, key, value) {
|
||||||
|
let nodeOrComp = this.inspectorGameMemoryStorage[uuid];
|
||||||
|
if (nodeOrComp && key in nodeOrComp) {
|
||||||
|
nodeOrComp[key] = value;
|
||||||
|
}
|
||||||
|
},
|
||||||
sendMsgToDevTools(msg, data) {
|
sendMsgToDevTools(msg, data) {
|
||||||
// 发送给content.js处理
|
// 发送给content.js处理
|
||||||
window.postMessage({msg: msg, data: data}, "*");
|
window.postMessage({msg: msg, data: data}, "*");
|
||||||
@ -238,6 +257,9 @@ let cc_inspector = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
window.addEventListener("message", (a, b, c) => {
|
||||||
|
console.log(a, b, c);
|
||||||
|
});
|
||||||
window.ccinspector = window.ccinspector || cc_inspector;
|
window.ccinspector = window.ccinspector || cc_inspector;
|
||||||
window.ccinspector.init && window.ccinspector.init();// 执行初始化函数
|
window.ccinspector.init && window.ccinspector.init();// 执行初始化函数
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user