Exemple #1
0
        public static float GetActionFloat(TouchControllerHand hand, TouchControllerButton button, out bool wasChangedSinceLast, INPUT_DESIRED inputMode, bool fallback = false)
        {
            ActionStateGetInfo getfloat = new ActionStateGetInfo()
            {
                Action = GetAction(hand, button, inputMode),
                Type   = StructureType.TypeActionStateGetInfo
            };

            ActionStateFloat floatresult = new ActionStateFloat()
            {
                Type = StructureType.TypeActionStateFloat
            };

            baseHMD.Xr.GetActionStateFloat(baseHMD.globalSession, in getfloat, ref floatresult);

            if (floatresult.IsActive == 0)
            {
                if (fallback)
                {
                    // couldn't find an input...
                    wasChangedSinceLast = false;
                    return(0f);
                }

                // fallback if couldn't find float
                return(GetActionBool(hand, button, out wasChangedSinceLast, true) ? 1f : 0f);
            }

            wasChangedSinceLast = floatresult.ChangedSinceLastSync == 1;
            return(floatresult.CurrentState);
        }
 /// <summary>
 /// Handle button touches in standard mode.
 /// </summary>
 private void DoStandard()
 {
     for (int i = 0; i < Input.touchCount; i++)
     {
         // Find all collisions
         if (Input.touches[i].phase == TouchPhase.Began || Input.touches[i].phase == TouchPhase.Stationary || Input.touches[i].phase == TouchPhase.Moved)
         {
             RaycastHit[] hits;
             Ray          ray = uiCamera.ScreenPointToRay(Input.touches[i].position);
             hits = Physics.RaycastAll(ray, 100.0f, 1 << buttonLayer);
             foreach (RaycastHit hit in hits)
             {
                 TouchControllerButton button = hit.collider.gameObject.GetComponent <TouchControllerButton>();
                 if (button != null)
                 {
                     DoButton(button, Input.touches[i]);
                 }
             }
         }
         else                 // Released button
         {
             if (fingersToButtons.ContainsKey(Input.touches[i].fingerId))
             {
                 fingersToButtons[Input.touches[i].fingerId].Released();
                 fingersToButtons.Remove(Input.touches[i].fingerId);
             }
         }
     }
 }
Exemple #3
0
        public override float GetValue(InputManager manager)
        {
            TouchController tc = VRDeviceSystem.GetSystem?.GetController((Index & (1 << 16)) != 0 ? TouchControllerHand.Right : TouchControllerHand.Left);

            if (tc == null)
            {
                return(0f);
            }
            TouchControllerButton button = (TouchControllerButton)(Index & 0xFF);

            switch (button)
            {
            case TouchControllerButton.Grip:
                return(tc.Grip);

            case TouchControllerButton.Thumbstick:
                return((Index & (1 << 17)) != 0 ? tc.ThumbstickAxis.Y : tc.ThumbstickAxis.X);

            case TouchControllerButton.Touchpad:
                return((Index & (1 << 17)) != 0 ? tc.ThumbAxis.Y : tc.ThumbAxis.X);

            case TouchControllerButton.Trigger:
                return(tc.Trigger);

            default:
                return(tc.IsPressed(button) ? 1f : 0f);
            }
        }
        private bool IsButtonPressed(TouchControllerButton button, SpatialInteractionSourceState state)
        {
            switch (button)
            {
            case TouchControllerButton.Thumbstick:
                return(state.ControllerProperties.IsThumbstickPressed);

            case TouchControllerButton.Touchpad:
                return(state.ControllerProperties.IsTouchpadPressed);

            case TouchControllerButton.A when state.ControllerProperties.IsTouchpadPressed && hand == SpatialInteractionSourceHandedness.Right:
                return(ThumbAxis.X >= 0.0f);

            case TouchControllerButton.B when state.ControllerProperties.IsTouchpadPressed && hand == SpatialInteractionSourceHandedness.Right:
                return(ThumbAxis.X < 0.0f);

            case TouchControllerButton.X when state.ControllerProperties.IsTouchpadPressed && hand == SpatialInteractionSourceHandedness.Left:
                return(ThumbAxis.X < 0.0f);

            case TouchControllerButton.Y when state.ControllerProperties.IsTouchpadPressed && hand == SpatialInteractionSourceHandedness.Left:
                return(ThumbAxis.X >= 0.0f);

            case TouchControllerButton.Trigger:
                return(state.IsSelectPressed);

            case TouchControllerButton.Grip:
                return(state.IsGrasped);

            case TouchControllerButton.Menu:
                return(state.IsMenuPressed);

            default:
                return(false);
            }
        }
