public override void deactivateForStorage(EntityRef entity) { if (entity.exists()) { int entityId = entity.Id; if (eventSystem != null) { eventSystem.send(entity, BeforeDeactivateComponent.newInstance()); } loadedIds.remove(entityId); store.remove(entityId); } }
/// <summary> /// Removes a component from an entity /// </summary> /// <param name="entityId"> </param> /// <param name="componentClass"> </param> public override T removeComponent <T>(int entityId, Type componentClass) where T : org.terasology.entitySystem.Component { T component = store.get(entityId, componentClass); if (component != null) { if (eventSystem != null) { EntityRef entityRef = createEntityRef(entityId); eventSystem.send(entityRef, BeforeDeactivateComponent.newInstance(), component); eventSystem.send(entityRef, BeforeRemoveComponent.newInstance(), component); } notifyComponentRemoved(getEntity(entityId), componentClass); store.remove(entityId, componentClass); } return(component); }
/// <summary> /// Destroys this entity, sending event /// </summary> /// <param name="entityId"> </param> public override void destroy(int entityId) { // Don't allow the destruction of unloaded entities. if (!loadedIds.contains(entityId)) { return; } EntityRef @ref = createEntityRef(entityId); if (eventSystem != null) { eventSystem.send(@ref, BeforeDeactivateComponent.newInstance()); eventSystem.send(@ref, BeforeRemoveComponent.newInstance()); } foreach (Component comp in store.iterateComponents(entityId)) { notifyComponentRemoved(@ref, comp.GetType()); } destroy(@ref); foreach (EntityDestroySubscriber destroySubscriber in destroySubscribers) { destroySubscriber.onEntityDestroyed(entityId); } }