要迁移到 SteamVR 2.0,我按照以下步骤操作:
1)删除“SteamVR”文件夹,然后从 Unity Asset Store 导入“SteamVR”插件。
2)从场景中删除之前的“[CameraRig]”对象,然后拖动位于“SteamVR/Prefabs”上的新对象
3) Check for the script "Steam VR_Behaviour_Pose" on the "Controller (left)", and "Controller (right)" objects
在“姿势动作”字段和“输入源”上应该是:
控制器(左)
姿势动作: 骷髅左手
输入源: 左手
控制器(右)
姿势动作: 骷髅右手
输入源: 右手
4)将手写脚本添加到“控制器(左)”和“控制器(右)”对象中:
5)将您自己的自定义脚本添加到“控制器(左)”和“控制器(右)”对象中,在我的例子中为“HTC Vivie 输入”脚本。
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)默认情况下,例如菜单按钮不包含任何关联的操作或触摸板位置,因此打开“SteamVR 输入”菜单,然后添加操作:
\
8)在 SteamVR 服务运行时单击“打开绑定 UI”按钮,
并编辑当前绑定
将“菜单”与“菜单按钮”操作相关联。
将“触摸”与“触摸板”操作相关联。
将“位置”与“触摸板”操作相关联。
然后按“SteamVR 输入”菜单中的“保存并生成”按钮
9)打开您的自定义脚本(在我的例子中为“HTC Vive Input”)并添加您的代码,例如:
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)制作发布版本时,替换“绑定 UI”菜单中的默认绑定