Exemple #5
0
        public static bool GetActionBool(TouchControllerHand hand, TouchControllerButton button, out bool wasChangedSinceLast, bool fallback = false)
        {
            ActionStateGetInfo getbool = new ActionStateGetInfo()
            {
                Action = GetAction(hand, button, INPUT_DESIRED.CLICK),
                Type   = StructureType.TypeActionStateGetInfo
            };

            ActionStateBoolean boolresult = new ActionStateBoolean()
            {
                Type = StructureType.TypeActionStateBoolean
            };

            baseHMD.Xr.GetActionStateBoolean(baseHMD.globalSession, in getbool, ref boolresult);

            if (boolresult.IsActive == 0)
            {
                if (fallback)
                {
                    // couldn't find an input...
                    wasChangedSinceLast = false;
                    return(false);
                }

                // fallback if couldn't find bool
                return(GetActionFloat(hand, button, out wasChangedSinceLast, INPUT_DESIRED.VALUE, true) >= 0.75f);
            }

            wasChangedSinceLast = boolresult.ChangedSinceLastSync == 1;
            return(boolresult.CurrentState == 1);
        }
 /// <summary>
 /// Release button if user moved finger away from it. Assign new button to given fingerId.
 /// </summary>
 private void AssignButtonToFinger(int fingerId, TouchControllerButton button)
 {
     if (fingersToButtons.ContainsKey (fingerId)) {
         fingersToButtons[fingerId].Released();
         fingersToButtons.Remove(fingerId);
     }
     fingersToButtons.Add (fingerId, button);
 }
Exemple #7
0
        public static Silk.NET.OpenXR.Action GetAction(TouchControllerHand hand, TouchControllerButton button, INPUT_DESIRED wantMode)
        {
            switch (button)
            {
            case TouchControllerButton.ButtonXA:
                return(MappedActions[(int)hand, (int)HAND_PATHS.ButtonXA]);

            case TouchControllerButton.ButtonYB:
                return(MappedActions[(int)hand, (int)HAND_PATHS.ButtonYB]);

            case TouchControllerButton.Grip:
                return(wantMode == INPUT_DESIRED.CLICK ? MappedActions[(int)hand, (int)HAND_PATHS.GripClick] : MappedActions[(int)hand, (int)HAND_PATHS.GripValue]);

            case TouchControllerButton.Menu:
                return(MappedActions[(int)hand, (int)HAND_PATHS.Menu]);

            case TouchControllerButton.System:
                return(MappedActions[(int)hand, (int)HAND_PATHS.System]);

            case TouchControllerButton.Trigger:
                return(wantMode == INPUT_DESIRED.CLICK ? MappedActions[(int)hand, (int)HAND_PATHS.TriggerClick] : MappedActions[(int)hand, (int)HAND_PATHS.TriggerValue]);

            case TouchControllerButton.Thumbstick:
                switch (wantMode)
                {
                default:
                case INPUT_DESIRED.CLICK:
                    return(MappedActions[(int)hand, (int)HAND_PATHS.ThumbstickClick]);

                case INPUT_DESIRED.XAXIS:
                    return(MappedActions[(int)hand, (int)HAND_PATHS.ThumbstickX]);

                case INPUT_DESIRED.YAXIS:
                    return(MappedActions[(int)hand, (int)HAND_PATHS.ThumbstickY]);
                }

            case TouchControllerButton.Touchpad:
                switch (wantMode)
                {
                default:
                case INPUT_DESIRED.CLICK:
                    return(MappedActions[(int)hand, (int)HAND_PATHS.TrackpadClick]);

                case INPUT_DESIRED.XAXIS:
                    return(MappedActions[(int)hand, (int)HAND_PATHS.TrackpadX]);

                case INPUT_DESIRED.YAXIS:
                    return(MappedActions[(int)hand, (int)HAND_PATHS.TrackpadY]);

                case INPUT_DESIRED.VALUE:
                    return(MappedActions[(int)hand, (int)HAND_PATHS.TrackpadForce]);
                }

            default:
                throw new ArgumentException("Don't know button: " + button);
            }
        }
 /// <summary>
 /// Release button if user moved finger away from it. Assign new button to given fingerId.
 /// </summary>
 private void AssignButtonToFinger(int fingerId, TouchControllerButton button)
 {
     if (fingersToButtons.ContainsKey(fingerId))
     {
         fingersToButtons[fingerId].Released();
         fingersToButtons.Remove(fingerId);
     }
     fingersToButtons.Add(fingerId, button);
 }
