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)); }); }
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)); }); }
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(); } }
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)); }); }