Implement rudimentary joystick deadzone support.

This commit is contained in:
Rune Skovbo Johansen 2016-02-23 13:11:14 +01:00
Родитель ab7569e9e6
Коммит 29a80d34ad
4 изменённых файлов: 23 добавлений и 11 удалений

Просмотреть файл

@ -15,11 +15,11 @@ namespace UnityEngine.InputNew
SetMappingsCount(gamepad.controlCount, gamepad.controlCount);
SetMapping(00, gamepad.leftStickX.index, "Left Stick X");
SetMapping(01, gamepad.leftStickY.index, "Left Stick Y", Range.fullInverse, Range.full);
SetMapping(01, gamepad.leftStickY.index, "Left Stick Y", defaultDeadZones, Range.fullInverse, Range.full);
SetMapping(21, gamepad.leftStickButton.index, "Left Stick Button");
SetMapping(02, gamepad.rightStickX.index, "Right Stick X");
SetMapping(03, gamepad.rightStickY.index, "Right Stick Y", Range.fullInverse, Range.full);
SetMapping(03, gamepad.rightStickY.index, "Right Stick Y", defaultDeadZones, Range.fullInverse, Range.full);
SetMapping(22, gamepad.rightStickButton.index, "Right Stick Button");
SetMapping(15, gamepad.dPadUp.index, "DPad Up");
@ -32,8 +32,8 @@ namespace UnityEngine.InputNew
SetMapping(28, gamepad.action3.index, "X");
SetMapping(29, gamepad.action4.index, "Y");
SetMapping(04, gamepad.leftTrigger.index, "Left Trigger", Range.full, Range.positive);
SetMapping(05, gamepad.rightTrigger.index, "Right Trigger", Range.full, Range.positive);
SetMapping(04, gamepad.leftTrigger.index, "Left Trigger", defaultDeadZones, Range.full, Range.positive);
SetMapping(05, gamepad.rightTrigger.index, "Right Trigger", defaultDeadZones, Range.full, Range.positive);
SetMapping(23, gamepad.leftBumper.index, "Left Bumper");
SetMapping(24, gamepad.rightBumper.index, "Right Bumper");

Просмотреть файл

@ -15,11 +15,11 @@ namespace UnityEngine.InputNew
SetMappingsCount(gamepad.controlDataList.Count, gamepad.controlDataList.Count);
SetMapping(00, gamepad.leftStickX.index, "Left Stick X");
SetMapping(01, gamepad.leftStickY.index, "Left Stick Y", Range.fullInverse, Range.full);
SetMapping(01, gamepad.leftStickY.index, "Left Stick Y", defaultDeadZones, Range.fullInverse, Range.full);
SetMapping(18, gamepad.leftStickButton.index, "Left Stick Button");
SetMapping(03, gamepad.rightStickX.index, "Right Stick X");
SetMapping(04, gamepad.rightStickY.index, "Right Stick Y", Range.fullInverse, Range.full);
SetMapping(04, gamepad.rightStickY.index, "Right Stick Y", defaultDeadZones, Range.fullInverse, Range.full);
SetMapping(19, gamepad.rightStickButton.index, "Right Stick Button");
SetMapping(06, gamepad.dPadUp.index, "DPad Up");
@ -32,8 +32,8 @@ namespace UnityEngine.InputNew
SetMapping(12, gamepad.action3.index, "X");
SetMapping(13, gamepad.action4.index, "Y");
SetMapping(08, gamepad.leftTrigger.index, "Left Trigger", Range.full, Range.positive);
SetMapping(09, gamepad.rightTrigger.index, "Right Trigger", Range.full, Range.positive);
SetMapping(08, gamepad.leftTrigger.index, "Left Trigger", defaultDeadZones, Range.full, Range.positive);
SetMapping(09, gamepad.rightTrigger.index, "Right Trigger", defaultDeadZones, Range.full, Range.positive);
SetMapping(14, gamepad.leftBumper.index, "Left Bumper");
SetMapping(15, gamepad.rightBumper.index, "Right Bumper");

Просмотреть файл

@ -11,5 +11,6 @@ namespace UnityEngine.InputNew
public int targetIndex;
public Range fromRange;
public Range toRange;
public Range interDeadZoneRange;
}
}

Просмотреть файл

@ -11,6 +11,8 @@ namespace UnityEngine.InputNew
public JoystickControlMapping[] mappings;
public string[] nameOverrides;
protected static Range defaultDeadZones = new Range(0.2f, 0.9f);
#endregion
#region Public Methods
@ -26,6 +28,9 @@ namespace UnityEngine.InputNew
controlEvent.controlIndex = mapping.targetIndex;
controlEvent.value = Mathf.InverseLerp(mapping.fromRange.min, mapping.fromRange.max, controlEvent.value);
controlEvent.value = Mathf.Lerp(mapping.toRange.min, mapping.toRange.max, controlEvent.value);
Range deadZones = mapping.interDeadZoneRange;
controlEvent.value = Mathf.InverseLerp(deadZones.min, deadZones.max, Mathf.Abs(controlEvent.value))
* Mathf.Sign(controlEvent.value);
}
}
}
@ -38,16 +43,22 @@ namespace UnityEngine.InputNew
public void SetMapping(int sourceControlIndex, int targetControlIndex, string displayName)
{
SetMapping(sourceControlIndex, targetControlIndex, displayName, Range.full, Range.full);
SetMapping(sourceControlIndex, targetControlIndex, displayName, defaultDeadZones, Range.full, Range.full);
}
public void SetMapping(int sourceControlIndex, int targetControlIndex, string displayName, Range sourceRange, Range targetRange)
public void SetMapping(int sourceControlIndex, int targetControlIndex, string displayName, Range interDeadZoneRange)
{
SetMapping(sourceControlIndex, targetControlIndex, displayName, interDeadZoneRange, Range.full, Range.full);
}
public void SetMapping(int sourceControlIndex, int targetControlIndex, string displayName, Range interDeadZoneRange, Range sourceRange, Range targetRange)
{
mappings[sourceControlIndex] = new JoystickControlMapping
{
targetIndex = targetControlIndex,
fromRange = sourceRange,
toRange = targetRange
toRange = targetRange,
interDeadZoneRange = interDeadZoneRange
};
nameOverrides[targetControlIndex] = displayName;
}