Exemple #1
0
        private static void HandleAxisMappings(InputComponent inputComponent)
        {
            ResetAxisStates(inputComponent);
            if (inputComponent.InputMapping == null)
            {
                return;
            }

            var axisMappings = inputComponent.InputMapping.AxisMappings;

            foreach (var axisMapping in axisMappings)
            {
                var axisName = axisMapping.AxisName;

                foreach (var hardwareAxis in axisMapping.HardwareAxes)
                {
                    var state       = ComputeState(inputComponent.HardwareInput, hardwareAxis);
                    var scaledState = state * hardwareAxis.Scale;

                    if (inputComponent.AxisStates.ContainsKey(axisName))
                    {
                        inputComponent.AxisStates[axisName] += scaledState;
                    }
                    else
                    {
                        inputComponent.AxisStates[axisName] = scaledState;
                    }
                }

                if (inputComponent.AxisBindings.ContainsKey(axisName))
                {
                    inputComponent.AxisBindings[axisName](inputComponent.GetAxisState(axisName));
                }
            }
        }
        public void GetAxisState_ShouldReturnAxisState()
        {
            // Arrange
            var inputComponent = new InputComponent();

            const string axisName  = "AxisName";
            const double axisState = Math.PI;

            inputComponent.AxisStates[axisName] = axisState;

            // Act
            var actual = inputComponent.GetAxisState(axisName);

            // Assert
            Assert.That(actual, Is.EqualTo(axisState));
        }