/// <summary> /// Removes components marked for removal. /// </summary> internal void RemoveMarkedComponents() { foreach (Tuple <Entity, ComponentType> pair in this.componentsToBeRemoved) { Entity entity = pair.Item1; ComponentType componentType = pair.Item2; int entityId = entity.Index; Bag <IEntityComponent> components = this.componentsByType.Get(componentType.Id); if (components != null && entityId < components.Count) { IEntityComponent componentToBeRemoved = components.Get(entityId); if (RemovedComponentEvent != null && componentToBeRemoved != null) { RemovedComponentEvent(entity, componentToBeRemoved); } entity.RemoveTypeBit(componentType.Bit); this.entityWorld.RefreshEntity(entity); components.Set(entityId, null); } } this.componentsToBeRemoved.Clear(); }
/// <summary> /// Strips all components from the given entity. /// </summary> /// <param name="entity">Entity for which you want to remove all components</param> internal void RemoveComponentsOfEntity(Entity entity) { Debug.Assert(entity != null, "Entity must not be null."); entity.TypeBits = 0; this.entityWorld.RefreshEntity(entity); int entityId = entity.Index; for (int index = this.componentsByType.Count - 1; index >= 0; --index) { Bag <IEntityComponent> components = this.componentsByType.Get(index); if (components != null && entityId < components.Count) { IEntityComponent componentToBeRemoved = components.Get(entityId); if (RemovedComponentEvent != null && componentToBeRemoved != null) { RemovedComponentEvent(entity, componentToBeRemoved); } components.Set(entityId, null); } } }