How to update your Unity project Input to SteamVR 2.0?

前端 未结 1 1387
离开以前
离开以前 2021-01-02 11:46

I have some Unity Scenes that worked well with the previous version of the SteamVR plugin, since there is a new version of the plugin \"SteamVR Unity Plugin 2.0\" my code no

1条回答
  •  孤街浪徒
    2021-01-02 12:32

    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();
        }
    
        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

    0 讨论(0)
提交回复
热议问题