From d51d3349ef9d481ee4e9da37de96da0c9c615349 Mon Sep 17 00:00:00 2001 From: xu_yanfeng Date: Tue, 27 May 2025 17:54:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AC=E6=89=93=E7=AE=97=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E7=9A=84prefab=E4=B8=8D=E5=90=8C=E7=9A=84=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=EF=BC=8C=E6=84=9F=E8=A7=89=E4=B8=8D=E7=AE=97=E6=98=AF=E5=88=9A?= =?UTF-8?q?=E9=9C=80=EF=BC=8C=E6=9A=82=E6=97=B6=E4=B8=8D=E5=81=9A=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E4=B9=9F=E4=B8=8D=E6=98=AF=E5=BE=88=E5=A5=BD=E5=81=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scripts/inject/inspector.ts | 29 +++++++++++++++++------------ src/scripts/inject/types.ts | 5 ++++- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/scripts/inject/inspector.ts b/src/scripts/inject/inspector.ts index d79d53f..debfd5a 100644 --- a/src/scripts/inject/inspector.ts +++ b/src/scripts/inject/inspector.ts @@ -12,7 +12,7 @@ import { Hint } from "./hint"; import { injectView } from "./inject-view"; import { inspectTarget } from "./inspect-list"; import { getValue, trySetValueWithConfig } from "./setValue"; -import { BuildArrayOptions, BuildImageOptions, BuildObjectOptions, BuildVecOptions } from "./types"; +import { BuildArrayOptions, BuildImageOptions, BuildObjectOptions, BuildVecOptions, NodeChildrenOptions } from "./types"; import { isHasProperty } from "./util"; declare const cc: any; @@ -265,12 +265,7 @@ export class Inspector extends InjectEvent { const node = this.inspectorGameMemoryStorage[uuid]; if (node && node.isValid) { console.log(node.uuid, node); - let prefabUUID = ""; - if (node instanceof cc.Scene) { - prefabUUID = node.uuid; - } else { - prefabUUID = node._prefab?.asset?._uuid; - } + const prefabUUID = this.getNodePrefabUUID(node); if (prefabUUID) { everything.open(prefabUUID); } @@ -278,6 +273,15 @@ export class Inspector extends InjectEvent { } } } + private getNodePrefabUUID(node: any) { + let prefabUUID = ""; + if (node instanceof cc.Scene) { + prefabUUID = node.uuid; + } else { + prefabUUID = node._prefab?.asset?._uuid; + } + return prefabUUID; + } init() { console.log(...this.terminal.init()); this.watchIsCocosGame(); @@ -351,7 +355,8 @@ export class Inspector extends InjectEvent { let scene = cc.director.getScene(); if (scene) { let treeData = new TreeData(); - this.getNodeChildren(scene, treeData); + const opts: NodeChildrenOptions = { index: 0 }; + this.getNodeChildren(scene, treeData, opts); notify && this.sendMsgToContent(Msg.ResponseTreeInfo, treeData as ResponseTreeInfoData); } else { let treeData = new TreeData(); @@ -491,7 +496,7 @@ export class Inspector extends InjectEvent { } return null; } - private calcColor(node: any) { + private calcColor(node: any, opts: NodeChildrenOptions) { if (node._prefab) { return "#01ff01ff"; } else { @@ -513,11 +518,11 @@ export class Inspector extends InjectEvent { return ret; } // 收集节点信息 - getNodeChildren(node: any, data: TreeData) { + getNodeChildren(node: any, data: TreeData, opts: NodeChildrenOptions) { data.id = node.uuid; data.text = node.name; data.icon = this.calcIcon(node); - data.color = this.calcColor(node); + data.color = this.calcColor(node, opts); const v2 = this.isCreatorV2(); calcCodeHint(node, data, v2); // @ts-ignore @@ -536,7 +541,7 @@ export class Inspector extends InjectEvent { for (let i = 0; i < nodeChildren.length; i++) { let childItem = nodeChildren[i]; let treeData = new TreeData(); - this.getNodeChildren(childItem, treeData); + this.getNodeChildren(childItem, treeData, opts); data.children.push(treeData); } } diff --git a/src/scripts/inject/types.ts b/src/scripts/inject/types.ts index 889082e..b26e3fb 100644 --- a/src/scripts/inject/types.ts +++ b/src/scripts/inject/types.ts @@ -34,7 +34,10 @@ export interface BuildVecOptions { value: Object; data: Vec3Data | Vec2Data; } - +export interface NodeChildrenOptions { + /**遍历到prefab的index,主要是为了着色 */ + index: number; +} export interface BuildImageOptions { path: string[]; ctor: Function;