示例#1
0
        public void CreateEntityBeforeUpdate()
        {
            EcsService service = EcsServiceFactory.CreateECSManager();

            Entity entity = service.CreateEntityFromTemplate <TestEntityTemplate>();

            Assert.That(entity.Transform, Is.Not.Null);

            ComponentA component = entity.GetComponent <ComponentA>();

            Assert.That(component.Transform, Is.Not.Null);

            Assert.That(!component.IsStarted);
            Assert.That(!component.IsUpdated);
            Assert.That(!component.IsDrew);
            Assert.That(!component.IsDestroyed);

            service.Update(new GameTime());
            service.Draw(new GameTime());

            Assert.That(component.IsStarted);
            Assert.That(component.IsUpdated);
            Assert.That(component.IsDrew);
            Assert.That(!component.IsDestroyed);
        }
        public void DrawDisabledHierarchicalEntities()
        {
            EcsService service = EcsServiceFactory.CreateECSManager();

            Entity entity      = service.CreateEntityFromTemplate <TestEntityTemplate>();
            Entity entityChild = service.CreateEntityFromTemplate <TestEntityTemplate>();

            entityChild.Transform.Parent = entity.Transform;

            ComponentA component      = entity.GetComponent <ComponentA>();
            ComponentA componentChild = entityChild.GetComponent <ComponentA>();

            entity.Enabled = false;

            service.Update(new GameTime());
            service.Draw(new GameTime());

            Assert.That(entity.EnabledInHierarchy, Is.False);
            Assert.That(component.IsStarted, Is.True);
            Assert.That(component.IsDrew, Is.False);

            Assert.That(entityChild.EnabledInHierarchy, Is.False);
            Assert.That(componentChild.IsStarted, Is.True);
            Assert.That(componentChild.IsDrew, Is.False);
        }
        public void EntityDestroyDuringDraw()
        {
            EcsService service = EcsServiceFactory.CreateECSManager();
            Entity     entity  = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>();

            var component = entity.GetComponent <ConfigurableComponent>();

            component.OnDrawAction = configurableComponent =>
            {
                configurableComponent.Entity.Destroy();
            };

            service.Update(new GameTime());
            Assert.That(() => service.Draw(new GameTime()), Throws.Exception.TypeOf <EcsWorkflowException>());
        }
示例#4
0
        public void CreateEntityWithComponentWhichRemovesItselfOnUpdate()
        {
            EcsService service   = EcsServiceFactory.CreateECSManager();
            Entity     entity    = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>();
            var        component = entity.GetComponent <ConfigurableComponent>();

            component.OnUpdateAction = configurableComponent =>
            {
                configurableComponent.Destroy();
            };

            service.Update(new GameTime());
            service.Draw(new GameTime());

            Assert.That(entity.GetComponent <ConfigurableComponent>(), Is.Null);
        }
示例#5
0
        public void CreateEntityWithComponentWhichAddedAnotherComponentDuringStart()
        {
            EcsService service   = EcsServiceFactory.CreateECSManager();
            Entity     entity    = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>();
            var        component = entity.GetComponent <ConfigurableComponent>();

            component.OnStartAction = configurableComponent =>
            {
                configurableComponent.Entity.AddComponent <ComponentA>();
            };

            service.Update(new GameTime());
            service.Draw(new GameTime());

            var componentA = entity.GetComponent <ComponentA>();

            Assert.That(componentA, Is.Not.Null);
            Assert.That(componentA.IsStarted, Is.True);
        }
        public void DrawEntityWhenChildChangedEnableness()
        {
            EcsService service = EcsServiceFactory.CreateECSManager();

            Entity entity      = service.CreateEntityFromTemplate <TestEntityTemplate>();
            Entity entityChild = service.CreateEntityFromTemplate <ConfigurableComponentTemplate>();

            entityChild.Transform.Parent = entity.Transform;

            var component      = entity.GetComponent <ComponentA>();
            var componentChild = entityChild.GetComponent <ConfigurableComponent>();

            componentChild.OnDrawAction = configurableComponent =>
            {
                configurableComponent.Entity.Transform.Parent.Entity.Enabled = false;
            };

            service.Update(new GameTime());
            service.Draw(new GameTime());

            Assert.That(entity.EnabledInHierarchy, Is.False);
            Assert.That(component.IsStarted, Is.True);
            Assert.That(component.IsDrew, Is.False);
        }