예제 #1
0
        public void AllAnyFilterTest()
        {
            List <IEcsEntity> entities = new List <IEcsEntity>
            {
                _entityABD
            };

            IEcsGroup group = _world.Filter(new EcsFilter().AllOf <ComponentB, ComponentB, ComponentD>().AnyOf <ComponentA>());

            Assert.AreEqual(entities.Count, group.CalculateCount());
            group.ForEach(entity =>
            {
                Assert.IsTrue(entities.Contains(entity));
            });



            entities = new List <IEcsEntity>
            {
                _entityABD, _entityBD0, _entityBD1
            };

            group = _world.Filter(new EcsFilter().AllOf <ComponentD, ComponentD>().AnyOf <ComponentB, ComponentC, ComponentC>());
            Assert.AreEqual(entities.Count, group.CalculateCount());
            group.ForEach(entity =>
            {
                Assert.IsTrue(entities.Contains(entity));
            });
        }
예제 #2
0
        public void AllFilterTest()
        {
            List <IEcsEntity> entities = new List <IEcsEntity>
            {
                _entityABD, _entityBD0, _entityBD1, _entityBC, _entityAB
            };

            IEcsGroup group = _world.Filter(new EcsFilter().AllOf <ComponentB>());

            Assert.AreEqual(entities.Count, group.CalculateCount());
            group.ForEach((IEcsEntity entity, ComponentB compB) =>
            {
                Assert.IsTrue(entities.Contains(entity));
            });



            entities = new List <IEcsEntity>
            {
                _entityABD, _entityBD0, _entityBD1
            };

            group = _world.Filter(new EcsFilter().AllOf <ComponentB, ComponentD>());
            Assert.AreEqual(3, group.CalculateCount());
            group.ForEach((IEcsEntity entity, ComponentB compB, ComponentD compD) =>
            {
                Assert.IsTrue(entities.Contains(entity));
            });
        }
예제 #3
0
    private static void CreateOrDestroyEntities(EcsWorld world, EcsFilter filter, int count, Action <EcsWorld> createEntity)
    {
        IEcsGroup group = world.Filter(filter);

        if (group.CalculateCount() == count)
        {
            return;
        }

        IEcsEntity[] entities = group.ToEntityArray();
        for (int i = entities.Length; i < count; i++)
        {
            createEntity(world);
        }

        for (int i = count; i < entities.Length; i++)
        {
            IEcsEntity             entity    = entities[i];
            BroadphaseRefComponent brRef     = entity.GetComponent <BroadphaseRefComponent>();
            CharacterComponent     character = entity.GetComponent <CharacterComponent>();

            Object.Destroy(character.Ref.gameObject);

            foreach (SAPChunk chunk in brRef.Chunks)
            {
                BroadphaseHelper.RemoveFormChunk(chunk, entity.Id);
            }

            entity.Destroy();
        }
    }
예제 #4
0
        public void NoneFilterTest()
        {
            List <IEcsEntity> entities = new List <IEcsEntity>
            {
                _entityAC
            };

            IEcsGroup group = _world.Filter(new EcsFilter().NoneOf <ComponentB, ComponentD>());

            Assert.AreEqual(entities.Count, group.CalculateCount());
            group.ForEach(entity =>
            {
                Assert.IsTrue(entities.Contains(entity));
            });



            group = _world.Filter(new EcsFilter().NoneOf <ComponentB, ComponentD, ComponentB>());
            Assert.AreEqual(entities.Count, group.CalculateCount());
            group.ForEach(entity =>
            {
                Assert.IsTrue(entities.Contains(entity));
            });
        }