如何将Unity项目输入更新为SteamVR 2.0? [英] How to update your Unity project Input to SteamVR 2.0?

查看:130
本文介绍了如何将Unity项目输入更新为SteamVR 2.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于有些新版本的插件"SteamVR Unity Plugin 2.0",我的代码无法正常工作.

I have some Unity Scenes that worked well with the previous version of the SteamVR plugin, since there is a new version of the plugin "SteamVR Unity Plugin 2.0" my code no longer works.

https://steamcommunity.com/games/250820/announcements/detail/1696059027982397407

在按照文档说明导入新文件夹之前,我删除了"SteamVR"文件夹.

I deleted the "SteamVR" folder before importing the new one as the documentation say.

但是我得到了这个错误:

But I get this errors:

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?

因此我可以看到不推荐使用此类:

So I can see that this classes are deprecated:

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

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

What is the new way to get the Input by code using the SteamVR 2.0 plugin?

推荐答案

要迁移到SteamVR 2.0,请按照以下步骤操作:

To move to SteamVR 2.0 I followed this steps:

1):删除"SteamVR"文件夹,然后从Unity Asset Store导入"SteamVR"插件.

1) Delete the "SteamVR" folder, and then import the "SteamVR" plugin from the Unity Asset Store.

2)从场景中删除先前的"[CameraRig]"对象,然后拖动位于"SteamVR/Prefabs"上的新对象

2) Delete your previous "[CameraRig]" object from your scenes and drag the new one located on: "SteamVR/Prefabs"

3)检查控制器(左)"和控制器(右)"对象上的脚本"Steam VR_Behaviour_Pose"

3) Check for the script "Steam VR_Behaviour_Pose" on the "Controller (left)", and "Controller (right)" objects

姿势操作"字段和输入源"上应该是:

there on the "Pose Action" field, and on "Input Source" should be:

控制器(左)

Controller (left)

姿势动作:SkeletonLeftHand

Pose Action: SkeletonLeftHand

输入源:左手

控制器(右)

Controller (right)

姿势动作:SkeletonRightHand

Pose Action: SkeletonRightHand

输入源:右手

4)将手写脚本添加到控制器(左)"和控制器(右)"对象:

4) Add hand script to your "Controller (left)" and "Controller (right)" objects:

5)将自己的自定义脚本添加到控制器(左)"和控制器(右)"对象中,在我的情况下是"HTC Vivie Input"脚本.

5) Add your own custom script to your "Controller (left)" and "Controller (right)" objects, in my case "HTC Vivie Input" script.

6)确保没有任何编译错误,在这种情况下,您应该能够从Unity的窗口菜单中看到"SteamVR Input"和"SteamVR Input Live View",

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输入"菜单,然后添加操作:

7) By default for example the Menu button does not contain any Action asociated, or the Touch pad position, so open the "SteamVR Input" menu, and add the actions:

  • 触摸板

  • touchPad

touchPos

MenuButton

MenuButton

\

8),在您的SteamVR服务运行时,点击打开绑定用户界面"按钮, 并编辑当前绑定

8) Click on the "Open binding UI" button while your SteamVR service is running, and edit the current binding

将菜单"与菜单按钮"动作相关联.

Asociate the "Menu" with the "MenuButton" action.

将触摸"与触摸板"动作相关联.

Asociate the "Touch" with the "touchPad" action.

将位置"与"touchPos"动作相关联.

Asociate the "Position" with the "touchPos" action.

然后从"SteamVR输入"菜单中按保存并生成"按钮

Then press the Save and generate button from the "SteamVR Input" menu

9)打开您的自定义脚本(本例中为"HTC Vivie Input")并添加代码,例如:

9) Open your custom script ("HTC Vivie Input" in my case) and add your code, for example:

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"菜单中的默认绑定

10) When making a release build replace the default bindings from the "binding UI" menu

这篇关于如何将Unity项目输入更新为SteamVR 2.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