Unity Free版でOculus Riftを使う

Oculus RiftのUnity用SDKはUniry Pro向けとなっていますが、一応前回のHydraと同じような方法でUniry Free版でも動作させることができます。(ただし一部制限あり)

Unity Free - Oculus 1/2 Unity Free - Oculus 1/2

Unity Oculus SDKの使い方

OculusVR Developer Cneterにユーザ登録して、「ovr_unity_0.2.4_lib.zip」をダウンロード・解凍します。

UnityのProjectビューの右クリックメニューから「Import Package」→「Custom Package」をクリックします。

解凍したフォルダ内の「OculusUnityIntegration」→「OculusUnityIntegrationTuscanyDemo.unitypackage」を選択して「開く」をクリックします。

当初Unity 4.1.5を使用していたため以下のようなエラーが発生しましたが、Unity 4.2.1にアップデートして解消しました。(参考:Unity 4.2 supports anti-aliasing on render targets | Unity 4 Integration | Oculus Rift Developer Forums)

Assets/OVR/Scripts/OVRCamera.cs(112,39): error CS1061: Type `UnityEngine.RenderTexture' does not contain a definition for `antiAliasing' and no extension method `antiAliasing' of type `UnityEngine.RenderTexture' could be found (are you missing a using directive or an assembly reference?)

インポートが完了したらProjectビューから「Assets」→「Tuscany」→「Scenes」→「VRDemo_Tuscany.unity」を開きます。

Oculusを接続して再生ボタンをクリックしてみると、Unity Free版では以下のエラーが発生して正しく動作しません。

DllNotFoundException: OculusPlugin
License error. Plugins are only supported in Unity Pro!

前回同様、Free版でなんとか動作させる方法を紹介します。

Unity Free版でUnity Oculus SDKを動作させる

まず、Unity.exeのインストールフォルダ(C:\Program Files\Unity\Editor)に、プロジェクトフォルダのAssets→Plugins内にあるOculusPlugin.dllをコピーします。

次にProjectビューから「OVR」→「Scripts」配下の「OVRGamepadController.cs」と「OVRDevice.cs」を開いて、全てのDllImportを以下のように変更します。

変更前 : [DllImport ("OculusPlugin")]
変更後 : [DllImport ("OculusPlugin.dll")]

再びOculusを接続して再生すると、今度は一応実行されます。ただ、実行してすぐに左目側の表示がブラックアウトしてしまいます。

Hierarchyビューから「OVRPlayerController」を選択し、Inspectorビューの「OVRMain Menu(Script)」をオフにすると、正しく両目とも表示されるようになります。

Unity Free - Oculus 2/2 Unity Free - Oculus 2/2

「OVRMain Menu(Script)」内の原因箇所は特定できていません。このままだとメニュー機能が使用できないと思うので、改善の余地があります。

また、再生時に以下のエラーが発生しますが、これはPro版のみの機能のようで、対策は未確認です。こちらはとりあえず動作には影響が無いように見えます。(参考:unity3d - can't use image filters (npot-RT are not supported or RT are disabled completely) when applying Glow effect - Stack Overflow)

can't use image filters (npot-RT are not supported or RT are disabled completely)

OculusUnityIntegrationのみ使用する場合

上記は、動作が確認しやすいように「OculusUnityIntegrationTuscanyDemo.unitypackage」をインポートする手順を紹介しました。

Unityで単純にOculus Riftの機能のみ使用したい場合は、「OculusUnityIntegration.unitypackage」の方をインポートして、「OVR」→「Prefabs」配下のPrefabを利用します。

OVRCameraController : Oculus Riftでの表示に対応したカメラ
OVRPlayerController : OVRCameraControllerを取り付けたCharacter Contoroller

床になるオブジェクトを作ったうえでOVRPlayerControllerを配置し、再生すると動作が確認できます。

なお、ビルドの設定については「Anti Aliasing」を「4x」以上にするなど、推奨値があるようです。詳しくは以下の参考ページやSDKのドキュメントで確認して下さい。

参考ページ

関連記事

blog comments powered by Disqus