* 批量创建实体(高性能版本) * @param count 要创建的实体数量 * @param namePrefix 实体名称前缀 * @returns 创建的实体列表
(count: number, namePrefix: string = 'Entity')
| 792 | * @returns 创建的实体列表 |
| 793 | */ |
| 794 | public createEntities(count: number, namePrefix: string = 'Entity'): Entity[] { |
| 795 | const entities: Entity[] = []; |
| 796 | |
| 797 | for (let i = 0; i < count; i++) { |
| 798 | const entity = new Entity(`${namePrefix}_${i}`, this.identifierPool.checkOut()); |
| 799 | entity.scene = this; |
| 800 | |
| 801 | const handle = this.handleManager.create(); |
| 802 | entity.setHandle(handle); |
| 803 | this._handleToEntity.set(handle, entity); |
| 804 | |
| 805 | entities.push(entity); |
| 806 | } |
| 807 | |
| 808 | for (const entity of entities) { |
| 809 | this.entities.add(entity); |
| 810 | } |
| 811 | |
| 812 | this.querySystem.addEntitiesUnchecked(entities); |
| 813 | this.eventSystem.emitSync('entities:batch_added', { entities, scene: this, count }); |
| 814 | |
| 815 | return entities; |
| 816 | } |
| 817 | |
| 818 | /** |
| 819 | * 批量销毁实体 |