MCPcopy Create free account
hub / github.com/esengine/esengine / queryEntities

Method queryEntities

packages/core/src/Plugins/DebugPlugin.ts:277–320  ·  view source on GitHub ↗

* 查询实体 * * @param filter - 查询过滤器

(filter: {
        sceneName?: string;
        tag?: number;
        name?: string;
        hasComponent?: string;
    })

Source from the content-addressed store, hash-verified

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 * 打印统计信息到日志

Callers 5

entitiesFunction · 0.45
initializeFunction · 0.45
updateFunction · 0.45
lateUpdateFunction · 0.45

Calls 5

getEntityInfoMethod · 0.95
pushMethod · 0.65
getAllWorldsMethod · 0.45
getAllScenesMethod · 0.45
someMethod · 0.45

Tested by

no test coverage detected