public DirectInputGamePad(DirectInput directInput, GamePadKey key) : base(key) { this.key = key; this.directInput = directInput; this.instance = new Joystick(directInput, key.Guid); joystickState = new JoystickState(); }
// REF : http://wiki.unity3d.com/index.php/Xbox360Controller public static KeyCode GetXboxKeyCode(int gamePadNum, GamePadKey key) { KeyCode keyCode = KeyCode.None; switch (key) { case GamePadKey.BACK: keyCode = KeyCode.Joystick1Button6; break; case GamePadKey.START: keyCode = KeyCode.Joystick1Button7; break; case GamePadKey.A: case GamePadKey.FUNC_DOWN: keyCode = KeyCode.Joystick1Button0; break; case GamePadKey.B: case GamePadKey.FUNC_RIGHT: keyCode = KeyCode.Joystick1Button1; break; case GamePadKey.Y: case GamePadKey.FUNC_UP: keyCode = KeyCode.Joystick1Button3; break; case GamePadKey.X: case GamePadKey.FUNC_LEFT: keyCode = KeyCode.Joystick1Button2; break; case GamePadKey.LB: keyCode = KeyCode.Joystick1Button4; break; case GamePadKey.RB: keyCode = KeyCode.Joystick1Button5; break; case GamePadKey.L_STICK: keyCode = KeyCode.Joystick1Button8; break; case GamePadKey.R_STICK: keyCode = KeyCode.Joystick1Button9; break; } if (gamePadNum > 1) { keyCode += 20; } return(keyCode); }
public virtual bool GetKeyDown(GamePadKey key) { if (TryProcessAxisValue(key, KeyPhase.PRESS)) { return(true); } var keyCode = GetKeyCode(key); return(Input.GetKeyDown(keyCode)); }
public virtual bool GetKeyUp(GamePadKey key) { if (TryProcessAxisValue(key, KeyPhase.RELEASE)) { return(true); } var keyCode = GetKeyCode(key); return(Input.GetKeyUp(keyCode)); }
protected override KeyCode GetKeyCode(GamePadKey key) { if (gamePadType == GamePadType.XBOX) { return(KeyConverter.GetXboxKeyCode(gamePadIndex, key)); } else if (gamePadType == GamePadType.DUALSHOCK) { return(KeyConverter.GetDS4KeyCode(gamePadIndex, key)); } return(KeyCode.None); }
public static bool GetButtonUp(GamePadKey key, GamePad.Index controller) { // Button if ((int)key <= 10 && (int)key >= 1) { return GamePad.GetButtonUp(TranslateButton(key), controller); } // Anything else is not a button and should not be passed as an argument to this method else { return false; } }
public static Vector2 GetAxis(GamePadKey key, GamePad.Index controller) { // Button if ((int)key >= 13 && (int)key <= 15) { return GamePad.GetAxis(TranslateAxis(key), controller); } // Anything else is not an axis and should not be passed as an argument to this method else { return Vector2.zero; } }
protected override KeyCode GetKeyCode(GamePadKey key) { switch (key) { case GamePadKey.BACK: return(KeyCode.Joystick1Button8); case GamePadKey.START: return(KeyCode.Joystick1Button9); case GamePadKey.A: case GamePadKey.FUNC_DOWN: return(KeyCode.Joystick1Button1); case GamePadKey.B: case GamePadKey.FUNC_RIGHT: return(KeyCode.Joystick1Button2); case GamePadKey.Y: case GamePadKey.FUNC_UP: return(KeyCode.Joystick1Button3); case GamePadKey.X: case GamePadKey.FUNC_LEFT: return(KeyCode.Joystick1Button0); case GamePadKey.LB: return(KeyCode.Joystick1Button4); case GamePadKey.RB: return(KeyCode.Joystick1Button5); case GamePadKey.L_STICK: return(KeyCode.Joystick1Button10); case GamePadKey.R_STICK: return(KeyCode.Joystick1Button11); } // PS Button : Joystick Button12 // Touchpad Click : Joystick Button13 return(KeyCode.None); }
public KeyPhase GetButtonPhase(GamePadKey key) { if (GetKeyDown(key)) { return(KeyPhase.PRESS); } if (GetKeyUp(key)) { return(KeyPhase.RELEASE); } if (GetKey(key)) { return(KeyPhase.PRESSED); } return(KeyPhase.NONE); }
public SdlInputGamePad(IntPtr instance, GamePadKey key) : base(key) { this.instance = instance; }
public static GamePad.Button TranslateButton(GamePadKey key) { switch(key) { case GamePadKey.A: return GamePad.Button.A; case GamePadKey.B: return GamePad.Button.B; case GamePadKey.X: return GamePad.Button.X; case GamePadKey.Y: return GamePad.Button.Y; case GamePadKey.LeftShoulder: return GamePad.Button.LeftShoulder; case GamePadKey.RightShoulder: return GamePad.Button.RightShoulder; case GamePadKey.LeftStickButton: return GamePad.Button.LeftStick; case GamePadKey.RightStickButton: return GamePad.Button.RightStick; case GamePadKey.Back: return GamePad.Button.Back; case GamePadKey.Start: return GamePad.Button.Start; default: throw new System.Exception("Invalid GamePadKey code."); } }
public static float GetTrigger(GamePadKey key, GamePad.Index controller) { // Button if ((int)key >= 11 && (int)key < 13) { return GamePad.GetTrigger(TranslateTrigger(key), controller); } // Anything else is not a trigger and should not be passed as an argument to this method else { return 0.0f; } }
public static GamePad.Trigger TranslateTrigger(GamePadKey key) { switch (key) { case GamePadKey.LeftTrigger: return GamePad.Trigger.LeftTrigger; case GamePadKey.RightTrigger: return GamePad.Trigger.RightTrigger; default: throw new System.Exception("Invalid GamePadKey code."); } }
public XInputGamePad(Controller instance, GamePadKey key) : base(key) { this.instance = instance; }
protected bool TryProcessAxisValue(GamePadKey key, KeyPhase phase) { string axisName = string.Empty; bool isPositiveValue = true; switch (key) { case GamePadKey.D_UP: axisName = axisNames.DPadY; isPositiveValue = true; break; case GamePadKey.D_DOWN: axisName = axisNames.DPadY; isPositiveValue = false; break; case GamePadKey.D_LEFT: axisName = axisNames.DPadX; isPositiveValue = false; break; case GamePadKey.D_RIGHT: axisName = axisNames.DPadX; isPositiveValue = true; break; case GamePadKey.LT: axisName = axisNames.LTrigger; isPositiveValue = true; break; case GamePadKey.RT: axisName = axisNames.RTrigger; isPositiveValue = true; break; case GamePadKey.ANALOG_L_UP: axisName = axisNames.LeftAnalogStickY; isPositiveValue = true; break; case GamePadKey.ANALOG_L_DOWN: axisName = axisNames.LeftAnalogStickY; isPositiveValue = false; break; case GamePadKey.ANALOG_L_LEFT: axisName = axisNames.LeftAnalogStickX; isPositiveValue = false; break; case GamePadKey.ANALOG_L_RIGHT: axisName = axisNames.LeftAnalogStickX; isPositiveValue = true; break; case GamePadKey.ANALOG_R_UP: axisName = axisNames.RightAnalogStickY; isPositiveValue = true; break; case GamePadKey.ANALOG_R_DOWN: axisName = axisNames.RightAnalogStickY; isPositiveValue = false; break; case GamePadKey.ANALOG_R_LEFT: axisName = axisNames.RightAnalogStickX; isPositiveValue = false; break; case GamePadKey.ANALOG_R_RIGHT: axisName = axisNames.RightAnalogStickX; isPositiveValue = true; break; } if (string.IsNullOrEmpty(axisName)) { return(false); } else if (!axisValueDict.ContainsKey(axisName)) { return(false); } if (phase == KeyPhase.RELEASE) { return(axisValueDict[axisName].Released(isPositiveValue)); } else if (phase == KeyPhase.PRESS) { return(axisValueDict[axisName].Press(isPositiveValue)); } else if (phase == KeyPhase.PRESSED) { return(axisValueDict[axisName].IsPressing(isPositiveValue)); } return(false); }
protected GamePad(GamePadKey key) { Key = key; }
protected abstract KeyCode GetKeyCode(GamePadKey key);
public static GamePad.Axis TranslateAxis(GamePadKey key) { switch (key) { case GamePadKey.DPad: return GamePad.Axis.Dpad; case GamePadKey.LeftStick: return GamePad.Axis.LeftStick; case GamePadKey.RightStick: return GamePad.Axis.RightStick; default: throw new System.Exception("Invalid GamePadKey code."); } }