fix: debug 工具改用 query-node-tree 替换不存在的 query-hierarchy

This commit is contained in:
feng0207
2026-06-20 22:45:03 +08:00
parent f3f1176ae7
commit 3d5b0adc0f
2 changed files with 121 additions and 79 deletions

File diff suppressed because one or more lines are too long

View File

@@ -268,52 +268,69 @@ export class DebugTools implements ToolExecutor {
private async getNodeTree(rootUuid?: string, maxDepth: number = 10): Promise<ToolResponse> { private async getNodeTree(rootUuid?: string, maxDepth: number = 10): Promise<ToolResponse> {
return new Promise((resolve) => { return new Promise((resolve) => {
const buildTree = async (nodeUuid: string, depth: number = 0): Promise<any> => { const mapTree = (node: any, depth: number = 0): any => {
if (depth >= maxDepth) { if (depth >= maxDepth) {
return { truncated: true }; return { truncated: true };
} }
if (!node) {
try { return null;
const nodeData = await Editor.Message.request('scene', 'query-node', nodeUuid);
const tree = {
uuid: nodeData.uuid,
name: nodeData.name,
active: nodeData.active,
components: (nodeData as any).components ? (nodeData as any).components.map((c: any) => c.__type__) : [],
childCount: nodeData.children ? nodeData.children.length : 0,
children: [] as any[]
};
if (nodeData.children && nodeData.children.length > 0) {
for (const childId of nodeData.children) {
const childTree = await buildTree(childId, depth + 1);
tree.children.push(childTree);
}
}
return tree;
} catch (err: any) {
return { error: err.message };
} }
const children = Array.isArray(node.children) ? node.children : [];
return {
uuid: node.uuid,
name: node.name,
active: node.active,
components: Array.isArray(node.components)
? node.components.map((c: any) => c.__type__ || c.type || c.cid).filter((x: any) => x)
: [],
childCount: children.length,
children: children.map((c: any) => mapTree(c, depth + 1))
};
}; };
if (rootUuid) { const findInTree = (node: any, uuid: string): any => {
buildTree(rootUuid).then(tree => { if (!node) {
resolve({ success: true, data: tree }); return null;
}); }
} else { if (node.uuid === uuid) {
Editor.Message.request('scene', 'query-hierarchy').then(async (hierarchy: any) => { return node;
const trees = []; }
for (const rootNode of hierarchy.children) { const children = Array.isArray(node.children) ? node.children : [];
const tree = await buildTree(rootNode.uuid); for (const child of children) {
trees.push(tree); const found = findInTree(child, uuid);
if (found) {
return found;
} }
}
return null;
};
// 'query-hierarchy' 在 3.8.x 不存在,统一使用已验证可用的 'query-node-tree'
Editor.Message.request('scene', 'query-node-tree').then((tree: any) => {
if (rootUuid) {
const roots = Array.isArray(tree) ? tree : [tree];
let target: any = null;
for (const root of roots) {
target = findInTree(root, rootUuid);
if (target) {
break;
}
}
if (!target) {
resolve({ success: false, error: `Node not found: ${rootUuid}` });
return;
}
resolve({ success: true, data: mapTree(target, 0) });
} else {
const roots = Array.isArray(tree)
? tree
: (tree && Array.isArray(tree.children) ? tree.children : (tree ? [tree] : []));
const trees = roots.map((root: any) => mapTree(root, 0));
resolve({ success: true, data: trees }); resolve({ success: true, data: trees });
}).catch((err: Error) => { }
resolve({ success: false, error: err.message }); }).catch((err: Error) => {
}); resolve({ success: false, error: err.message });
} });
}); });
} }
@@ -359,8 +376,11 @@ export class DebugTools implements ToolExecutor {
// Check for performance issues // Check for performance issues
if (options.checkPerformance) { if (options.checkPerformance) {
const hierarchy = await Editor.Message.request('scene', 'query-hierarchy'); const hierarchy: any = await Editor.Message.request('scene', 'query-node-tree');
const nodeCount = this.countNodes(hierarchy.children); const roots = Array.isArray(hierarchy)
? hierarchy
: (hierarchy && Array.isArray(hierarchy.children) ? hierarchy.children : []);
const nodeCount = this.countNodes(roots);
if (nodeCount > 1000) { if (nodeCount > 1000) {
issues.push({ issues.push({