LoginSignup
3
3

More than 5 years have passed since last update.

GearVRのアプリ開発時にエディタで視点移動をしたい

Last updated at Posted at 2017-02-13

GearVRのアプリをUnityで開発していると、エディタでの実行時にHMDの回転をしたくなる時がある。

このような場合、開発に使うPCにOculusなどのHMDが接続されていればそこで回転などをエディタ内でもテストできる。
ただし出先での開発だったり、開発機がMacだったりなど色々な理由でHMDが使えない場合がある。

解決策: MouseLookのスクリプトを使う

ということでMouseでの操作で視点を回転できるようにする。以前はFirstPersonControllerなどに付属するスクリプトもあったが全く同等のものがStandardAssetには無かったので下記のスクリプトを使った。

かつ、このままでGearVRなどのHMDで実行した時にもマウスに反応する処理が残ってしまう。そこで下記のスクリプトを使い、VR実行時は該当のスクリプトを無効にするようにした。

DebugHelper.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VR;

public class DebugHelper : MonoBehaviour {

    public MonoBehaviour targetComponent; //アタッチしたSmoothMouseLookのスクリプトをアタッチする

    // Use this for initialization
    void Start () {
        if (VRSettings.enabled) {
            this.targetComponent.enabled = false;
        }
    }
}

上記の2つのスクリプトをメインのカメラに下記のようにアタッチしている。(インスペクタ上でSmoothMouseLookのスクリプトをDebugHelperのTargetComponentの所へドラッグしてドロップ)

Unity_5_6_0b3__64bit__-_main_unity_-_VR-TileGolf_-_Android__OpenGL_4_1_.png

結果

まだ潜在的な問題もありそうだが、ひとまず動いている。
結果的にPC向けのビルドも簡単に作れるようになった。(PlayerSettingでVR Supportをオフにするだけ)

ScreenFlow.gif

3
3
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
3