* 查询实体 * * @param filter - 查询过滤器
(filter: {
sceneName?: string;
tag?: number;
name?: string;
hasComponent?: string;
})
| 275 | * @param filter - 查询过滤器 |
| 276 | */ |
| 277 | public queryEntities(filter: { |
| 278 | sceneName?: string; |
| 279 | tag?: number; |
| 280 | name?: string; |
| 281 | hasComponent?: string; |
| 282 | }): EntityDebugInfo[] { |
| 283 | if (!this.worldManager) { |
| 284 | throw new Error('Plugin not installed'); |
| 285 | } |
| 286 | |
| 287 | const results: EntityDebugInfo[] = []; |
| 288 | const worlds = this.worldManager.getAllWorlds(); |
| 289 | |
| 290 | for (const world of worlds) { |
| 291 | for (const scene of world.getAllScenes()) { |
| 292 | if (filter.sceneName && scene.name !== filter.sceneName) { |
| 293 | continue; |
| 294 | } |
| 295 | |
| 296 | for (const entity of scene.entities.buffer) { |
| 297 | if (filter.tag !== undefined && entity.tag !== filter.tag) { |
| 298 | continue; |
| 299 | } |
| 300 | |
| 301 | if (filter.name && !entity.name.includes(filter.name)) { |
| 302 | continue; |
| 303 | } |
| 304 | |
| 305 | if (filter.hasComponent) { |
| 306 | const hasComp = entity.components.some( |
| 307 | (c) => c.constructor.name === filter.hasComponent |
| 308 | ); |
| 309 | if (!hasComp) { |
| 310 | continue; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | results.push(this.getEntityInfo(entity)); |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | return results; |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * 打印统计信息到日志 |
no test coverage detected