3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UnityでOculus向けの環境で壊れたOVRHeadsetEmulatorを直す

Last updated at Posted at 2019-08-13

はじめに

UnityのOculus Integrationはエディタ上でカメラの動きをエミュレートできるOVRHeadsetEmulatorがあります。

image.png

このコンポーネントはOVRCameraRig.prefabOVRPlayerController.prefabにアタッチされているのですぐに使えるのですがv1.38とv1.39でOpenVRがサポートされた時に動かなくなってしまいました。せっかくの便利なコンポーネントなので動くように直してみました。
※1.37以前と1.40はそのままで動作します。

修正方法

InitOVRManager()を実行するかどうかの判定をエディタの時は無視します。これはOpenVRサポート前と同じ挙動です。

diff --git a/Assets/Oculus/VR/Scripts/OVRManager.cs b/Assets/Oculus/VR/Scripts/OVRManager.cs
index bff7d992..4f6f3d45 100644
--- a/Assets/Oculus/VR/Scripts/OVRManager.cs
+++ b/Assets/Oculus/VR/Scripts/OVRManager.cs
@@ -1294,7 +1294,9 @@ public class OVRManager : MonoBehaviour
        private void Awake()
        {
                //If OVRPlugin is initialized on Awake(), or if the device is OpenVR, OVRManager should be initialized right away.
+#if !UNITY_EDITOR
                if (OVRPlugin.initialized || (Settings.enabled && Settings.loadedDeviceName == OPENVR_UNITY_NAME_STR))
+#endif
                {
                        InitOVRManager();
                }

別の方法

Oculusのフォーラムにも修正方法がありOVRPlugin.initializedを反転してInitOVRManager()を実行しています。ですがこのプロパティはドキュメントがなく挙動が分からないので上記のようにエディタの時だけ変更した方が安全です。

diff --git a/Assets/Oculus/VR/Scripts/OVRManager.cs b/Assets/Oculus/VR/Scripts/OVRManager.cs
index bff7d992..30ee8cde 100644
--- a/Assets/Oculus/VR/Scripts/OVRManager.cs
+++ b/Assets/Oculus/VR/Scripts/OVRManager.cs
@@ -1294,7 +1294,7 @@ public class OVRManager : MonoBehaviour
        private void Awake()
        {
                //If OVRPlugin is initialized on Awake(), or if the device is OpenVR, OVRManager should be initialized right away.
-               if (OVRPlugin.initialized || (Settings.enabled && Settings.loadedDeviceName == OPENVR_UNITY_NAME_STR))
+               if (!OVRPlugin.initialized || (Settings.enabled && Settings.loadedDeviceName == OPENVR_UNITY_NAME_STR))
                {
                        InitOVRManager();
                }
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?