Ejemplo n.º 1
0
 protected void onEntityReleased(Entity entity)
 {
     if (entity._isEnabled) {
         throw new EntityIsNotDestroyedException("Cannot release " + entity + "!");
     }
     entity.removeAllOnEntityReleasedHandlers();
     _retainedEntities.Remove(entity);
     _reusableEntities.Push(entity);
 }
Ejemplo n.º 2
0
        /// Destroys the entity, removes all its components and pushs it back to the internal ObjectPool for entities.
        public virtual void DestroyEntity(Entity entity)
        {
            var removed = _entities.Remove(entity);
            if (!removed) {
                throw new PoolDoesNotContainEntityException("'" + this + "' cannot destroy " + entity + "!",
                    "Did you call pool.DestroyEntity() on a wrong pool?");
            }
            _entitiesCache = null;

            if (OnEntityWillBeDestroyed != null) {
                OnEntityWillBeDestroyed(this, entity);
            }

            entity.destroy();

            if (OnEntityDestroyed != null) {
                OnEntityDestroyed(this, entity);
            }

            if (entity.retainCount == 1) {
                // Can be released immediately without going to _retainedEntities
                entity.OnEntityReleased -= _cachedOnEntityReleased;
                _reusableEntities.Push(entity);
                entity.Release(this);
                entity.removeAllOnEntityReleasedHandlers();
            } else {
                _retainedEntities.Add(entity);
                entity.Release(this);
            }
        }