Exemple #9
0
        public override bool IsReleased()
        {
            TouchController tc = VRDeviceSystem.GetSystem?.GetController((Index & (1 << 16)) != 0 ? TouchControllerHand.Right : TouchControllerHand.Left);

            if (tc == null)
            {
                return(false);
            }
            TouchControllerButton strippedButton = (TouchControllerButton)(Index & 0xFF);

            if (tc.IsPressReleased(strippedButton) == false)
            {
                return(false);
            }
            Vector2 axis;

            switch (strippedButton)
            {
            default:
                return(true);

            case TouchControllerButton.Thumbstick:
                axis = tc.ThumbstickAxis;
                break;

            case TouchControllerButton.Touchpad:
                axis = tc.TouchpadAxis;
                break;
            }
            switch (Index >> 17)
            {
            case 0:     // up
                return(axis.Y > 0.5f);

            case 1:     // down
                return(axis.Y < -0.5f);

            case 2:     // left
                return(axis.X < -0.5f);

            case 3:     // right
                return(axis.X > 0.5f);

            case 4:     // center
                return(axis.X > -0.5f && axis.X < 0.5f && axis.Y < 0.5f && axis.Y > -0.5f);
            }
            return(false);
        }
 private OpenVR.Controller.ButtonId ToOpenVrButton(TouchControllerButton button)
 {
     switch (button)
     {
         case TouchControllerButton.Thumbstick:
             return OpenVR.Controller.ButtonId.ButtonSteamVrTouchpad;              
         case TouchControllerButton.Trigger:
             return OpenVR.Controller.ButtonId.ButtonSteamVrTrigger;
         case TouchControllerButton.Grip:
             return OpenVR.Controller.ButtonId.ButtonGrip;
         case TouchControllerButton.Menu:
             return OpenVR.Controller.ButtonId.ButtonApplicationMenu;
         default:
             return OpenVR.Controller.ButtonId.ButtonMax;
     }
 }
    /// <summary>
    /// Do the actual button action
    /// </summary>
    private void DoButton(TouchControllerButton button, Touch touch)
    {
        AssignButtonToFinger(touch.fingerId, button);
        button.Held();
        switch (button.type)
        {
        case TouchControllerButtonType.LEFT:
            x = -1 * xButtonValue;
            break;

        case TouchControllerButtonType.RIGHT:
            x = xButtonValue;
            break;

        case TouchControllerButtonType.UP:
            y = yButtonValue;
            break;

        case TouchControllerButtonType.DOWN:
            y = -1 * yButtonValue;
            break;

        case TouchControllerButtonType.JUMP:
            if (touch.phase == TouchPhase.Began)
            {
                jumpButtonDown = true;
            }
            jumpButtonHeld = true;
            break;

        case TouchControllerButtonType.RUN:
            if (allowRun)
            {
                running = true;
            }
            break;

        case TouchControllerButtonType.CHEAT:
            if (touch.phase == TouchPhase.Began)
            {
                GameObject.Find("GameController").GetComponent <GameManager>().toggle = !GameObject.Find("GameController").GetComponent <GameManager>().toggle;               // toggles onoff at each click
            }
            break;
        }
    }
