diff --git a/XboxCtrlrInput/Assets/XboxCtrlrInputPackage/XboxCtrlrInput.cs b/XboxCtrlrInput/Assets/XboxCtrlrInputPackage/XboxCtrlrInput.cs index 8c6a06c..6078c0a 100644 --- a/XboxCtrlrInput/Assets/XboxCtrlrInputPackage/XboxCtrlrInput.cs +++ b/XboxCtrlrInput/Assets/XboxCtrlrInputPackage/XboxCtrlrInput.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using XInputDotNetPure; namespace XboxCtrlrInput @@ -352,7 +352,7 @@ public static bool GetDPad(XboxDPad padDirection, int controllerNumber) } GamePadState ctrlrState = XInputGetPaticularState(controllerNumber); - + if( XInputGetDPadState(ctrlrState.DPad, padDirection) == ButtonState.Pressed ) { return true; @@ -392,6 +392,222 @@ public static bool GetDPad(XboxDPad padDirection, int controllerNumber) return r; } + /// Returns true at the frame the specified button is released. + /// Identifier for the Xbox button to be tested. + /// An identifier for the specific controller on which to test the button. An int between 1 and 4. + public static bool GetDPadUp(XboxDPad padDirection) + { + + bool r = false; + + if(OnWindowsNative()) + { + if(Time.frameCount < 2) + { + return false; + } + + if(!XInputStillInCurrFrame()) + { + XInputUpdateAllStates(); //XInputUpdatePaticularState(controllerNumber); + } + + GamePadState ctrlrState = XInputGetSingleState(); + GamePadState ctrlrStatePrev = XInputGetSingleStatePrev(); + + if( ( XInputGetDPadState(ctrlrState.DPad, padDirection) == ButtonState.Released ) && + ( XInputGetDPadState(ctrlrStatePrev.DPad, padDirection) == ButtonState.Pressed ) ) + { + return true; + } + } + + else + { + string inputCode = ""; + + if(OnMac()) + { + inputCode = DetermineDPadMac(padDirection, 0); + r = Input.GetKeyUp(inputCode); + } + else if(OnLinux() && IsControllerWireless()) + { + inputCode = DetermineDPadWirelessLinux(padDirection, 0); + r = Input.GetKeyUp(inputCode); + } + else + { + //Place Holder for Wired Linux + r = false; + } + } + + return r; + } + + /// Returns true at the frame the specified button is released by a specified controller. + /// Identifier for the Xbox button to be tested. + /// An identifier for the specific controller on which to test the button. An int between 1 and 4. + public static bool GetDPadUp(XboxDPad padDirection, int controllerNumber) + { + + bool r = false; + + if(OnWindowsNative()) + { + if(Time.frameCount < 2) + { + return false; + } + + if(!XInputStillInCurrFrame()) + { + XInputUpdateAllStates(); //XInputUpdatePaticularState(controllerNumber); + } + + GamePadState ctrlrState = XInputGetPaticularState(controllerNumber); + GamePadState ctrlrStatePrev = XInputGetPaticularStatePrev(controllerNumber); + + if( ( XInputGetDPadState(ctrlrState.DPad, padDirection) == ButtonState.Released ) && + ( XInputGetDPadState(ctrlrStatePrev.DPad, padDirection) == ButtonState.Pressed ) ) + { + return true; + } + } + + else + { + string inputCode = ""; + + if(OnMac()) + { + inputCode = DetermineDPadMac(padDirection, controllerNumber); + r = Input.GetKeyUp(inputCode); + } + else if(OnLinux() && IsControllerWireless(controllerNumber)) + { + inputCode = DetermineDPadWirelessLinux(padDirection, controllerNumber); + r = Input.GetKeyUp(inputCode); + } + else + { + //Place Holder for Wired Linux + r = false; + } + } + + return r; + } + + /// Returns true at the frame the specified button is Pressed. + /// Identifier for the Xbox button to be tested. + /// An identifier for the specific controller on which to test the button. An int between 1 and 4. + public static bool GetDPadDown(XboxDPad padDirection) + { + + bool r = false; + + if(OnWindowsNative()) + { + if(Time.frameCount < 2) + { + return false; + } + + if(!XInputStillInCurrFrame()) + { + XInputUpdateAllStates(); //XInputUpdatePaticularState(controllerNumber); + } + + GamePadState ctrlrState = XInputGetSingleState(); + GamePadState ctrlrStatePrev = XInputGetSingleStatePrev(); + + if( ( XInputGetDPadState(ctrlrState.DPad, padDirection) == ButtonState.Pressed ) && + ( XInputGetDPadState(ctrlrStatePrev.DPad, padDirection) == ButtonState.Released ) ) + { + return true; + } + } + + else + { + string inputCode = ""; + + if(OnMac()) + { + inputCode = DetermineDPadMac(padDirection, 0); + r = Input.GetKeyDown(inputCode); + } + else if(OnLinux() && IsControllerWireless()) + { + inputCode = DetermineDPadWirelessLinux(padDirection, 0); + r = Input.GetKeyDown(inputCode); + } + else + { + //Place Holder for Wired Linux + r = false; + } + } + + return r; + } + + /// Returns true at the frame the specified button is Pressed by a specified controller. + /// Identifier for the Xbox button to be tested. + /// An identifier for the specific controller on which to test the button. An int between 1 and 4. + public static bool GetDPadDown(XboxDPad padDirection, int controllerNumber) + { + + bool r = false; + + if(OnWindowsNative()) + { + if(Time.frameCount < 2) + { + return false; + } + + if(!XInputStillInCurrFrame()) + { + XInputUpdateAllStates(); //XInputUpdatePaticularState(controllerNumber); + } + + GamePadState ctrlrState = XInputGetPaticularState(controllerNumber); + GamePadState ctrlrStatePrev = XInputGetPaticularStatePrev(controllerNumber); + + if( ( XInputGetDPadState(ctrlrState.DPad, padDirection) == ButtonState.Pressed ) && + ( XInputGetDPadState(ctrlrStatePrev.DPad, padDirection) == ButtonState.Released ) ) + { + return true; + } + } + + else + { + string inputCode = ""; + + if(OnMac()) + { + inputCode = DetermineDPadMac(padDirection, controllerNumber); + r = Input.GetKeyDown(inputCode); + } + else if(OnLinux() && IsControllerWireless(controllerNumber)) + { + inputCode = DetermineDPadWirelessLinux(padDirection, controllerNumber); + r = Input.GetKeyDown(inputCode); + } + else + { + //Place Holder for Wired Linux + r = false; + } + } + + return r; + } + // >>> For Axis <<< // /// Returns the analog number of the specified axis from any controller.