// ------------ Public Methods --------------- // // >>> For Buttons <<< // /// <summary> /// Returns <c>true</c> if the specified button is held down by any controller. /// </summary> /// <param name='button'> /// Identifier for the Xbox button to be tested. /// </param> public static bool GetButton(XboxButton button) { if (button.IsDPad()) return GetDPad(button.ToDPad()); if(OnWindowsNative()) { if(!XInputStillInCurrFrame()) { XInputUpdateAllStates(); } GamePadState ctrlrState = XInputGetSingleState(); if( XInputGetButtonState(ctrlrState.Buttons, button) == ButtonState.Pressed ) { return true; } } else { string btnCode = DetermineButtonCode(button, 0); if(Input.GetKey(btnCode)) { return true; } } return false; }
/// <summary> /// Returns <c>true</c> at the frame the specified button is released by a specified controller. /// </summary> /// <param name='button'> /// Identifier for the Xbox button to be tested. /// </param> /// <param name='controller'> /// An identifier for the specific controller on which to test the button. /// </param> public static bool GetButtonUp(XboxButton button, XboxController controller) { if (button.IsDPad()) return GetDPadUp(button.ToDPad(), controller); if (controller == XboxController.All) return GetButtonUp(button); int controllerNumber = (int)controller; if(OnWindowsNative()) { if(Time.frameCount < 2) { return false; } if(!XInputStillInCurrFrame()) { XInputUpdateAllStates(); } GamePadState ctrlrState = XInputGetPaticularState(controllerNumber); GamePadState ctrlrStatePrev = XInputGetPaticularStatePrev(controllerNumber); if( ( XInputGetButtonState(ctrlrState.Buttons, button) == ButtonState.Released ) && ( XInputGetButtonState(ctrlrStatePrev.Buttons, button) == ButtonState.Pressed ) ) { return true; } } else { string btnCode = DetermineButtonCode(button, controllerNumber); if(Input.GetKeyUp(btnCode)) { return true; } } return false; }