Exemple #12
0
        public override bool IsTouchReleased(TouchControllerButton button)
        {
            switch (button)
            {
            case TouchControllerButton.Thumbstick:
                var thumbFlag = hand == TouchControllerHand.Left ? 0x00000400 : 0x00000004;
                //ovrButton_RThumb
                return((previousTouchesState & thumbFlag) == thumbFlag && (currentTouchesState & thumbFlag) != thumbFlag);

            case TouchControllerButton.A:
                //ovrButton_A
                return((previousTouchesState & 0x00000001) == 0x00000001 && (currentTouchesState & 0x00000001) != 0x00000001);

            case TouchControllerButton.B:
                //ovrButton_B
                return((previousTouchesState & 0x00000002) == 0x00000002 && (currentTouchesState & 0x00000002) != 0x00000002);

            case TouchControllerButton.X:
                //ovrButton_X
                return((previousTouchesState & 0x00000100) == 0x00000100 && (currentTouchesState & 0x00000100) != 0x00000100);

            case TouchControllerButton.Y:
                //ovrButton_Y
                return((previousTouchesState & 0x00000200) == 0x00000200 && (currentTouchesState & 0x00000200) != 0x00000200);

            case TouchControllerButton.Trigger:
                return(previousTrigger > TriggerAndGripDeadzone && currentTrigger <= TriggerAndGripDeadzone);

            case TouchControllerButton.Grip:
                return(previousGrip > TriggerAndGripDeadzone && currentGrip <= TriggerAndGripDeadzone);

            case TouchControllerButton.Menu:
                return((previousTouchesState & 0x00100000) == 0x00100000 && (currentTouchesState & 0x00100000) != 0x00100000);

            default:
                return(false);
            }
        }
        public override bool IsPressed(TouchControllerButton button)
        {
            switch (button)
            {
            case TouchControllerButton.Thumbstick:
                var thumbFlag = hand == TouchControllerHand.Left ? 0x00000400 : 0x00000004;
                //ovrButton_RThumb
                return((currentButtonsState & thumbFlag) == thumbFlag);

            case TouchControllerButton.A:
                //ovrButton_A
                return((currentButtonsState & 0x00000001) == 0x00000001);

            case TouchControllerButton.B:
                //ovrButton_B
                return((currentButtonsState & 0x00000002) == 0x00000002);

            case TouchControllerButton.X:
                //ovrButton_X
                return((currentButtonsState & 0x00000100) == 0x00000100);

            case TouchControllerButton.Y:
                //ovrButton_Y
                return((currentButtonsState & 0x00000200) == 0x00000200);

            case TouchControllerButton.Trigger:
                return(currentTrigger > triggerAndGripDeadzone);

            case TouchControllerButton.Grip:
                return(currentGrip > triggerAndGripDeadzone);

            case TouchControllerButton.Menu:
                return((currentButtonsState & 0x00100000) == 0x00100000);

            default:
                return(false);
            }
        }
    /// <summary>
    /// Do the actual button action
    /// </summary>
    private void DoButton(TouchControllerButton button, Touch touch)
    {
        AssignButtonToFinger(touch.fingerId, button);
        button.Held();
        switch (button.type)
        {
        case TouchControllerButtonType.LEFT:
            x = -1 * xButtonValue;
            break;

        case TouchControllerButtonType.RIGHT:
            x = xButtonValue;
            break;

        case TouchControllerButtonType.UP:
            y = yButtonValue;
            break;

        case TouchControllerButtonType.DOWN:
            y = -1 * yButtonValue;
            break;

        case TouchControllerButtonType.JUMP:
            if (touch.phase == TouchPhase.Began)
            {
                jumpButtonDown = true;
            }
            jumpButtonHeld = true;
            break;

        case TouchControllerButtonType.RUN:
            if (allowRun)
            {
                running = true;
            }
            break;
        }
    }
        private bool IsButtonTouched(TouchControllerButton button, SpatialInteractionSourceState state)
        {
            switch (button)
            {
            case TouchControllerButton.Touchpad:
                return(state.ControllerProperties.IsTouchpadTouched);

            case TouchControllerButton.A when state.ControllerProperties.IsTouchpadPressed && hand == SpatialInteractionSourceHandedness.Right:
                return(ThumbAxis.X >= 0.0f);

            case TouchControllerButton.B when state.ControllerProperties.IsTouchpadPressed && hand == SpatialInteractionSourceHandedness.Right:
                return(ThumbAxis.X < 0.0f);

            case TouchControllerButton.X when state.ControllerProperties.IsTouchpadPressed && hand == SpatialInteractionSourceHandedness.Left:
                return(ThumbAxis.X < 0.0f);

            case TouchControllerButton.Y when state.ControllerProperties.IsTouchpadPressed && hand == SpatialInteractionSourceHandedness.Left:
                return(ThumbAxis.X >= 0.0f);

            default:
                return(false);
            }
        }
 public override bool IsTouchedDown(TouchControllerButton button) => !IsButtonTouched(button, previousState) ? IsButtonTouched(button, currentState) : false;
