Exemplo n.º 1
0
    public override NVRButtonInputs GetButtonState(NVRHand hand, NVRButtonID button)
    {
        SteamVR_Controller.Device controller;
        if (hand == LeftHand)
        {
            controller = SteamVR_Controller.Input((int)LeftHandTracker.index);
        }
        else
        {
            controller = SteamVR_Controller.Input((int)RightHandTracker.index);
        }

        NVRButtonInputs buttonState = new NVRButtonInputs();

        buttonState.Axis       = controller.GetAxis(InputMap[button]);
        buttonState.SingleAxis = buttonState.Axis.x;
        buttonState.PressDown  = controller.GetPressDown(InputMap[button]);
        buttonState.PressUp    = controller.GetPressUp(InputMap[button]);
        buttonState.IsPressed  = controller.GetPress(InputMap[button]);
        buttonState.TouchDown  = controller.GetTouchDown(InputMap[button]);
        buttonState.TouchUp    = controller.GetTouchUp(InputMap[button]);
        buttonState.IsTouched  = controller.GetTouch(InputMap[button]);

        return(buttonState);
    }
    public override NVRButtonInputs GetButtonState(NVRHand hand, NVRButtonID button)
    {
        NVRButtonInputs buttonState = new NVRButtonInputs();

        switch (button)
        {
        case NVRButtonID.HoldButton:
            if (grasping && !hand.Inputs[button].IsPressed)     // first frame of grasp
            {
                buttonState.Axis       = Vector2.one;
                buttonState.SingleAxis = 1;
                buttonState.PressDown  = true;
                buttonState.PressUp    = false;
                buttonState.IsPressed  = true;
                buttonState.TouchDown  = true;
                buttonState.TouchUp    = false;
                buttonState.IsTouched  = true;
            }
            else if (grasping && hand.Inputs[button].IsPressed)     // we're continuing to grasp
            {
                buttonState.Axis       = Vector2.one;
                buttonState.SingleAxis = 1;
                buttonState.PressDown  = false;
                buttonState.PressUp    = false;
                buttonState.IsPressed  = true;
                buttonState.TouchDown  = false;
                buttonState.TouchUp    = false;
                buttonState.IsTouched  = true;
            }
            else if (!grasping && !hand.Inputs[button].IsPressed)     // not grasping at all
            {
                buttonState.Axis       = Vector2.zero;
                buttonState.SingleAxis = 0;
                buttonState.PressDown  = false;
                buttonState.PressUp    = false;
                buttonState.IsPressed  = false;
                buttonState.TouchDown  = false;
                buttonState.TouchUp    = false;
                buttonState.IsTouched  = false;
            }
            else if (!grasping && hand.Inputs[button].IsPressed)     // first frame of not grasping after a grasp
            {
                buttonState.Axis       = Vector2.zero;
                buttonState.SingleAxis = 0;
                buttonState.PressDown  = false;
                buttonState.PressUp    = true;
                buttonState.IsPressed  = false;
                buttonState.TouchDown  = false;
                buttonState.TouchUp    = true;
                buttonState.IsTouched  = false;
            }

            break;

        case NVRButtonID.UseButton:
            buttonState.Axis       = Vector2.zero;
            buttonState.SingleAxis = 0;
            buttonState.PressDown  = false;
            buttonState.PressUp    = false;
            buttonState.IsPressed  = false;
            buttonState.TouchDown  = false;
            buttonState.TouchUp    = false;
            buttonState.IsTouched  = false;
            break;

        default:
            break;
        }

        return(buttonState);
    }
