Example #1
0
    /*
     * ScrollControl
     *
     * Control scheme for moving on the w axis similar to early iPod controls by making circles on the touchpad
     */
    void ScrollControl()
    {
        if (SteamVR_Controller.Input((int)gameObject.GetComponent <SteamVR_TrackedObject>().index).GetTouch(EVRButtonId.k_EButton_SteamVR_Touchpad))
        {
            var axis = SteamVR_Controller.Input((int)gameObject.GetComponent <SteamVR_TrackedObject>().index).GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);

            //define areas for up, down, left and right
            if (axis.y > .2 && (axis.x > -.2 && axis.x <= .2))
            {
                tUp = stage;
            }
            if (axis.y < .2 && (axis.x >= -.2 && axis.x < .2))
            {
                tDown = stage;
            }
            if (axis.x > .2 && (axis.y >= -.2 && axis.y < .2))
            {
                tRight = stage;
            }
            if (axis.x < .2 && (axis.y > -.2 && axis.y <= .2))
            {
                tLeft = stage;
            }
        }
        else
        { //if the players stops touching the touch pad, reset all the variables
            stage  = 0;
            tUp    = -1;
            tDown  = -1;
            tLeft  = -1;
            tRight = -1;
        }

        if (stage == 0)
        {//wait for the first touch, the variable will have a value of 1
            if (tUp == 0 || tDown == 0 || tLeft == 0 || tRight == 0)
            {
                stage = 1;
            }
        }
        else if (stage == 1)
        {//wait for acceptable second input, the second touch should be directly clockwise or counterclockwise from the first touch, the second touch will register as 1 here and then have a value of 2 in the next stage
            if ((tUp == 1 && tLeft == 1) ||
                (tUp == 1 && tRight == 1) ||
                (tDown == 1 && tRight == 1) ||
                (tDown == 1 && tLeft == 1))
            {
                stage = 2;
            }
            else if ((tUp == 1 && tLeft == -1 && tRight == -1 && tDown == -1) ||
                     (tUp == -1 && tLeft == 1 && tRight == -1 && tDown == -1) ||
                     (tUp == -1 && tLeft == -1 && tRight == 1 && tDown == -1) ||
                     (tUp == -1 && tLeft == -1 && tRight == -1 && tDown == 1))
            {//check if the touch is the same as the first touch to prevent the values from resetting
                stage = 1;
            }
            else
            {//if the second touch is invalid reset the variables
                stage  = 0;
                tUp    = -1;
                tDown  = -1;
                tLeft  = -1;
                tRight = -1;
            }
        }
        else if (stage == 2)
        {//depending on the order the first and second touches happened, detect if movement of the finger was clockwise or counter clockwise and move on the w axis appropriatly
            if ((tUp == 1 && tRight == 2) || (tRight == 1 && tDown == 2) || (tDown == 1 && tLeft == 2) || (tLeft == 1 && tUp == 2))
            {
                player.WMove(1);
                SlideAllHeldObjectsAlongW(1);
                callWMoveOnAllHyperScripts = true;
                SteamVR_Controller.Input((int)gameObject.GetComponent <SteamVR_TrackedObject>().index).TriggerHapticPulse(1000);
            }
            else if ((tUp == 2 && tRight == 1) || (tRight == 2 && tDown == 1) || (tDown == 2 && tLeft == 1) || (tLeft == 2 && tUp == 1))
            {
                player.WMove(-1);
                SlideAllHeldObjectsAlongW(-1);
                callWMoveOnAllHyperScripts = true;
                SteamVR_Controller.Input((int)gameObject.GetComponent <SteamVR_TrackedObject>().index).TriggerHapticPulse(1000);
            }

            //reset variables to setup for moving again
            stage  = 0;
            tUp    = -1;
            tDown  = -1;
            tLeft  = -1;
            tRight = -1;
        }
    }