Exemple #17
0
 /// <summary>
 /// Returns true if in this frame the button switched to pressed state
 /// </summary>
 /// <param name="button"></param>
 /// <returns></returns>
 public abstract bool IsTouchedDown(TouchControllerButton button);
Exemple #18
0
 /// <summary>
 /// Returns true if in this frame the button was released
 /// </summary>
 /// <param name="button"></param>
 /// <returns></returns>
 public abstract bool IsPressReleased(TouchControllerButton button);
 public override bool IsPressedDown(TouchControllerButton button)
 {
     return(controller?.GetPressDown(ToOpenVrButton(button)) ?? false);
 }
 public override bool IsTouchReleased(TouchControllerButton button)
 {
     return(controller?.GetTouchUp(ToOpenVrButton(button)) ?? false);
 }
 public override bool IsTouchReleased(TouchControllerButton button) => IsButtonTouched(button, previousState) ? !IsButtonTouched(button, currentState) : false;
 public override bool IsTouched(TouchControllerButton button)
 {
     return controller?.GetTouch(ToOpenVrButton(button)) ?? false;
 }
 public override bool IsTouched(TouchControllerButton button) => !IsButtonTouched(button, currentState);
 public override bool IsPressed(TouchControllerButton button) => IsButtonPressed(button, currentState);
Exemple #25
0
	/// <summary>
	/// Do the actual button action
	/// </summary>
	private void DoButton(TouchControllerButton button, Touch touch) {
		AssignButtonToFinger (touch.fingerId, button);
		button.Held();
		switch (button.type) {
			case TouchControllerButtonType.LEFT:
				x = -1 * xButtonValue;
				break;
			case TouchControllerButtonType.RIGHT:
				x = xButtonValue;
				break;
			case TouchControllerButtonType.UP:
				y = yButtonValue;
				break;
			case TouchControllerButtonType.DOWN:
				y = -1 * yButtonValue;
				break;
			case TouchControllerButtonType.JUMP:
				if (touch.phase == TouchPhase.Began) {
					jumpButtonDown = true;
				}
				jumpButtonHeld = true;
				break;
			case TouchControllerButtonType.RUN:
				if (allowRun) running = true;
				break;
		}
	}
 /// <summary>
 /// Do the actual button action
 /// </summary>
 private void DoButton(TouchControllerButton button, Touch touch)
 {
     AssignButtonToFinger (touch.fingerId, button);
     button.Held();
     switch (button.type) {
         case TouchControllerButtonType.LEFT:
             x = -1 * xButtonValue;
             break;
         case TouchControllerButtonType.RIGHT:
             x = xButtonValue;
             break;
         case TouchControllerButtonType.UP:
             y = yButtonValue;
             break;
         case TouchControllerButtonType.DOWN:
             y = -1 * yButtonValue;
             break;
         case TouchControllerButtonType.JUMP:
         if (touch.phase == TouchPhase.Began) {
                 jumpButtonDown = true;
             }
             jumpButtonHeld = true;
             break;
         case TouchControllerButtonType.RUN:
             if (allowRun) running = true;
             break;
         case TouchControllerButtonType.CHEAT:
             if (touch.phase == TouchPhase.Began)
             GameObject.Find("GameController").GetComponent<GameManager>().toggle = !GameObject.Find("GameController").GetComponent<GameManager>().toggle; // toggles onoff at each click
         break;
     }
 }
 public override bool IsPressReleased(TouchControllerButton button)
 {
     return controller?.GetPressUp(ToOpenVrButton(button)) ?? false;
 }