diff --git a/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput.cs b/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput.cs
index 8e7f25e..af5975f 100644
--- a/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput.cs
+++ b/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput.cs
@@ -751,8 +751,9 @@ public static float GetAxis(XboxAxis axis)
{
r = XInputGetAxisState(ctrlrState.ThumbSticks, axis);
}
+
+ r = XInputApplyDeadzone(r, axis, XboxController.All);
}
-
else
{
string axisCode = DetermineAxisCode(axis, 0);
@@ -799,8 +800,9 @@ public static float GetAxis(XboxAxis axis, XboxController controller)
{
r = XInputGetAxisState(ctrlrState.ThumbSticks, axis);
}
+
+ r = XInputApplyDeadzone(r, axis, controller);
}
-
else
{
string axisCode = DetermineAxisCode(axis, controllerNumber);
@@ -1672,6 +1674,51 @@ private static bool XInputStillInCurrFrame()
return r;
}
+ private static float XInputApplyDeadzone(float rawAxisValue, XboxAxis axis, XboxController controller)
+ {
+ float finalValue = rawAxisValue;
+ float deadzone = 0.0f;
+
+ // Find the deadzone
+ switch(axis)
+ {
+ case XboxAxis.LeftStickX:
+ deadzone = XciHandler.Instance.Deadzones.LeftStickX[(int) controller];
+ break;
+ case XboxAxis.LeftStickY:
+ deadzone = XciHandler.Instance.Deadzones.LeftStickY[(int) controller];
+ break;
+ case XboxAxis.RightStickX:
+ deadzone = XciHandler.Instance.Deadzones.RightStickX[(int) controller];
+ break;
+ case XboxAxis.RightStickY:
+ deadzone = XciHandler.Instance.Deadzones.RightStickY[(int) controller];
+ break;
+ case XboxAxis.LeftTrigger:
+ deadzone = XciHandler.Instance.Deadzones.LeftTrigger[(int) controller];
+ break;
+ case XboxAxis.RightTrigger:
+ deadzone = XciHandler.Instance.Deadzones.RightTrigger[(int) controller];
+ break;
+ }
+
+
+ // Clear axis value if less than the deadzone
+ if(Mathf.Abs(rawAxisValue) < deadzone)
+ {
+ finalValue = 0.0f;
+ }
+ // Remap the axis value from interval [0,1] to [deadzone,1]
+ else
+ {
+ finalValue = (Mathf.Abs(rawAxisValue) * (1 - deadzone)) + deadzone;
+ finalValue = finalValue * Mathf.Sign(rawAxisValue);
+ }
+
+
+ return finalValue;
+ }
+
// -------------------------- Handler Script -------------------
@@ -1690,6 +1737,7 @@ private class XciHandler : MonoBehaviour
public bool u3dTrigger3RightIsTouched = false;
public bool u3dTrigger4LeftIsTouched = false;
public bool u3dTrigger4RightIsTouched = false;
+ private XciAxisDeadzoneData deadZones = null;
void Awake()
{
@@ -1700,6 +1748,9 @@ void Awake()
XciHandler.instance = this;
+ this.deadZones = new XciAxisDeadzoneData();
+ this.deadZones.Init(XciInputManagerReader.Instance.InputManager);
+
// Lives for the life of the game
DontDestroyOnLoad(this.gameObject);
}
@@ -1717,6 +1768,14 @@ void OnApplicationFocus(bool isWindowInFocusNow)
}
}
+ public XciAxisDeadzoneData Deadzones
+ {
+ get
+ {
+ return this.deadZones;
+ }
+ }
+
private void ResetTriggerTouches()
{
this.u3dTrigger0LeftIsTouched = false;
diff --git a/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput_Helpers/XciAxisDeadzoneData.cs b/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput_Helpers/XciAxisDeadzoneData.cs
new file mode 100644
index 0000000..5d195ed
--- /dev/null
+++ b/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput_Helpers/XciAxisDeadzoneData.cs
@@ -0,0 +1,107 @@
+using UnityEngine;
+
+namespace XboxCtrlrInput
+{
+ ///
+ /// Contains deadzone data of every axis for every joystick number (see XboxController enum).
+ /// Mostly for use with XInput (Windows API)
+ ///
+ public class XciAxisDeadzoneData
+ {
+ private float[] leftStickX = new float[5];
+ private float[] leftStickY = new float[5];
+ private float[] rightStickX = new float[5];
+ private float[] rightStickY = new float[5];
+ private float[] leftTrigger = new float[5];
+ private float[] rightTrigger = new float[5];
+
+
+ public void Init(XciInputManagerClone inputManager)
+ {
+ this.leftStickX[0] = inputManager.SearchInputByName("XboxAxisXJoy0").dead;
+ this.leftStickX[1] = inputManager.SearchInputByName("XboxAxisXJoy1").dead;
+ this.leftStickX[2] = inputManager.SearchInputByName("XboxAxisXJoy2").dead;
+ this.leftStickX[3] = inputManager.SearchInputByName("XboxAxisXJoy3").dead;
+ this.leftStickX[4] = inputManager.SearchInputByName("XboxAxisXJoy4").dead;
+
+ this.leftStickY[0] = inputManager.SearchInputByName("XboxAxisYJoy0").dead;
+ this.leftStickY[1] = inputManager.SearchInputByName("XboxAxisYJoy1").dead;
+ this.leftStickY[2] = inputManager.SearchInputByName("XboxAxisYJoy2").dead;
+ this.leftStickY[3] = inputManager.SearchInputByName("XboxAxisYJoy3").dead;
+ this.leftStickY[4] = inputManager.SearchInputByName("XboxAxisYJoy4").dead;
+
+ this.rightStickX[0] = inputManager.SearchInputByName("XboxAxis4Joy0").dead;
+ this.rightStickX[1] = inputManager.SearchInputByName("XboxAxis4Joy1").dead;
+ this.rightStickX[2] = inputManager.SearchInputByName("XboxAxis4Joy2").dead;
+ this.rightStickX[3] = inputManager.SearchInputByName("XboxAxis4Joy3").dead;
+ this.rightStickX[4] = inputManager.SearchInputByName("XboxAxis4Joy4").dead;
+
+ this.rightStickY[0] = inputManager.SearchInputByName("XboxAxis5Joy0").dead;
+ this.rightStickY[1] = inputManager.SearchInputByName("XboxAxis5Joy1").dead;
+ this.rightStickY[2] = inputManager.SearchInputByName("XboxAxis5Joy2").dead;
+ this.rightStickY[3] = inputManager.SearchInputByName("XboxAxis5Joy3").dead;
+ this.rightStickY[4] = inputManager.SearchInputByName("XboxAxis5Joy4").dead;
+
+ this.leftTrigger[0] = inputManager.SearchInputByName("XboxAxis3Joy0").dead;
+ this.leftTrigger[1] = inputManager.SearchInputByName("XboxAxis3Joy1").dead;
+ this.leftTrigger[2] = inputManager.SearchInputByName("XboxAxis3Joy2").dead;
+ this.leftTrigger[3] = inputManager.SearchInputByName("XboxAxis3Joy3").dead;
+ this.leftTrigger[4] = inputManager.SearchInputByName("XboxAxis3Joy4").dead;
+
+ this.rightTrigger[0] = inputManager.SearchInputByName("XboxAxis3Joy0").dead;
+ this.rightTrigger[1] = inputManager.SearchInputByName("XboxAxis3Joy1").dead;
+ this.rightTrigger[2] = inputManager.SearchInputByName("XboxAxis3Joy2").dead;
+ this.rightTrigger[3] = inputManager.SearchInputByName("XboxAxis3Joy3").dead;
+ this.rightTrigger[4] = inputManager.SearchInputByName("XboxAxis3Joy4").dead;
+ }
+
+
+ public float[] LeftStickX
+ {
+ get
+ {
+ return this.leftStickX;
+ }
+ }
+
+ public float[] LeftStickY
+ {
+ get
+ {
+ return this.leftStickY;
+ }
+ }
+
+ public float[] RightStickX
+ {
+ get
+ {
+ return this.rightStickX;
+ }
+ }
+
+ public float[] RightStickY
+ {
+ get
+ {
+ return this.rightStickY;
+ }
+ }
+
+ public float[] LeftTrigger
+ {
+ get
+ {
+ return this.leftTrigger;
+ }
+ }
+
+ public float[] RightTrigger
+ {
+ get
+ {
+ return this.rightTrigger;
+ }
+ }
+ }
+}
diff --git a/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput_Helpers/XciAxisDeadzoneData.cs.meta b/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput_Helpers/XciAxisDeadzoneData.cs.meta
new file mode 100644
index 0000000..1844f24
--- /dev/null
+++ b/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput_Helpers/XciAxisDeadzoneData.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 92bc4e0ff46bb40639bb7ce55fabbaad
+timeCreated: 1482271074
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput_Helpers/XciInputManagerClone.cs b/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput_Helpers/XciInputManagerClone.cs
index 94a1ed0..c1c03b5 100644
--- a/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput_Helpers/XciInputManagerClone.cs
+++ b/XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput_Helpers/XciInputManagerClone.cs
@@ -69,6 +69,29 @@ public InputManagerEntry this[int index]
}
}
+ ///
+ /// Searchs by the name of the input.
+ ///
+ public InputManagerEntry SearchInputByName(string entryName)
+ {
+ InputManagerEntry foundEntry = null;
+
+ InputManagerEntry currentEntry = null;
+ int numEntries = this.NumberOfEntries;
+ for(int i = 0; i < numEntries; i++)
+ {
+ currentEntry = this.inputManagerEntries[i];
+
+ if(currentEntry.name.Equals(entryName))
+ {
+ foundEntry = currentEntry;
+ break;
+ }
+ }
+
+ return foundEntry;
+ }
+
///
/// WARNING: Clears entire Input Manager Clone
///