* 在场景的实体列表中添加一个实体 * @param entity 要添加的实体 * @param deferCacheClear 是否延迟缓存清理(用于批量操作)
(entity: Entity, deferCacheClear: boolean = false)
| 771 | * @param deferCacheClear 是否延迟缓存清理(用于批量操作) |
| 772 | */ |
| 773 | public addEntity(entity: Entity, deferCacheClear: boolean = false) { |
| 774 | this.entities.add(entity); |
| 775 | entity.scene = this; |
| 776 | |
| 777 | this.querySystem.addEntity(entity, deferCacheClear); |
| 778 | |
| 779 | if (!deferCacheClear) { |
| 780 | this.clearSystemEntityCaches(); |
| 781 | } |
| 782 | |
| 783 | this.eventSystem.emitSync('entity:added', { entity, scene: this }); |
| 784 | |
| 785 | return entity; |
| 786 | } |
| 787 | |
| 788 | /** |
| 789 | * 批量创建实体(高性能版本) |
no test coverage detected