Led*_*ine 5 c# plugins unity-game-engine steamvr
我有一些Unity场景与之前版本的SteamVR插件运行良好,因为有一个新版本的插件"SteamVR Unity Plugin 2.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?
Run Code Online (Sandbox Code Playgroud)
所以我可以看到这些类已被弃用:
private SteamVR_Controller.Device device;
private SteamVR_TrackedController controller;
controller = GetComponent<SteamVR_TrackedController>();
Run Code Online (Sandbox Code Playgroud)
使用SteamVR 2.0插件通过代码获取输入的新方法是什么?
Led*_*ine 22
要转到SteamVR 2.0,我按照以下步骤操作:
1)删除"SteamVR"文件夹,然后从Unity资源商店导入"SteamVR"插件.
2)从场景中删除以前的"[CameraRig]"对象并拖动位于"SteamVR/Prefabs"上的新对象
3)检查"Controller(左)"和"Controller(右)"对象上的脚本"Steam VR_Behaviour_Pose"

在"姿势动作"字段上,"输入源"应该是:
控制器(左)
姿势动作:SkeletonLeftHand
输入源:左手
控制器(右)
姿势动作:SkeletonRightHand
输入源:右手
4)将手脚本添加到"Controller(左)"和"Controller(右)"对象:
5)在我的"HTC Vivie Input"脚本中,将您自己的自定义脚本添加到"Controller(左)"和"Controller(右)"对象中.
6)确保没有任何编译错误,在这种情况下,您应该能够在Unity的窗口菜单上看到"SteamVR输入"和"SteamVR输入实时视图",

7)默认情况下,例如菜单按钮不包含任何动作,或触摸板位置,因此打开"SteamVR输入"菜单,并添加动作:
触摸板
touchPos
菜单按钮
8)在SteamVR服务运行时单击"打开绑定UI"按钮,然后编辑当前绑定
使用"MenuButton"操作关联"菜单".
使用"touchPad"动作分配"Touch".
使用"touchPos"操作将"位置"关联起来.
然后按"SteamVR输入"菜单中的保存并生成按钮
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;
}
}
Run Code Online (Sandbox Code Playgroud)
10)进行发布构建时,请替换"绑定UI"菜单中的默认绑定
| 归档时间: |
|
| 查看次数: |
8257 次 |
| 最近记录: |