Пример #1
0
 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);
     }
 }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <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);
            }
        }