* 从查询系统移除实体 * * 从查询系统中移除指定实体,并清理相关索引。 * * @param entity 要移除的实体
(entity: Entity)
| 193 | * @param entity 要移除的实体 |
| 194 | */ |
| 195 | public removeEntity(entity: Entity): void { |
| 196 | const index = this._entities.indexOf(entity); |
| 197 | if (index !== -1) { |
| 198 | const componentTypes: ComponentType[] = []; |
| 199 | for (const component of entity.components) { |
| 200 | componentTypes.push(component.constructor as ComponentType); |
| 201 | } |
| 202 | |
| 203 | this._entities.splice(index, 1); |
| 204 | this.removeEntityFromIndexes(entity); |
| 205 | |
| 206 | this._archetypeSystem.removeEntity(entity); |
| 207 | |
| 208 | if (componentTypes.length > 0) { |
| 209 | this.notifyReactiveQueriesEntityRemoved(entity, componentTypes); |
| 210 | } else { |
| 211 | this.notifyReactiveQueriesEntityRemovedFallback(entity); |
| 212 | } |
| 213 | |
| 214 | this.clearQueryCache(); |
| 215 | |
| 216 | this._version++; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * 更新实体在查询系统中的索引 |
nothing calls this directly
no test coverage detected