How to update your Unity project Input to SteamVR 2.0?

寵の児 提交于 2019-11-30 15:22:47

To move to SteamVR 2.0 I followed this steps:

1) Delete the "SteamVR" folder, and then import the "SteamVR" plugin from the Unity Asset Store.

2) Delete your previous "[CameraRig]" object from your scenes and drag the new one located on: "SteamVR/Prefabs"

3) Check for the script "Steam VR_Behaviour_Pose" on the "Controller (left)", and "Controller (right)" objects

there on the "Pose Action" field, and on "Input Source" should be:

Controller (left)

Pose Action: SkeletonLeftHand

Input Source: Left Hand

Controller (right)

Pose Action: SkeletonRightHand

Input Source: right Hand

4) Add hand script to your "Controller (left)" and "Controller (right)" objects:

5) Add your own custom script to your "Controller (left)" and "Controller (right)" objects, in my case "HTC Vivie Input" script.

6) Make sure you do not have any compilation errors, in that case you should be able to see the "SteamVR Input" and "SteamVR Input Live View" on window menu from Unity,

7) By default for example the Menu button does not contain any Action asociated, or the Touch pad position, so open the "SteamVR Input" menu, and add the actions:

  • touchPad

  • touchPos

  • MenuButton

\

8) Click on the "Open binding UI" button while your SteamVR service is running, and edit the current binding

Asociate the "Menu" with the "MenuButton" action.

Asociate the "Touch" with the "touchPad" action.

Asociate the "Position" with the "touchPos" action.

Then press the Save and generate button from the "SteamVR Input" menu

9) Open your custom script ("HTC Vivie Input" in my case) and add your code, for example:

using UnityEngine;
using Valve.VR;
using Valve.VR.InteractionSystem;

public class HTCVivieInput : MonoBehaviour {

    private Hand hand;

    // Use this for initialization
    void Start () {
        hand = gameObject.GetComponent<Hand>();
    }

    public Vector2 getTrackPadPos()
    {
        SteamVR_Action_Vector2 trackpadPos = SteamVR_Input._default.inActions.touchPos;
        return trackpadPos.GetAxis(hand.handType);
    }

    public bool getPinch()
    {
        return SteamVR_Input._default.inActions.GrabPinch.GetState(hand.handType);
    }

    public bool getPinchDown()
    {
        return SteamVR_Input._default.inActions.GrabPinch.GetStateDown(hand.handType);
    }

    public bool getPinchUp()
    {
        return SteamVR_Input._default.inActions.GrabPinch.GetStateUp(hand.handType);
    }

    public bool getGrip()
    {
        return SteamVR_Input._default.inActions.GrabGrip.GetState(hand.handType);
    }

    public bool getGrip_Down()
    {
        return SteamVR_Input._default.inActions.GrabGrip.GetStateDown(hand.handType);
    }

    public bool getGrip_Up()
    {
        return SteamVR_Input._default.inActions.GrabGrip.GetStateUp(hand.handType);
    }

    public bool getMenu()
    {
        return SteamVR_Input._default.inActions.MenuButton.GetState(hand.handType);
    }

    public bool getMenu_Down()
    {
        return SteamVR_Input._default.inActions.MenuButton.GetStateDown(hand.handType);
    }

    public bool getMenu_Up()
    {
        return SteamVR_Input._default.inActions.MenuButton.GetStateUp(hand.handType);
    }

    public bool getTouchPad()
    {
        return SteamVR_Input._default.inActions.Teleport.GetState(hand.handType);
    }

    public bool getTouchPad_Down()
    {
        return SteamVR_Input._default.inActions.Teleport.GetStateDown(hand.handType);
    }

    public bool getTouchPad_Up()
    {
        return SteamVR_Input._default.inActions.Teleport.GetStateUp(hand.handType);
    }

    public Vector3 getControllerPosition()
    {
        SteamVR_Action_Pose[] poseActions = SteamVR_Input._default.poseActions;
        if (poseActions.Length > 0)
        {
            return poseActions[0].GetLocalPosition(hand.handType);
        }
        return new Vector3(0, 0, 0);
    }

    public Quaternion getControllerRotation()
    {
        SteamVR_Action_Pose[] poseActions = SteamVR_Input._default.poseActions;
        if (poseActions.Length > 0)
        {
            return poseActions[0].GetLocalRotation(hand.handType);
        }
        return Quaternion.identity;
    }
}

10) When making a release build replace the default bindings from the "binding UI" menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!