Beispiel #1
0
        public virtual void RemoveEntity(Entity entity) {
            var removed = _entities.Remove(entity);

            if (!removed)
                throw new EntityNotInPoolException(entity, "Could not remove entity");

            // Inform subscribers the entity is going to be removed
            OnEntityRemoving.Invoke(this, new PoolChanged(this, entity));

            // Prepare it for removal
            entity.Destroy();

            // Inform subscribers the entity has been removed
            OnEntityRemoved.Invoke(this, new PoolChanged(this, entity));

            // Remove the item from memory
            entity.Dispose();
        }
        public void ObjectRemovedInvokedWhenAnEntityIsDestroyed()
        {
            var entity = new Entity(new VariableCollection());
            this.collection.Add(entity);
            var called = false;
            collection.ObjectRemoved += (x) => { called = true; };
            entity.Destroy();
            MonocleObject.LifeTimeManager.DestroyObjectsFlaggedForDestruction();

            Assert.IsTrue(called);
        }
        public void ObjectAddedInvokedWhenAnEntityIsAdded()
        {
            Entity e = null;
            collection.ObjectAdded += (x) => { e = (Entity)x; };
            var entity = new Entity(new VariableCollection());
            collection.Add(entity);

            Assert.AreSame(e, entity);

            entity.Destroy();
        }
        public void EntityCanBeAdded()
        {
            var entity = new Entity(new VariableCollection());
            collection.Add(entity);

            Assert.NotNull(collection.Find((x) => true));
            entity.Destroy();
        }
        public void ComponentCreatedInvokedWhenAComponentIsCreated()
        {
            var entity = new Entity(new VariableCollection());
            this.collection.Add(entity);
            var called = false;
            collection.ObjectAdded += (x) => { called = true; };
            entity.AddComponent<FakeComp>();
            Assert.IsTrue(called);

            entity.Destroy();
        }
 public static void Kill(Monster monster, Entity sender, EventArgs args)
 {
     if (sender is Unit)
         (sender as Unit).Kill();
     else
         sender.Destroy();
 }
 //-----------------------------------------------------------------------------
 // Basic Sender Reactions
 //-----------------------------------------------------------------------------
 public static void Destroy(Monster monster, Entity sender, EventArgs args)
 {
     sender.Destroy();
 }
 // Burn the monster for 1 damage.
 public static void Burn(Monster monster, Entity sender, EventArgs args)
 {
     monster.Burn(1);
     if (sender is Fire)
         sender.Destroy();
 }
        public void DestroyAlsoDestroysAllChildren()
        {
            var entity1 = new Entity(new VariableCollection());
            entity.Parent = entity1;

            entity1.Destroy();
            MonocleObject.LifeTimeManager.DestroyObjectsFlaggedForDestruction();

            Assert.IsTrue(entity == null);
        }