Ejemplo n.º 1
0
        public void ProcessInput(Scene scene)
        {
            var hardwareInput = _inputProvider.Capture();

            foreach (var entity in scene.AllEntities.ToList())
            {
                if (entity.HasComponent <InputComponent>())
                {
                    var input = entity.GetComponent <InputComponent>();
                    input.HardwareInput = hardwareInput;

                    HandleActionMappings(input);
                    HandleAxisMappings(input);
                }
            }
        }
Ejemplo n.º 2
0
        public void ProcessInput_ShouldCallActionBindingsCorrectNumberOfTimes_WhenExecutedTwice(bool first, bool second,
                                                                                                int expectedCount)
        {
            // Arrange
            var inputSceneBuilder = new InputSceneBuilder();

            inputSceneBuilder.AddInputWithSampleKeyboardActionMappings(out var inputComponent, out var moveRight, out _, out _);
            var scene = inputSceneBuilder.Build();

            var hardwareInput1 = GetKeyboardInput(new KeyboardInputBuilder
            {
                Up    = false,
                Down  = false,
                Right = first,
                Left  = false,
                Space = false
            });

            var hardwareInput2 = GetKeyboardInput(new KeyboardInputBuilder
            {
                Up    = false,
                Down  = false,
                Right = second,
                Left  = false,
                Space = false
            });

            // fill in action states based on hardwareInput
            _inputProvider.Capture().Returns(hardwareInput1);
            _inputSystem.ProcessInput(scene);

            var callCounter = 0;

            inputComponent.BindAction(moveRight.ActionName, () => { callCounter++; });

            // Act
            _inputProvider.Capture().Returns(hardwareInput1);
            _inputSystem.ProcessInput(scene);

            _inputProvider.Capture().Returns(hardwareInput2);
            _inputSystem.ProcessInput(scene);

            // Assert
            Assert.That(callCounter, Is.EqualTo(expectedCount));
        }