我有一些Unity场景在以前版本的SteamVR插件上工作得很好,因为有了新版本的插件"SteamVR Unity plugin2.0“,我的代码不再工作了。
https://steamcommunity.com/games/250820/announcements/detail/1696059027982397407
正如文档所说,在导入新文件夹之前,我删除了"SteamVR“文件夹。
但是我得到了这个错误:
error CS0246: The type or namespace name `SteamVR_Controller' could not be found. Are you missing an assembly reference?
error CS0246: The type or namespace name `SteamVR_TrackedController' could not be found. Are you missing an assembly reference?所以我可以看到这个类已经被弃用了:
private SteamVR_Controller.Device device;
private SteamVR_TrackedController controller;
controller = GetComponent<SteamVR_TrackedController>();使用SteamVR 2.0插件通过代码获取输入的新方法是什么?
发布于 2018-10-14 04:48:27
为了迁移到SteamVR 2.0,我遵循了以下步骤:
1)删除SteamVR文件夹,然后从Unity Asset Store导入SteamVR插件。
2)从场景中删除之前的"CameraRig“对象,然后拖动位于:"SteamVR/Prefabs”上的新对象。
3)检查“控制器(左)”和“控制器(右)”对象上的脚本"Steam VR_Behaviour_Pose“


在"Pose Action“字段上,在"Input Source”上应该是:
控制器(左)
姿势动作:SkeletonLeftHand
输入源:左侧
控制器(右)
姿势动作:SkeletonRightHand
输入源:right Hand
4)将手写脚本添加到“控制器(左)”和“控制器(右)”对象中:

5)将您自己的自定义脚本添加到“控制器(左)”和“控制器(右)”对象中,在我的示例中是"HTC Vivie Input“脚本。

6)确保您没有任何编译错误,在这种情况下,您应该能够在Unity菜单上看到"SteamVR Input“和"SteamVR Input Live View”。

7)默认情况下,菜单按钮不包含任何关联的操作,或触摸板位置,因此打开"SteamVR Input“菜单,并添加操作:

\



8)在SteamVR服务运行时单击“打开绑定UI”按钮,然后编辑当前绑定
将"Menu“与"MenuButton”操作关联起来。

将"Touch“与"touchPad”操作相关联。
将"Position“与"touchPos”操作关联起来。

然后按下"SteamVR Input“菜单中的保存并生成按钮

9)打开您的自定义脚本(在我的示例中是“HTC Vivie 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)在进行发布构建时替换"binding UI“菜单中的缺省绑定

https://stackoverflow.com/questions/52686286
复制相似问题