準備
Google VR SDK for Unityをインポートする。
Android7.0以上に設定
Other Settings > Minimum API Level > Android7.0
SDKをDaydreamに設定
XR Settings > Virtual Reality Supported > Virtual Reality SDKs > Daydream
ヘッドセットの動きをマウスで擬似的に表現する
GoogleVR/Prefabs/GvrEditorEmulator
をヒエラルキーに置く
https://developers.google.com/vr/unity/reference/prefab/GvrEditorEmulator
2台目のアンドロイド端末をコントローラにする(手元にコントローラがない場合)
The Controller Emulator
https://developers.google.com/vr/daydream/controller-emulator#game_engines
参考
Controller Emulatorを利用してDaydream実機なしでDaydream対応アプリを開発する方法
ビルドせずに実機でアプリの挙動を確認する
GoogleVR/Prefabs/InstantPreview/GvrInstantPreviewMain
をヒエラルキーに置く
https://developers.google.com/vr/develop/unity/instant-preview
初回起動時にInstant Previewアプリが自動でインストールされる。
次回からはinstantPreview.cs
のInstall Apk on Run
のチェックを外す。
コントローラでクリック
コントローラでポインターを合わせたオブジェクトをクリックする、といった一番基本的な動作を実装する手順。
https://developers.google.com/vr/develop/unity/controller-support
コントローラのエントリポイントを設置する
GoogleVR/Prefabs/Controller/GvrControllerMain
をヒエラルキーに置く
https://developers.google.com/vr/unity/reference/prefab/GvrControllerMain
接続状況、バッテリー残量、ジャイロ、加速度、ボタンの押下など、コントローラの状態を知るスクリプトがアタッチされているプレハブ
ポインターを設置する
GoogleVR/Prefabs/Controller/GvrControllerPointer
をヒエラルキーに置く
https://developers.google.com/vr/unity/reference/prefab/GvrControllerPointer
子要素のLaserにアタッチされているGvrLaserVisual.cs
のShrink Laser
のチェックを外すとポインターまでの線が引かれる。
https://developers.google.com/vr/unity/reference/class/GvrLaserVisual
イベントを有効にする
GoogleVR/Prefabs/EventSystem/GvrEventSystem
をヒエラルキーに置く
https://developers.google.com/vr/unity/reference/prefab/GvrEventSystem
レイキャストする
メインカメラにGvrPointerPhysicsRaycaster.cs
をアタッチ
https://developers.google.com/vr/unity/reference/class/GvrPointerPhysicsRaycaster
クリックされた時の処理を設定する
対象オブジェクトにEvent Trigger
をアタッチ
Add New Event Type > PointerClick
を選択
最後にクリックイベント(正規コントローラのタッチパッドを押し込む)が発火したときに呼びたい関数を設定して完成
https://docs.unity3d.com/ja/current/ScriptReference/EventSystems.EventTrigger.html