Setting up Unity for Gear VR development is a relatively straightforward task, but working with VR makes it more complicated for new developers.
Although VR is officially supported with Unity 5.1, most of the "tutorials" or "guides" out there are pretty out of date. And since Oculus (what Gear VR runs on) keeps updating their Utilities for Unity quite often it so happens that every update brings new ways to setting up Gear VR.
In this tutorial, I'm going to be using Unity 5.4 although it also should work with 5.3 as well.This guide contains all the tips and procedures followed to get it working and hopefully this will get you up to speed for mobile VR development as well.
This guide assumes that you have set up Java SDK and Android SDK and working USB drivers for your Samsung device on your machine. If not there are plenty of guides out there which will help you. This is Unity's official guide.
Once you have that and you wish to test the apps on your Samsung device without docking your phone into Gear VR every time you build and run from Unity you can enable development mode for Gear VR.
Open Application Manager > Gear VR Service and select that.
Click on VR service version several times until it says "You are a developer" and the Developer Mode toggle shows up.
Again note that I'm using Unity 5.4.1f1.
The good thing with Unity 5 is you don't need to do any additional integration for it to make it work with VR. All you need is the Oculus Utilities which include all the API, scripts and prefabs we need to work with Gear VR which is in the form of a unity package.Download it from here.(Under Engine Integration).
Open up Unity and create a new project.
Since we're building for Android, Go to File > Build Settings. Select Android and hit switch platform.
In the same Build Settings open the Player Settings. Set Virtual Reality Supported in the Other settings which would show Oculus under SDK's. Also set your Bundle Identifier and Minimum API Level while you're at it.
You will need your Device ID for this which you can get by running adb devices on a terminal or a Command Prompt on Windows. Copy that into the form and download the .osig file. This file should be placed in the following directory inside your unity project – /YourProjectDirectory/Assets/Plugins/Android/assets/. If such DIR doesn't exist, create one. If you don't do this step you will see the APK is not Signed error while running the App.
Open the OculusUtilities.unitypackage you've downloaded which will open in Unity. Select all and Import. This contains all the Universal Scripts, Event Handlers and much more which all are needed to create a VR App. Although Unity has made integration with Gear VR much simpler and complete than before, it still lacks these utilities.
Once importing is done the OVR and Plugins Folder in your project will be there which contain all the said utilities we will be using later.
In the scenes Folder under OVR you can find a few example scenes which are basic at best.
You can download the VR Samples from Unity's Asset store which have more detailed projects built specifically for Gear VR and Rift.
To test the demo scenes on your device connect it to your machine. Open the Scene and go to File > Build Settings or Shift + CMD + B on a mac and click on Add Open Scenes. Check the Scene(s) you want to be in your app. Then select Build & Run.
Insert your device into the Gear VR headset and test.