简体   繁体   English

如何更新Unity项目输入到SteamVR 2.0?

[英]How to update your Unity project Input to SteamVR 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. 我有一些Unity场景与之前版本的SteamVR插件运行良好,因为有一个新版本的插件“SteamVR Unity Plugin 2.0”我的代码不再有效。

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

I deleted the "SteamVR" folder before importing the new one as the documentation say. 如文档所述,我在导入新文件夹之前删除了“SteamVR”文件夹。

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>();

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: 要转到SteamVR 2.0,我按照以下步骤操作:

1) Delete the "SteamVR" folder, and then import the "SteamVR" plugin from the Unity Asset Store. 1)删除“SteamVR”文件夹,然后从Unity资源商店导入“SteamVR”插件。

2) Delete your previous "[CameraRig]" object from your scenes and drag the new one located on: "SteamVR/Prefabs" 2)从场景中删除以前的“[CameraRig]”对象并拖动位于“SteamVR / Prefabs”上的新对象

3) Check for the script "Steam VR_Behaviour_Pose" on the "Controller (left)", and "Controller (right)" objects 3)检查“Controller(左)”和“Controller(右)”对象上的脚本“Steam VR_Behaviour_Pose” 在此输入图像描述 在此输入图像描述

there on the "Pose Action" field, and on "Input Source" should be: 在“姿势动作”字段上,“输入源”应该是:

Controller (left) 控制器(左)

Pose Action : SkeletonLeftHand 姿势动作 :SkeletonLeftHand

Input Source : Left Hand 输入源 :左手

Controller (right) 控制器(右)

Pose Action : SkeletonRightHand 姿势动作 :SkeletonRightHand

Input Source : right Hand 输入源 :右手

4) Add hand script to your "Controller (left)" and "Controller (right)" objects: 4)将手脚本添加到“Controller(左)”和“Controller(右)”对象:

在此输入图像描述

5) Add your own custom script to your "Controller (left)" and "Controller (right)" objects, in my case "HTC Vivie Input" script. 5)在我的“HTC Vivie输入”脚本中,将您自己的自定义脚本添加到“Controller(左)”和“Controller(右)”对象中。

在此输入图像描述

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, 6)确保没有任何编译错误,在这种情况下,您应该能够在Unity的窗口菜单上看到“SteamVR输入”和“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: 7)默认情况下,例如菜单按钮不包含任何动作,或触摸板位置,因此打开“SteamVR输入”菜单,并添加动作:

  • touchPad 触摸板

  • touchPos touchPos

  • MenuButton 菜单按钮

在此输入图像描述 \\ \\ 在此输入图像描述 在此输入图像描述 在此输入图像描述

8) Click on the "Open binding UI" button while your SteamVR service is running, and edit the current binding 8)在SteamVR服务运行时单击“打开绑定UI”按钮,然后编辑当前绑定

Asociate the "Menu" with the "MenuButton" action. 使用“MenuButton”操作关联“菜单”。

在此输入图像描述

Asociate the "Touch" with the "touchPad" action. 使用“touchPad”动作分配“Touch”。

Asociate the "Position" with the "touchPos" action. 使用“touchPos”操作将“位置”关联起来。

在此输入图像描述

Then press the Save and generate button from the "SteamVR Input" menu 然后按“SteamVR输入”菜单中的保存并生成按钮

在此输入图像描述

9) Open your custom script ("HTC Vivie Input" in my case) and add your code, for example: 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) When making a release build replace the default bindings from the "binding UI" menu 10)进行发布构建时,请替换“绑定UI”菜单中的默认绑定

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM