コード例 #1
0
        public void DestroyEntity()
        {
            ECSWorld world  = new ECSWorld();
            var      buffer = new EntityCommandBuffer(world);

            SharedComponent1 shared1   = new SharedComponent1();
            EntityArchetype  archetype = EntityArchetype.Empty;

            archetype = archetype.Add <TestComponent1>();
            archetype = archetype.AddShared(shared1);


            buffer.CreateEntity(archetype);
            buffer.Playback();

            ComponentQuery query = new ComponentQuery();

            query.IncludeReadWrite <TestComponent1>();
            query.IncludeShared <SharedComponent1>();

            Entity e = default;

            Assert.Collection(world.ComponentManager.GetBlocks(query), accessor => {
                Assert.Equal(1, accessor.GetEntityData().Length);
                e = accessor.GetEntityData()[0];
            });

            buffer.DestroyEntity(e);
            buffer.Playback();

            Assert.Empty(world.ComponentManager.GetBlocks(query));
        }
コード例 #2
0
        public void RemoveSharedComponentFromEntity()
        {
            ECSWorld world  = new ECSWorld();
            var      buffer = new EntityCommandBuffer(world);

            SharedComponent1 shared1   = new SharedComponent1();
            EntityArchetype  archetype = EntityArchetype.Empty;

            archetype = archetype.Add <TestComponent1>();
            archetype = archetype.AddShared(shared1);

            Entity target = world.Instantiate(archetype);

            buffer.RemoveSharedComponent <SharedComponent1>(target);
            buffer.Playback();

            ComponentQuery query = new ComponentQuery();

            query.IncludeReadWrite <TestComponent1>();
            query.ExcludeShared <SharedComponent1>();

            Assert.Collection(world.ComponentManager.GetBlocks(query), accessor => {
                Assert.Equal(1, accessor.GetEntityData().Length);
            });
        }
コード例 #3
0
        public void SetComponentToEntity()
        {
            ECSWorld world  = new ECSWorld();
            var      buffer = new EntityCommandBuffer(world);

            SharedComponent1 shared1   = new SharedComponent1();
            EntityArchetype  archetype = EntityArchetype.Empty;

            archetype = archetype.Add <TestComponent1>();
            archetype = archetype.AddShared(shared1);

            Entity target = world.Instantiate(archetype);

            buffer.SetComponent(target, new TestComponent1 {
                i = 2, d = 3, f = 4
            });
            buffer.Playback();

            ComponentQuery query = new ComponentQuery();

            query.IncludeReadWrite <TestComponent1>();
            query.IncludeShared <SharedComponent1>();

            Assert.Collection(world.ComponentManager.GetBlocks(query), accessor => {
                Assert.Equal(1, accessor.GetEntityData().Length);

                var cData = accessor.GetComponentData <TestComponent1>();
                Assert.Equal(2, cData[0].i);
                Assert.Equal(3d, cData[0].d, 3);
                Assert.Equal(4f, cData[0].f, 3);
            });
        }
コード例 #4
0
        private static EntityArchetype CreateCameraArchetype()
        {
            EntityArchetype archetype = new EntityArchetype();

            Camera camera = new Camera();

            camera.aspect    = (float)Window.window.Width / (float)Window.window.Height;
            camera.fow       = 60f;
            camera.nearPlane = 0.01f;
            camera.farPlane  = 1000f;

            archetype = archetype.AddShared(camera);
            archetype = archetype.AddShared(CameraAutoScaleAspectComponent.Instance);
            archetype = archetype.AddShared(MainCameraTag.Instance);
            archetype = archetype.Add <Position>();
            archetype = archetype.Add <Rotation>();
            return(archetype);
        }
コード例 #5
0
        public ComponentQueryTests()
        {
            var shared1 = new SharedComponent1();
            var shared2 = new SharedComponent2();

            archetypeC1       = EntityArchetype.Empty.Add <TestComponent1>();
            archetypeC1C2     = archetypeC1.Add <TestComponent2>();
            archetypeC1S1     = archetypeC1.AddShared(shared1);
            archetypeC1C2S1   = archetypeC1S1.Add <TestComponent2>();
            archetypeC1C2S1S2 = archetypeC1C2S1.AddShared(shared2);

            archetypeC2S1 = EntityArchetype.Empty.Add <TestComponent2>().AddShared(shared1);
        }