/// <summary> /// Creates a bind that expects key, mouse and controller input. /// </summary> public Binding(KeyCode key, MouseButton mouseButton, ControllerButton controllerButton) : this(BindInputListener.ALL) { Key = key; MouseButton = mouseButton; ControllerButton = controllerButton; }
private bool SelectItem(MenuGroup group, ControllerButton controllerButton) { if (group.Active) group.SelectItem(controllerButton); else if(group.Values.Any(x => x != null && x.Child != null)) { } return false; }
public void SelectNewButton(ControllerButton button) { if (button != null) { // Clear the button. ClearButtons(); // Select the new button. m_SelectedButton = button; m_SelectedButton.ButtonOver(); } }
public static String GetButtonName( GameVersion version, ControllerButton button ) { switch ( version ) { case GameVersion.X360: switch ( button ) { case ControllerButton.Start: return "Start"; case ControllerButton.Select: return "Back"; case ControllerButton.RightButton: return "B"; case ControllerButton.LowerButton: return "A"; case ControllerButton.LeftButton: return "X"; case ControllerButton.UpperButton: return "Y"; case ControllerButton.L1: return "LB"; case ControllerButton.L2: return "LT"; case ControllerButton.L3: return "Push LS"; case ControllerButton.R1: return "RB"; case ControllerButton.R2: return "RT"; case ControllerButton.R3: return "Push RS"; case ControllerButton.LeftStick: return "Left Stick"; case ControllerButton.RightStick: return "Right Stick"; case ControllerButton.DPad: return "D-Pad"; case ControllerButton.System: return "Guide"; } break; case GameVersion.PS3: switch ( button ) { case ControllerButton.Start: return "Start"; case ControllerButton.Select: return "Select"; case ControllerButton.RightButton: return "Circle"; case ControllerButton.LowerButton: return "Cross"; case ControllerButton.LeftButton: return "Square"; case ControllerButton.UpperButton: return "Triangle"; case ControllerButton.L1: return "L1"; case ControllerButton.L2: return "L2"; case ControllerButton.L3: return "L3"; case ControllerButton.R1: return "R1"; case ControllerButton.R2: return "R2"; case ControllerButton.R3: return "R3"; case ControllerButton.LeftStick: return "Left Stick"; case ControllerButton.RightStick: return "Right Stick"; case ControllerButton.DPad: return "D-Pad"; case ControllerButton.System: return "PS"; } break; } return "None"; }
public bool IsPressed(ControllerButton button) { switch (button) { case ControllerButton.LeftTrigger: return state.LeftTrigger > Gamepad.TriggerThreshold; case ControllerButton.RightTrigger: return state.RightTrigger > Gamepad.TriggerThreshold; case ControllerButton.LeftThumbX: case ControllerButton.LeftThumbY: case ControllerButton.RightThumbX: case ControllerButton.RightThumbY: throw new ArgumentException("The thumbsticks are invalid arguments for this function."); default: return state.Buttons.HasFlag((GamepadButtonFlags)button); } }
public float GetAnalogState(ControllerButton button) { switch (button) { case ControllerButton.LeftTrigger: return state.LeftTrigger / 255f; case ControllerButton.RightTrigger: return state.RightTrigger / 255f; case ControllerButton.LeftThumbX: return CalculateNormalizedMagnitude(state.LeftThumbX, Gamepad.LeftThumbDeadZone); case ControllerButton.LeftThumbY: return CalculateNormalizedMagnitude(state.LeftThumbY, Gamepad.LeftThumbDeadZone); case ControllerButton.RightThumbX: return CalculateNormalizedMagnitude(state.RightThumbX, Gamepad.RightThumbDeadZone); case ControllerButton.RightThumbY: return CalculateNormalizedMagnitude(state.RightThumbY, Gamepad.RightThumbDeadZone); default: throw new ArgumentException("Only the thumbsticks and triggers are valid arguments for this function."); } }
public virtual bool GetPressUp(ControllerButton button) { return(false); }
public virtual void RemoveListener(ControllerButton button, RoleValueEventListener listener, ButtonEventType type = ButtonEventType.Click) { }
public virtual float LastPressDownTime(ControllerButton button) { return(0f); }
public override bool GetPressUp(ControllerButton button) { return(IsValidButton(button) && EnumUtils.GetFlag(prevButtonPressed, (int)button) && !EnumUtils.GetFlag(currButtonPressed, (int)button)); }
public override int ClickCount(ControllerButton button) { return(IsValidButton(button) ? clickCount[(int)button] : 0); }
private Buttons GetXboxButton(ControllerButton Button) { switch (Button) { case ControllerButton.A: return Buttons.A; case ControllerButton.B: return Buttons.B; case ControllerButton.X: return Buttons.X; case ControllerButton.Y: return Buttons.Y; case ControllerButton.Start: return Buttons.Start; case ControllerButton.Select: return Buttons.Back; case ControllerButton.Up: return Buttons.DPadUp; case ControllerButton.Down: return Buttons.DPadDown; case ControllerButton.Left: return Buttons.DPadLeft; case ControllerButton.Right: return Buttons.DPadRight; case ControllerButton.LB: return Buttons.LeftShoulder; case ControllerButton.RB: return Buttons.RightShoulder; case ControllerButton.LS: return Buttons.LeftStick; case ControllerButton.RS: return Buttons.RightStick; default: throw new Exception("The button does not exist on the XBOX controller."); } }
// return true if frame skipped public override bool Update() { if (!ChangeProp.Set(ref updatedFrameCount, Time.frameCount)) { return(true); } var deviceIndex = m_map.GetMappedDeviceByRoleValue(m_roleValue); // treat this frame as updated if both prevDeviceIndex and currentDeviceIndex are invalid if (!VRModule.IsValidDeviceIndex(prevDeviceIndex) && !VRModule.IsValidDeviceIndex(deviceIndex)) { return(false); } // get device state var currState = VRModule.GetCurrentDeviceState(deviceIndex); // copy to previous states and reset current state prevDeviceIndex = deviceIndex; prevButtonPressed = currButtonPressed; currButtonPressed = 0; currentInput2DType = currState.input2DType; for (int i = CONTROLLER_AXIS_COUNT - 1; i >= 0; --i) { prevAxisValue[i] = currAxisValue[i]; currAxisValue[i] = 0f; } // update button states EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.System, currState.GetButtonPress(VRModuleRawButton.System)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.Menu, currState.GetButtonPress(VRModuleRawButton.ApplicationMenu)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.MenuTouch, currState.GetButtonTouch(VRModuleRawButton.ApplicationMenu)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.Trigger, currState.GetButtonPress(VRModuleRawButton.Trigger)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.TriggerTouch, currState.GetButtonTouch(VRModuleRawButton.Trigger)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.Pad, currState.GetButtonPress(VRModuleRawButton.Touchpad)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.PadTouch, currState.GetButtonTouch(VRModuleRawButton.Touchpad)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.Grip, currState.GetButtonPress(VRModuleRawButton.Grip)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.GripTouch, currState.GetButtonTouch(VRModuleRawButton.Grip)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.CapSenseGrip, currState.GetButtonPress(VRModuleRawButton.CapSenseGrip)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.CapSenseGripTouch, currState.GetButtonTouch(VRModuleRawButton.CapSenseGrip)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.ProximitySensor, currState.GetButtonPress(VRModuleRawButton.ProximitySensor)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.AKey, currState.GetButtonPress(VRModuleRawButton.A)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.AKeyTouch, currState.GetButtonTouch(VRModuleRawButton.A)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.Axis3, currState.GetButtonPress(VRModuleRawButton.Axis3)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.Axis3Touch, currState.GetButtonTouch(VRModuleRawButton.Axis3)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.Axis4, currState.GetButtonPress(VRModuleRawButton.Axis4)); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.Axis4Touch, currState.GetButtonTouch(VRModuleRawButton.Axis4)); // update axis values currAxisValue[(int)ControllerAxis.PadX] = currState.GetAxisValue(VRModuleRawAxis.TouchpadX); currAxisValue[(int)ControllerAxis.PadY] = currState.GetAxisValue(VRModuleRawAxis.TouchpadY); currAxisValue[(int)ControllerAxis.Trigger] = currState.GetAxisValue(VRModuleRawAxis.Trigger); currAxisValue[(int)ControllerAxis.CapSenseGrip] = currState.GetAxisValue(VRModuleRawAxis.CapSenseGrip); currAxisValue[(int)ControllerAxis.IndexCurl] = currState.GetAxisValue(VRModuleRawAxis.IndexCurl); currAxisValue[(int)ControllerAxis.MiddleCurl] = currState.GetAxisValue(VRModuleRawAxis.MiddleCurl); currAxisValue[(int)ControllerAxis.RingCurl] = currState.GetAxisValue(VRModuleRawAxis.RingCurl); currAxisValue[(int)ControllerAxis.PinkyCurl] = currState.GetAxisValue(VRModuleRawAxis.PinkyCurl); switch (currentInput2DType) { case VRModuleInput2DType.Unknown: case VRModuleInput2DType.TrackpadOnly: currAxisValue[(int)ControllerAxis.PadX] = currState.GetAxisValue(VRModuleRawAxis.TouchpadX); currAxisValue[(int)ControllerAxis.PadY] = currState.GetAxisValue(VRModuleRawAxis.TouchpadY); if (!VIUSettings.individualTouchpadJoystickValue) { currAxisValue[(int)ControllerAxis.JoystickX] = currState.GetAxisValue(VRModuleRawAxis.TouchpadX); currAxisValue[(int)ControllerAxis.JoystickY] = currState.GetAxisValue(VRModuleRawAxis.TouchpadY); } break; case VRModuleInput2DType.JoystickOnly: currAxisValue[(int)ControllerAxis.JoystickX] = currState.GetAxisValue(VRModuleRawAxis.TouchpadX); currAxisValue[(int)ControllerAxis.JoystickY] = currState.GetAxisValue(VRModuleRawAxis.TouchpadY); if (!VIUSettings.individualTouchpadJoystickValue) { currAxisValue[(int)ControllerAxis.PadX] = currState.GetAxisValue(VRModuleRawAxis.TouchpadX); currAxisValue[(int)ControllerAxis.PadY] = currState.GetAxisValue(VRModuleRawAxis.TouchpadY); } break; case VRModuleInput2DType.Both: currAxisValue[(int)ControllerAxis.PadX] = currState.GetAxisValue(VRModuleRawAxis.TouchpadX); currAxisValue[(int)ControllerAxis.PadY] = currState.GetAxisValue(VRModuleRawAxis.TouchpadY); currAxisValue[(int)ControllerAxis.JoystickX] = currState.GetAxisValue(VRModuleRawAxis.JoystickX); currAxisValue[(int)ControllerAxis.JoystickY] = currState.GetAxisValue(VRModuleRawAxis.JoystickY); break; } // update d-pad var axis = new Vector2(currAxisValue[(int)ControllerAxis.PadX], currAxisValue[(int)ControllerAxis.PadY]); var deadZone = VIUSettings.virtualDPadDeadZone; if (axis.sqrMagnitude >= deadZone * deadZone) { var padPress = GetPress(ControllerButton.Pad); var padTouch = GetPress(ControllerButton.PadTouch); var right = Vector2.Angle(Vector2.right, axis) < 45f; var up = Vector2.Angle(Vector2.up, axis) < 45f; var left = Vector2.Angle(Vector2.left, axis) < 45f; var down = Vector2.Angle(Vector2.down, axis) < 45f; EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadRight, padPress && right); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadUp, padPress && up); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadLeft, padPress && left); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadDown, padPress && down); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadRightTouch, padTouch && right); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadUpTouch, padTouch && up); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadLeftTouch, padTouch && left); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadDownTouch, padTouch && down); var upperRight = axis.x > 0f && axis.y > 0f; var upperLeft = axis.x <0f && axis.y> 0f; var lowerLeft = axis.x < 0f && axis.y < 0f; var lowerRight = axis.x > 0f && axis.y < 0f; EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadUpperRight, padPress && upperRight); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadUpperLeft, padPress && upperLeft); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadLowerLeft, padPress && lowerLeft); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadLowerRight, padPress && lowerRight); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadUpperRightTouch, padTouch && upperRight); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadUpperLeftTouch, padTouch && upperLeft); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadLowerLeftTouch, padTouch && lowerLeft); EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.DPadLowerRightTouch, padTouch && lowerRight); } // update hair trigger var currTriggerValue = currAxisValue[(int)ControllerAxis.Trigger]; EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.FullTrigger, currTriggerValue >= 0.99f); if (EnumUtils.GetFlag(prevButtonPressed, (int)ControllerButton.HairTrigger)) { EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.HairTrigger, currTriggerValue >= (hairTriggerLimit - hairDelta) && currTriggerValue > 0.0f); } else { EnumUtils.SetFlag(ref currButtonPressed, (int)ControllerButton.HairTrigger, currTriggerValue > (hairTriggerLimit + hairDelta) || currTriggerValue >= 1.0f); } if (EnumUtils.GetFlag(currButtonPressed, (int)ControllerButton.HairTrigger)) { hairTriggerLimit = Mathf.Max(hairTriggerLimit, currTriggerValue); } else { hairTriggerLimit = Mathf.Min(hairTriggerLimit, currTriggerValue); } // record pad down axis values if (GetPressDown(ControllerButton.Pad)) { padDownAxis = new Vector2(currAxisValue[(int)ControllerAxis.PadX], currAxisValue[(int)ControllerAxis.PadY]); } if (GetPressDown(ControllerButton.PadTouch)) { padTouchDownAxis = new Vector2(currAxisValue[(int)ControllerAxis.PadX], currAxisValue[(int)ControllerAxis.PadY]); } // record press down time and click count var timeNow = Time.unscaledTime; for (int button = 0; button < CONTROLLER_BUTTON_COUNT; ++button) { if (GetPressDown((ControllerButton)button)) { if (timeNow - lastPressDownTime[button] < clickInterval) { ++clickCount[button]; } else { clickCount[button] = 1; } lastPressDownTime[button] = timeNow; } } // invoke event listeners for (ControllerButton button = 0; button < (ControllerButton)CONTROLLER_BUTTON_COUNT; ++button) { if (GetPress(button)) { if (GetPressDown(button)) { // PressDown event TryInvokeListener(button, ButtonEventType.Down); TryInvokeTypeListener(button, ButtonEventType.Down); } // Press event TryInvokeListener(button, ButtonEventType.Press); TryInvokeTypeListener(button, ButtonEventType.Press); } else if (GetPressUp(button)) { // PressUp event TryInvokeListener(button, ButtonEventType.Up); TryInvokeTypeListener(button, ButtonEventType.Up); if (timeNow - lastPressDownTime[(int)button] < clickInterval) { // Click event TryInvokeListener(button, ButtonEventType.Click); TryInvokeTypeListener(button, ButtonEventType.Click); } } } return(false); }
public override void AddListener(ControllerButton button, Action listener, ButtonEventType type = ButtonEventType.Click) { m_state.AddListener(button, listener, type); }
public override bool GetPress(ControllerButton button, bool usePrevState = false) { return(m_state.GetPress(button, usePrevState)); }
public bool IsXboxControllerButtonReleasedOnce(int PlayerID, ControllerButton Button) { var button = GetXboxButton(Button); return IsXboxControllerConnected(PlayerID) && oldXboxStates[PlayerID].IsButtonDown(button) && xboxStates[PlayerID].IsButtonUp(button); }
protected virtual void InvokeEvent(ControllerButton button) { }
extern public static Byte GameControllerGetButton(IntPtr gamecontroller, ControllerButton button);
extern public static ControllerButtonBind GameControllerGetBindForAxis(IntPtr gamecontroller, ControllerButton button);
public bool IsXboxControllerButtonUp(int PlayerID, ControllerButton Button) { return IsXboxControllerConnected(PlayerID) && xboxStates[PlayerID].IsButtonUp(GetXboxButton(Button)); }
public void Reset() { m_MoveAvailable = true; m_SelectedButton = null; SelectNewButton(); }
public override float LastPressDownTime(ControllerButton button) { return(m_state.LastPressDownTime(button)); }
public TextMenuItem(string text, ControllerButton button, Action onSelect, MenuGroup child = null) : base(child) { Text = text; OnSelect = onSelect; SelectButton = button; }
public bool IsXboxControllerButtonUp(int PlayerID, ControllerButton Button) { #if DEBUG_VERBOSE Debug.WriteLine("IsXboxControllerButtonUp() called in NullInputState"); #endif return false; }
protected virtual void TryInvokeListener(ControllerButton button, ButtonEventType type) { }
/// <summary> /// Add press up handler for the button on the controller identified by role /// </summary> public static void AddPressUp(HandRole role, ControllerButton button, Action callback) { GetState(role).AddListener(button, callback, ButtonEventType.Up); }
public override void RemoveListener(ControllerButton button, RoleValueEventListener listener, ButtonEventType type = ButtonEventType.Click) { m_state.RemoveListener(button, listener, type); }
/// <summary> /// Remove click handler for the button on the controller identified by role /// </summary> public static void RemoveClick(HandRole role, ControllerButton button, Action callback) { GetState(role).RemoveListener(button, callback, ButtonEventType.Click); }
public override bool GetPressUp(ControllerButton button) { return(m_state.GetPressUp(button)); }
/// <summary> /// Returns true during the frame the user releases the button on the controller identified by role /// </summary> public static bool GetPressUp(HandRole role, ControllerButton button) { return(GetState(role).GetPressUp(button)); }
public override int ClickCount(ControllerButton button) { return(m_state.ClickCount(button)); }
/// <summary> /// Returns time of the last frame that user pressed down the button on the controller identified by role /// </summary> public static float LastPressDownTime(HandRole role, ControllerButton button) { return(GetState(role).LastPressDownTime(button)); }
public override bool GetPress(ControllerButton button, bool usePrevState = false) { return(IsValidButton(button) && EnumUtils.GetFlag(usePrevState ? prevButtonPressed : currButtonPressed, (int)button)); }
/// <summary> /// Return amount of clicks in a row for the button on the controller identified by role /// Set ViveInput.clickInterval to configure click interval /// </summary> public static int ClickCount(HandRole role, ControllerButton button) { return(GetState(role).ClickCount(button)); }
public override float LastPressDownTime(ControllerButton button) { return(IsValidButton(button) ? lastPressDownTime[(int)button] : 0f); }
public bool GetButtonPressDown(ControllerButton button) { return(_controllerAdapter.GetButtonPressDown(button)); }
public virtual void RemoveListener(ControllerButton button, Action listener, ButtonEventType type = ButtonEventType.Click) { }
public bool GetButtonTouchUp(ControllerButton button) { return(_controllerAdapter.GetButtonTouchUp(button)); }
public virtual bool GetPress(ControllerButton button, bool usePrevState = false) { return(false); }
internal ControllerButtonEventArgs(ControllerInfo controller, ControllerButton button) { Controller = controller; Button = button; }
public virtual int ClickCount(ControllerButton button) { return(0); }
public XboxControllerButtonInputCommand(int PlayerID, ControllerButton Button, XboxControllerButtonInputCommandType CommandType) { this.PlayerID = PlayerID; this.Button = Button; this.CommandType = CommandType; }
public virtual void AddListener(ControllerButton button, RoleEventListener <TRole> listener, ButtonEventType type = ButtonEventType.Click) { }
public bool IsPrimeryGrabButtonOn(ControllerButton btn) { return(EnumUtils.GetFlag(m_primaryGrabButton, (int)btn)); }
public void SetPrimeryGrabButton(ControllerButton btn, bool isOn = true) { EnumUtils.SetFlag(ref m_primaryGrabButton, (int)btn, isOn); }
/// <summary> /// Resets the ControllerButton binding by navigating through all active binds and resetting any with the specified ControllerButton. /// </summary> /// <param name="controllerButton">The gamePad binding to reset.</param> public static void ResetBinding(ControllerButton controllerButton) { foreach (var b in binds) if (b.Value.HasListener(BindInputListener.CONTROLLER) && b.Value.ControllerButton == controllerButton) b.Value.RemoveListener(BindInputListener.CONTROLLER); }