要切换到SteamVR 2.0,我按照以下步骤进行:
1) 删除"SteamVR"文件夹,然后从Unity Asset Store导入"SteamVR"插件。
2) 从场景中删除以前的"[CameraRig]"对象,并将位于"SteamVR/Prefabs"上的新对象拖动到场景中。
3) 在"Controller (left)"和"Controller (right)"对象上检查脚本"Steam VR_Behaviour_Pose"
![enter image description here](https://istack.dev59.com/0iAFy.webp)
在"Pose Action"字段和"Input Source"字段上应该是:
Controller (left)
Pose Action: SkeletonLeftHand
Input Source: Left Hand
Controller (right)
Pose Action: SkeletonRightHand
Input Source: right Hand
4) 将手部脚本添加到"Controller (left)"和"Controller (right)"对象中:
![enter image description here](https://istack.dev59.com/82TuL.webp)
5) 在您的“控制器(左)”和“控制器(右)”对象中添加自己的自定义脚本,在我的情况下是“HTC Vivie Input”脚本。
![enter image description here](https://istack.dev59.com/yHp6c.webp)
6)确保没有编译错误,如果有错误,你应该能在Unity的窗口菜单中看到“SteamVR输入”和“SteamVR输入实时视图”,
![enter image description here](https://istack.dev59.com/yGqfH.webp)
7)默认情况下,例如菜单按钮不包含任何关联操作,或者触摸板位置,因此打开“SteamVR输入”菜单,并添加以下操作:
- touchPad
- touchPos
- MenuButton
\
![enter image description here](https://istack.dev59.com/Tf6OS.webp)
8) 当您的SteamVR服务正在运行时,单击“打开绑定UI”按钮,并编辑当前绑定
将“菜单”与“MenuButton”操作相关联。
![enter image description here](https://istack.dev59.com/8REAF.webp)
将“Touch”与“touchPad”操作相关联。
将“Position”与“touchPos”操作相关联。
![enter image description here](https://istack.dev59.com/w484e.webp)
然后从“SteamVR输入”菜单中按下保存和生成按钮
![enter image description here](https://istack.dev59.com/vcJgK.webp)
9) 打开您的自定义脚本(在我的情况下是“HTC Vivie Input”),并添加您的代码,例如:
using UnityEngine;
using Valve.VR;
using Valve.VR.InteractionSystem;
public class HTCVivieInput : MonoBehaviour {
private Hand hand;
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) 在制作发布版本时,从“绑定UI”菜单中替换默认绑定。
![enter image description here](https://istack.dev59.com/9iayg.webp)