Exemplo n.º 3
0
    public override void SetButtonStates(NVRHand hand)
    {
        bool grasping = (hand == Player.LeftHand && leftGrasp > 0.9f) || (hand == Player.RightHand && rightGrasp > 0.9f);
        bool isUsing  = (hand == Player.LeftHand && leftUse > 0.9f) || (hand == Player.RightHand && rightUse > 0.9f);

        foreach (var button in hand.Inputs.Keys.ToList())
        {
            NVRButtonInputs buttonState = new NVRButtonInputs();
            switch (button)
            {
            case NVRButtonID.HoldButton:
                if (grasping && !hand.Inputs[button].IsPressed)     // first frame after grasp start
                {
                    buttonState.Axis       = Vector2.one;
                    buttonState.SingleAxis = 1;
                    buttonState.PressDown  = true;
                    buttonState.PressUp    = false;
                    buttonState.IsPressed  = true;
                    buttonState.TouchDown  = true;
                    buttonState.TouchUp    = false;
                    buttonState.IsTouched  = true;
                }
                else if (grasping && hand.Inputs[button].IsPressed)     // continuing to grasp after first frame
                {
                    buttonState.Axis       = Vector2.one;
                    buttonState.SingleAxis = 1;
                    buttonState.PressDown  = false;
                    buttonState.PressUp    = false;
                    buttonState.IsPressed  = true;
                    buttonState.TouchDown  = false;
                    buttonState.TouchUp    = false;
                    buttonState.IsTouched  = true;
                }
                else if (!grasping && !hand.Inputs[button].IsPressed)     // not grasping at all
                {
                    buttonState.Axis       = hand == Player.LeftHand ? new Vector2(leftGrasp, leftGrasp) : new Vector2(rightGrasp, rightGrasp);
                    buttonState.SingleAxis = hand == Player.LeftHand ? leftGrasp : rightGrasp;
                    buttonState.PressDown  = false;
                    buttonState.PressUp    = false;
                    buttonState.IsPressed  = false;
                    buttonState.TouchDown  = false;
                    buttonState.TouchUp    = false;
                    buttonState.IsTouched  = false;
                }
                else if (!grasping && hand.Inputs[button].IsPressed)     // first frame of not grasping after a grasp
                {
                    buttonState.Axis       = hand == Player.LeftHand ? new Vector2(leftGrasp, leftGrasp) : new Vector2(rightGrasp, rightGrasp);
                    buttonState.SingleAxis = hand == Player.LeftHand ? leftGrasp : rightGrasp;
                    buttonState.PressDown  = false;
                    buttonState.PressUp    = true;
                    buttonState.IsPressed  = false;
                    buttonState.TouchDown  = false;
                    buttonState.TouchUp    = true;
                    buttonState.IsTouched  = false;
                }
                break;

            case NVRButtonID.UseButton:
                if (isUsing && !hand.Inputs[button].IsPressed)     // first frame after use start
                {
                    buttonState.Axis       = Vector2.one;
                    buttonState.SingleAxis = 1;
                    buttonState.PressDown  = true;
                    buttonState.PressUp    = false;
                    buttonState.IsPressed  = true;
                    buttonState.TouchDown  = true;
                    buttonState.TouchUp    = false;
                    buttonState.IsTouched  = true;
                }
                else if (isUsing && hand.Inputs[button].IsPressed)     // continuing to use after first frame
                {
                    buttonState.Axis       = Vector2.one;
                    buttonState.SingleAxis = 1;
                    buttonState.PressDown  = false;
                    buttonState.PressUp    = false;
                    buttonState.IsPressed  = true;
                    buttonState.TouchDown  = false;
                    buttonState.TouchUp    = false;
                    buttonState.IsTouched  = true;
                }
                else if (!isUsing && !hand.Inputs[button].IsPressed)     // not using at all
                {
                    buttonState.Axis       = hand == Player.LeftHand ? new Vector2(leftUse, leftUse) : new Vector2(rightUse, rightUse);
                    buttonState.SingleAxis = hand == Player.LeftHand ? leftUse : rightUse;
                    buttonState.PressDown  = false;
                    buttonState.PressUp    = false;
                    buttonState.IsPressed  = false;
                    buttonState.TouchDown  = false;
                    buttonState.TouchUp    = false;
                    buttonState.IsTouched  = false;
                }
                else if (!isUsing && hand.Inputs[button].IsPressed)     // first frame of not using after a grasp
                {
                    buttonState.Axis       = hand == Player.LeftHand ? new Vector2(leftUse, leftUse) : new Vector2(rightUse, rightUse);
                    buttonState.SingleAxis = hand == Player.LeftHand ? leftUse : rightUse;
                    buttonState.PressDown  = false;
                    buttonState.PressUp    = true;
                    buttonState.IsPressed  = false;
                    buttonState.TouchDown  = false;
                    buttonState.TouchUp    = true;
                    buttonState.IsTouched  = false;
                }
                break;

            default:
                break;
            }
            hand.Inputs[button] = buttonState;
        }
    }