Пример #1
0
        void onEntityReleased(Entity entity)
        {
            if (entity.isEnabled)
            {
                throw new EntityIsNotDestroyedException(
                          "Cannot release " + entity + "!"
                          );
            }
            var tEntity = (Entity)entity;

            entity.RemoveAllOnEntityReleasedHandlers();
            _retainedEntities.Remove(tEntity);
            _reusableEntities.Push(tEntity);
        }
Пример #2
0
        /// Destroys the entity, removes all its components and pushs it back
        /// to the internal ObjectPool for entities.
        private void DestroyEntity(Entity entity)
        {
            var removed = _entities.Remove(entity);

            if (!removed)
            {
                throw new ContextDoesNotContainEntityException(
                          "'" + this + "' cannot destroy " + entity + "!",
                          "This cannot happen!?!"
                          );
            }
            _entitiesCache = null;

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

            entity.InternalDestroy();

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

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