private void CaptureInput() { CloseMenuPressed = _gamePadState.Pressed(CButton.B); bool pressedDown = _gamePadState.GetAxis(CAxis.DY) == -1f || _gamePadState.GetAxis(CAxis.LY) == 1f; DownButtonPressed = ((pressedDown && !_downPressedLastFrame) || Input.GetKeyDown(KeyCode.DownArrow)); _downPressedLastFrame = pressedDown; bool pressedUp = _gamePadState.GetAxis(CAxis.DY) == 1f || _gamePadState.GetAxis(CAxis.LY) == -1f; UpButtonPressed = ((pressedUp && !_upPressedLastFrame) || Input.GetKeyDown(KeyCode.UpArrow)); _upPressedLastFrame = pressedUp; ExecuteButtonPressed = _gamePadState.Pressed(CButton.A) || Input.GetKeyDown(KeyCode.RightShift); }
void Update() { GamePadState state = GamePad.GetState(); bool input = false; const float deadZone = 0.25f; //any input input |= state.Pressed(CButton.A) || state.Pressed(CButton.B) || state.Pressed(CButton.X) || state.Pressed(CButton.Y); input |= state.Pressed(CButton.Back) || state.Pressed(CButton.Start); input |= Mathf.Abs(state.GetAxis(CAxis.LX)) > deadZone || Mathf.Abs(state.GetAxis(CAxis.LY)) > deadZone || Mathf.Abs(state.GetAxis(CAxis.RX)) > deadZone || Mathf.Abs(state.GetAxis(CAxis.RY)) > deadZone; if (input) { SceneManager.LoadScene("GamePlay"); } }
private void Update() { if (_movementLocked) { if (!_grounded.IsGrounded) { return; } else { _movementLocked = false; } } GamePadState state = GamePad.GetState(Index); if (Index == PlayerIndex.One) { if (Input.GetKey(KeyCode.D)) { HorizontalMovement = 1f; } else if (Input.GetKey(KeyCode.A)) { HorizontalMovement = -1f; } else { HorizontalMovement = 0f; } } else if (Index == PlayerIndex.Two) { if (Input.GetKey(KeyCode.RightArrow)) { HorizontalMovement = 1f; } else if (Input.GetKey(KeyCode.LeftArrow)) { HorizontalMovement = -1f; } else { HorizontalMovement = 0f; } } if (Index == PlayerIndex.Three || Index == PlayerIndex.Four || HorizontalMovement != 1 && HorizontalMovement != -1) { HorizontalMovement = state.GetAxis(CAxis.LX); } Jump = state.Pressed(CButton.A) || (Index == PlayerIndex.One && Input.GetKeyDown(KeyCode.Space) || (Index == PlayerIndex.Two && Input.GetKeyDown(KeyCode.UpArrow))); Dash = state.Pressed(CButton.X) || (Index == PlayerIndex.One && Input.GetKeyDown(KeyCode.LeftShift) || (Index == PlayerIndex.Two && Input.GetKeyDown(KeyCode.RightShift))); }
private void SendActions(JoystickState state) { int actionCode = -1; GamePadState betterState = new GamePadState(_diListener.Converter, ref state); // buttons if (actionCode == -1) { int button = -1; for (int i = 0; i < betterState.ButtonCount; i++) { if (betterState.IsButtonDown(i)) { button = i; break; } } if (button != -1) { if ((button >= 0) && (button <= 19)) { // don't need no stinkin' enum-constants here.... actionCode = 3030 + button; } } } // pov if (actionCode == -1) { for (int i = 0; i < betterState.PovCount; i++) { switch (betterState.GetPov(i)) { case 0: actionCode = (int)joyButton.povN; break; case 4500: actionCode = (int)joyButton.povNE; break; case 9000: actionCode = (int)joyButton.povE; break; case 13500: actionCode = (int)joyButton.povSE; break; case 18000: actionCode = (int)joyButton.povS; break; case 22500: actionCode = (int)joyButton.povSW; break; case 27000: actionCode = (int)joyButton.povW; break; case 31500: actionCode = (int)joyButton.povNW; break; } if (actionCode != -1) { break; } } } // axes if (actionCode == -1) { if (betterState.AvailableAxes.HasFlag(Axes.X) && Math.Abs(betterState.GetAxis(Axes.X)) > _config.AxisLimit) { if (betterState.GetAxis(Axes.X) > 0) { actionCode = (int)joyButton.axisXUp; // right } else { actionCode = (int)joyButton.axisXDown; // left } } else if (betterState.AvailableAxes.HasFlag(Axes.Y) && Math.Abs(betterState.GetAxis(Axes.Y)) > _config.AxisLimit) { if (betterState.GetAxis(Axes.Y) > 0) { actionCode = (int)joyButton.axisYUp; // down } else { actionCode = (int)joyButton.axisYDown; // up } } else if (betterState.AvailableAxes.HasFlag(Axes.Z) && Math.Abs(betterState.GetAxis(Axes.Z)) > _config.AxisLimit) { if (betterState.GetAxis(Axes.Z) > 0) { actionCode = (int)joyButton.axisZUp; } else { actionCode = (int)joyButton.axisZDown; } } else if (betterState.AvailableAxes.HasFlag(Axes.RotationX) && Math.Abs(betterState.GetAxis(Axes.RotationX)) > _config.AxisLimit) { if (betterState.GetAxis(Axes.RotationX) > 0) { actionCode = (int)joyButton.rotationXUp; } else { actionCode = (int)joyButton.rotationXDown; } } else if (betterState.AvailableAxes.HasFlag(Axes.RotationY) && Math.Abs(betterState.GetAxis(Axes.RotationY)) > _config.AxisLimit) { if (betterState.GetAxis(Axes.RotationY) > 0) { actionCode = (int)joyButton.rotationYUp; } else { actionCode = (int)joyButton.rotationYDown; } } else if (betterState.AvailableAxes.HasFlag(Axes.RotationZ) && Math.Abs(betterState.GetAxis(Axes.RotationZ)) > _config.AxisLimit) { if (betterState.GetAxis(Axes.RotationZ) > 0) { actionCode = (int)joyButton.rotationZUp; } else { actionCode = (int)joyButton.rotationZDown; } } } if (actionCode != -1 && RemoteCallback != null) { string keyCode = TranslateActionCode(actionCode); IrssLog.Debug("DirectInput action mapped actionCode={0} to keyCode={1}", actionCode, keyCode); RemoteCallback(Name, keyCode); } }