如何从 Oculus 遥控器获取输入?

How do I get input from the Oculus remote?

我想知道如何在 Unity3D 5.3.4f 中使用 oculus 遥控器。我找到了一些关于 OVR 映射的 documentation,但我似乎无法理解。

我想要实现的是当中间按钮(Button.One)被点击时

我现在用的就是这行代码

if (OVRInput.GetUp(OVRInput.Button.One))
    {
        Debug.Log("remote click");
    }

但是当我 运行 应用程序时,我得到了这个错误。

NullReferenceException: Object reference not set to an instance of an object OVRInput.GetUp (Button virtualMask, Controller controllerMask) (at Assets/OVR/Scripts/OVRInput.cs:600) menuButtonHandler.Update () (at Assets/menuButtonHandler.cs:136)

可以在这个脚本中找到

/// <summary>
/// Gets the current up state of the given virtual button mask with the given controller mask.
/// Returns true if any masked button was released this frame on any masked controller and no other masked button is still down this frame.
/// </summary>
public static bool GetUp(Button virtualMask, Controller controllerMask = Controller.Active)
{
    return OVRManager.input.GetResolvedButtonUp(virtualMask, RawButton.None, controllerMask);
}

有没有人在unity中用过Oculus遥控器,可以帮帮我吗?

谢谢,

约翰

在调用 GetUp() 之前,可能需要初始化该方法中的一个对象。

仔细查看您的初始化代码,以及您可能拥有的任何示例——我敢打赌,您不仔细查看就会发现缺少的东西。我不熟悉 Unity API,但如果它们是类似于 PC 或移动 C++ API 的东西,您很可能错过了一个步骤,或者忘记启动 VR 服务。

要在 Unity 版本 2017.1.1 中使用输入,您必须先下载 "Oculus Utilities for Unity"

Oculus Utilities asset package for Unity

然后你必须在Unity中导入包, 去: -- "Asset" --> "Import package" --> "Custom package"

浏览您的 "Oculus Utilities download"

点击导入

在调用输入检查函数之前调用函数 "OVRInput.update()"。

void Update ()
    {
        OVRInput.Update(); // Call before checking the input

        if (OVRInput.Get(OVRInput.Button.DpadLeft)) {
            print("left button pressed");
        }
        if (OVRInput.Get(OVRInput.Button.DpadRight)) {
            print("right button pressed");
        }
        if (OVRInput.Get(OVRInput.Button.One)) {
            print("round button pressed");
        }
    }

有关 OVRInput 的更多信息,请查看此 link

OVRInput