diff --git a/source/src/devtools/data.ts b/source/src/devtools/data.ts index bf3aa34..0fd94c1 100644 --- a/source/src/devtools/data.ts +++ b/source/src/devtools/data.ts @@ -15,6 +15,7 @@ export enum DataType { export class Info { public type: DataType = DataType.Number; public data: any; + public readonly: boolean = false; public path: Array = [];// 属性对应的路径 } diff --git a/source/src/devtools/inject.ts b/source/src/devtools/inject.ts index 0047100..2b260d3 100644 --- a/source/src/devtools/inject.ts +++ b/source/src/devtools/inject.ts @@ -192,7 +192,8 @@ class CCInspector { return null; } - _genInfoData(propertyValue: any, path: any) { + _genInfoData(node: any, key: string, path: any) { + let propertyValue = node[key]; let info = null; switch (typeof propertyValue) { case "boolean": @@ -220,6 +221,7 @@ class CCInspector { break; } if (info) { + info.readonly = this._isReadonly(node, key) info.path = path; } else { console.error(`暂不支持的属性值`, propertyValue); @@ -256,7 +258,7 @@ class CCInspector { pairValues.forEach((el: string) => { if (el in node) { let propertyPath = [node.uuid, el]; - let vecData = this._genInfoData(node[el], propertyPath); + let vecData = this._genInfoData(node, el, propertyPath); if (vecData) { info && info.add(new Property(el, vecData)); } @@ -273,7 +275,7 @@ class CCInspector { } } else { let propertyPath = [node.uuid, key]; - let info = this._genInfoData(propertyValue, propertyPath); + let info = this._genInfoData(node, key, propertyPath); if (info) { nodeGroup.addProperty(new Property(key, info)); } @@ -314,22 +316,26 @@ class CCInspector { } } + _isReadonly(base: Object, key: string): boolean { + let obj = Object.getPrototypeOf(base); + if (obj) { + let ret = Object.getOwnPropertyDescriptor(obj, key) + if (ret && ret.set) { + return false; + } else { + return this._isReadonly(obj, key) + } + } else { + return true; + } + } + setValue(uuid: string, key: string, value: string) { let nodeOrComp = this.inspectorGameMemoryStorage[uuid]; if (nodeOrComp && key in nodeOrComp) { - debugger - - function circleFind(base: Object): boolean { - let obj = Object.getPrototypeOf(base); - let ret = Object.getOwnPropertyDescriptor(obj, key) - if (ret && ret.set) { - return true; - } else { - return circleFind(obj) - } - } - - if (circleFind(nodeOrComp)) { + if (this._isReadonly(nodeOrComp, key)) { + console.warn(`值不允许修改`); + } else { nodeOrComp[key] = value; } } diff --git a/source/src/devtools/ui-prop.vue b/source/src/devtools/ui-prop.vue index be8320a..0d09912 100644 --- a/source/src/devtools/ui-prop.vue +++ b/source/src/devtools/ui-prop.vue @@ -4,11 +4,15 @@
{{ name }}
- + + @@ -16,6 +20,7 @@ style="width: 100%;text-align: left" v-model="value.data" :step="step" + :disabled="value.readonly" @change="onChangeValue" controls-position="right" > @@ -28,16 +33,26 @@
- + - + +
- + +
{{ value.data }}
@@ -131,7 +146,9 @@ export default class UiProp extends Vue { } onChangeValue() { - connectBackground.postMessageToBackground(Msg.SetProperty, this.value); + if (!this.value.readonly) { + connectBackground.postMessageToBackground(Msg.SetProperty, this.value); + } } @Prop({default: 1})