From 31c5ccf7c66a1de4eb64304fc86407b6a4912f1d Mon Sep 17 00:00:00 2001 From: xu_yanfeng Date: Wed, 29 Jan 2025 17:32:46 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8Dcreator=20v2=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E7=9A=84widget=E5=AF=B9pos=E7=9A=84=E5=BD=B1=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cc-inspector/src/scripts/inject/inspector.ts | 22 +++++++++----------- cc-inspector/src/views/devtools/data.ts | 7 +++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cc-inspector/src/scripts/inject/inspector.ts b/cc-inspector/src/scripts/inject/inspector.ts index ca0208d..cbdc3bd 100644 --- a/cc-inspector/src/scripts/inject/inspector.ts +++ b/cc-inspector/src/scripts/inject/inspector.ts @@ -515,22 +515,19 @@ export class Inspector extends InjectEvent { item.tip = ""; return false; } - private getDisabled(node: any, key: string | number, v: string, item: Info) { - if (typeof key !== "string") { - return false; - } - const cfgArray: Array<{ type: any; keys: Array<{ key: string; disabled: () => boolean }> }> = [ + private getDisabled(node: any, key: string, item: Info) { + const cfgArray: Array<{ type: any; keys: Array<{ key: string[]; disabled: () => boolean }> }> = [ { type: cc.Node, keys: [ { - key: "position.x", + key: ["position.x", "x"], disabled: () => { return this.isDisabledX(node, item); }, }, { - key: "position.y", + key: ["position.y", "y"], disabled: () => { return this.isDisabledY(node, item); }, @@ -541,7 +538,7 @@ export class Inspector extends InjectEvent { for (let i = 0; i < cfgArray.length; i++) { const { type, keys } = cfgArray[i]; if (node instanceof type) { - const ret = keys.find((item) => item.key === `${key.trim()}.${v.trim()}`); + const ret = keys.find((item) => !!item.key.find((el) => el === key)); if (ret) { return ret.disabled(); } @@ -608,6 +605,7 @@ export class Inspector extends InjectEvent { case "number": { const info = new NumberData(propertyValue); info.step = this.getStep(node, key); + info.disabled = this.getDisabled(node, key.toString(), info); return make(info); } case "string": { @@ -653,13 +651,13 @@ export class Inspector extends InjectEvent { { key: "x", disabled: (v: string, item: Info) => { - return this.getDisabled(node, key, v, item); + return this.getDisabled(node, `${key}.${v}`, item); }, }, { key: "y", disabled: (v: string, item: Info) => { - return this.getDisabled(node, key, v, item); + return this.getDisabled(node, `${key}.${v}`, item); }, }, { key: "z" }, @@ -691,13 +689,13 @@ export class Inspector extends InjectEvent { { key: "x", disabled: (v: string, item: Info) => { - return this.getDisabled(node, key, v, item); + return this.getDisabled(node, `${key}.${v}`, item); }, }, { key: "y", disabled: (v: string, item: Info) => { - return this.getDisabled(node, key, v, item); + return this.getDisabled(node, `${key}.${v}`, item); }, }, ], diff --git a/cc-inspector/src/views/devtools/data.ts b/cc-inspector/src/views/devtools/data.ts index 3cffd06..661242d 100644 --- a/cc-inspector/src/views/devtools/data.ts +++ b/cc-inspector/src/views/devtools/data.ts @@ -25,11 +25,13 @@ export class Info { public data: any; public readonly: boolean = false; public path: Array = []; // 属性对应的路径 + public tip: string = ""; constructor(id: string = "") { this.id = id || v4(); } parse(data: Info) { this.id = data.id; + this.tip = data.tip || ""; this.path = data.path; this.readonly = data.readonly; } @@ -324,6 +326,10 @@ export class StringData extends Info { export class NumberData extends Info { public data: number = 0; public step: number = 1; + /** + * 是否禁用,因为cc.Widget组件会影响调整x、y + */ + public disabled: boolean = false; constructor(data: number = 0) { super(); this.type = DataType.Number; @@ -333,6 +339,7 @@ export class NumberData extends Info { super.parse(data); this.data = data.data; this.step = data.step || 1; + this.disabled = !!data.disabled; return this; } public isNumber(): boolean {