Closed aschau closed 7 years ago
Here's one way to get that functionality. Please note we may be removing UnityVRDevice in a future release, but calling this method in some Update() should do the trick.
In UnityVRDevice's UpdateState, add:
public override void UpdateState() {
// Existing code here.
if (!VRSettings.enabled) {
UpdateHeadTrackingForVRCameras();
}
}
private void UpdateHeadTrackingForVRCameras() {
Quaternion pose =
InputTracking.GetLocalRotation(VRSettings.enabled ? VRNode.Head : VRNode.CenterEye);
Camera[] cams = Camera.allCameras;
for (int i = 0; i < cams.Length; i++) {
Camera cam = cams[i];
if (cam.targetTexture == null && cam.cullingMask != 0) {
cam.GetComponent<Transform>().localRotation = pose;
}
}
}
The OPENGL errors are being tracked in #492, and can be silenced by enabling OpenGLES3 in Player Settings.
Please reopen if you'd like to follow up with mono / stereo switching.
@aschau I use monoscopic rendering in my app primarily for showing my Daydream app on my phone, usually to a group of people (on the go, at social gatherings, to other game developers, etc.), although sometimes 1:1 when I don't have a Daydream View or Cardboard viewer with me.
This works like this: I've added three VR SDKs in Unity's player build settings, in this order: (Daydream, None, Cardboard). This way Daydream rendering is the default when the app launches on Daydream ready devices, but None (=monoscopic) is the default on other devices. This ensures that when the game is launched from Daydream home the app launches in VR (Daydream) mode and works as expected.
On non-Daydream devices the app launches in "magic window" mode, and I provide an on-screen VR icon which lets users switch to VR (Cardboard) mode.
I've wired up the Android "back" button so that the app exits VR (Daydream) mode and switches to "magic window" / demo mode.
Finally, since you asked about the controller:
I'm still getting crashes after going between "none" to cardboard VR mode and looking about for 5-10 seconds. in logcat the only errors I can see are those openGL errors and I still get them when deselecting "auto graphics API" (OpenGLES3 was already at the top of the list). My scene is a default scene and randomly has worked once or twice but more often than not will hang head tracking (the settings button for cardboard is still fully responsive) and then will crash after a while. I initially had none and cardboard (in that order) in my device list and I just tried going from daydream, none, cardboard in my device list and still same issue.
I verified if I just launch straight into cardboard it works fine but I need to launch in "none" and be able to turn on stereoscopic. I'm on Unity 5.6.0f3 and GVR SDK 1.4
@WelchCompositions Could you please file a bug report within Unity, and reply with the case ID?
Hi @miraleung I am trying to achieve Monoscopic rendering while keeping the phone tracking, you mentioned adding code snippet to "UnityVRDevice" that was back in April, I am using 1.50 now and looks like "UnityVRDevice" was removed. Can you please advice on how to achieve that? 1- Start the app in Portrait mode showing a UI menu items 2- Toggle to VR stereoscopic 3- Toggle to VR monoscopic
Also keen for the functionality requested by @Ibrahimhassan1 .
The code snippet does not necessarily need to be added to UnityVRDevice - it can be any script in your scene.
@miraleung But there is an override call in the snippet I will try to remove it and see if that works.
@miraleung That script doesn't work for me, I am now using the phone Gyroscope sensor to drive the camera but having some issues with Gyro Drift not sure how to fix them.
@Ibrahimhassan1 you may check this discussion https://github.com/googlevr/gvr-unity-sdk/issues/453
And, have you added "None" to top of your VR build settings?
Also using Gyroscope is expensive. I suggest solving this early without building on gyro. Or you still want to keep tracking the orientation in 2D mode?
@Ibrahimhassan1 Try this gyro camera script https://gist.github.com/kormyen/a1e3c144a30fc26393f14f09989f03e1 . It's not great but it works.
I also wanted screen touch swiping to offset the camera like the JauntVR app but couldn't work it out.
Also here is my VR mode switching (Cardboard to "magic window" (non-VR-360-mode)) script if it is of any use. It is pretty hacky trying to get around problems with Unity, but works. https://gist.github.com/kormyen/ae0bca96544634567e5eef49ed3cc2cd . Note: Unity crashes consistently if you keep switching VR on and off (even without the scene reset hack).
Open to any improvements.
Just an FYI - I've opened up a new issue (see #703) to discuss the overall UX for handling Daydream + Cardboard + Magic Window in a single app.
I currently am trying to work with Unity 5.6's native cardboard support to implement my VR application. I am trying to allow the user to switch between monoscopic and stereoscopic views within the same scene; however, the stereo UI overrides any screen overlay canvas I put into the scene. Another issue is that there is no way I can find to switch out of a stereoscopic view while still maintaining the head motion controls.
I tried to look at how to change the functionality of the [X] button to toggle this but from what I've seen from the forums the only thing that has been suggested is Input.GetKeyDown(KeyCode.Escape) and that doesn't work either.
Also, even though I added some functionality to switch modes if not starting in stereo mode, the device starts throwing OPENGL Native Plugin-Errors.