gpt4 book ai didi

c# - 如何将您的 Unity 项目输入更新为 SteamVR 2.0?

转载 作者:太空狗 更新时间:2023-10-29 22:05:04 25 4
gpt4 key购买 nike

我有一些 Unity 场景可以很好地与以前版本的 SteamVR 插件一起使用,因为有一个新版本的插件“SteamVR Unity 插件 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?

所以我可以看到这个类已被弃用:

private SteamVR_Controller.Device device;
private SteamVR_TrackedController controller;
controller = GetComponent<SteamVR_TrackedController>();

使用 SteamVR 2.0 插件通过代码获取输入的新方法是什么?

最佳答案

为了转移到 SteamVR 2.0,我遵循了以下步骤:

1)删除“SteamVR”文件夹,然后从Unity Asset Store导入“SteamVR”插件。

2) 从场景中删除之前的“[CameraRig]”对象并将新的对象拖动到:“SteamVR/Prefabs”

3) 检查“ Controller (左)”和“ Controller (右)”对象上的脚本“Steam VR_Behaviour_Pose” enter image description here enter image description here

在“姿势 Action ”字段和“输入源”上应该是:

Controller (左)

姿势 Action :SkeletonLeftHand

输入源:左手

Controller (右)

姿势 Action :SkeletonRightHand

输入源:右手

4) 将手写脚本添加到“ Controller (左)”和“ Controller (右)”对象:

enter image description here

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

enter image description here

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

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

  • 触控板

  • 触摸位置

  • 菜单按钮

enter image description here\ enter image description here enter image description here enter image description here

8) 在您的 SteamVR 服务运行时单击“打开绑定(bind) UI”按钮,并编辑当前绑定(bind)

将“菜单”与“MenuButton”操作相关联。

enter image description here

将“触摸”与“触摸板”操作相关联。

将“位置”与“touchPos” Action 相关联。

enter image description here

然后按“SteamVR 输入”菜单中的“保存并生成”按钮

enter image description here

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) 在制作发布版本时,从“绑定(bind) UI”菜单中替换默认绑定(bind)

enter image description here

关于c# - 如何将您的 Unity 项目输入更新为 SteamVR 2.0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52686286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com