void TestInputMapping(InputControlMapping.Range sourceRange, InputControlMapping.Range targetRange, bool invert, float expectA, float expectB, float expectC) { var mapping = new InputControlMapping() { SourceRange = sourceRange, TargetRange = targetRange, Invert = invert }; float input; float value; string sr = "Complete"; if (sourceRange == InputControlMapping.Range.Negative) { sr = "Negative"; } else if (sourceRange == InputControlMapping.Range.Positive) { sr = "Positive"; } string tr = "Complete"; if (targetRange == InputControlMapping.Range.Negative) { tr = "Negative"; } else if (targetRange == InputControlMapping.Range.Positive) { tr = "Positive"; } input = -1.0f; value = mapping.MapValue(input); if (Mathf.Abs(value - expectA) > Single.Epsilon) { Debug.LogError("Input of " + input + " got value of " + value + " instead of " + expectA + " (SR = " + sr + ", TR = " + tr + ")"); } input = 0.0f; value = mapping.MapValue(input); if (Mathf.Abs(value - expectB) > Single.Epsilon) { Debug.LogError("Input of " + input + " got value of " + value + " instead of " + expectB + " (SR = " + sr + ", TR = " + tr + ")"); } input = 1.0f; value = mapping.MapValue(input); if (Mathf.Abs(value - expectC) > Single.Epsilon) { Debug.LogError("Input of " + input + " got value of " + value + " instead of " + expectC + " (SR = " + sr + ", TR = " + tr + ")"); } }
public override void Update(ulong updateTick, float deltaTime) { if (skipUpdateFrames > 0) { skipUpdateFrames--; return; } if (Native.GetDeviceState(Handle, out IntPtr deviceState)) { Marshal.Copy(deviceState, buttons, 0, buttons.Length); deviceState = new IntPtr(deviceState.ToInt64() + buttons.Length * 2); Marshal.Copy(deviceState, analogs, 0, analogs.Length); } if (IsKnown) { int analogCount = profile.AnalogCount; for (int i = 0; i < analogCount; i++) { InputControlMapping inputControlMapping = profile.AnalogMappings[i]; float value = inputControlMapping.Source.GetValue(this); InputControl control = GetControl(inputControlMapping.Target); if (!inputControlMapping.IgnoreInitialZeroValue || !control.IsOnZeroTick || !Utility.IsZero(value)) { float value2 = inputControlMapping.MapValue(value); control.UpdateWithValue(value2, updateTick, deltaTime); } } int buttonCount = profile.ButtonCount; for (int j = 0; j < buttonCount; j++) { InputControlMapping inputControlMapping2 = profile.ButtonMappings[j]; bool state = inputControlMapping2.Source.GetState(this); UpdateWithState(inputControlMapping2.Target, state, updateTick, deltaTime); } } else { for (int k = 0; k < NumUnknownButtons; k++) { UpdateWithState((InputControlType)(500 + k), ReadRawButtonState(k), updateTick, deltaTime); } for (int l = 0; l < NumUnknownAnalogs; l++) { UpdateWithValue((InputControlType)(400 + l), ReadRawAnalogValue(l), updateTick, deltaTime); } } }
public override void Update(ulong updateTick, float deltaTime) { if (IsKnown) { int analogCount = profile.AnalogCount; for (int i = 0; i < analogCount; i++) { InputControlMapping inputControlMapping = profile.AnalogMappings[i]; float value = inputControlMapping.Source.GetValue(this); InputControl control = GetControl(inputControlMapping.Target); if (!inputControlMapping.IgnoreInitialZeroValue || !control.IsOnZeroTick || !Utility.IsZero(value)) { float value2 = inputControlMapping.MapValue(value); control.UpdateWithValue(value2, updateTick, deltaTime); } } int buttonCount = profile.ButtonCount; for (int j = 0; j < buttonCount; j++) { InputControlMapping inputControlMapping2 = profile.ButtonMappings[j]; bool state = inputControlMapping2.Source.GetState(this); UpdateWithState(inputControlMapping2.Target, state, updateTick, deltaTime); } } else { for (int k = 0; k < NumUnknownButtons; k++) { UpdateWithState((InputControlType)(500 + k), ReadRawButtonState(k), updateTick, deltaTime); } for (int l = 0; l < NumUnknownAnalogs; l++) { UpdateWithValue((InputControlType)(400 + l), ReadRawAnalogValue(l), updateTick, deltaTime); } } }
void TestInputMapping( InputControlMapping.Range sourceRange, InputControlMapping.Range targetRange, bool invert, float expectA, float expectB, float expectC ) { var mapping = new InputControlMapping() { SourceRange = sourceRange, TargetRange = targetRange, Invert = invert }; float input; float value; string sr = "Complete"; if (sourceRange == InputControlMapping.Range.Negative) sr = "Negative"; else if (sourceRange == InputControlMapping.Range.Positive) sr = "Positive"; string tr = "Complete"; if (targetRange == InputControlMapping.Range.Negative) tr = "Negative"; else if (targetRange == InputControlMapping.Range.Positive) tr = "Positive"; input = -1.0f; value = mapping.MapValue( input ); if (Mathf.Abs( value - expectA ) > Single.Epsilon) { Debug.LogError( "Input of " + input + " got value of " + value + " instead of " + expectA + " (SR = " + sr + ", TR = " + tr + ")" ); } input = 0.0f; value = mapping.MapValue( input ); if (Mathf.Abs( value - expectB ) > Single.Epsilon) { Debug.LogError( "Input of " + input + " got value of " + value + " instead of " + expectB + " (SR = " + sr + ", TR = " + tr + ")" ); } input = 1.0f; value = mapping.MapValue( input ); if (Mathf.Abs( value - expectC ) > Single.Epsilon) { Debug.LogError( "Input of " + input + " got value of " + value + " instead of " + expectC + " (SR = " + sr + ", TR = " + tr + ")" ); } }