- Home /
GoogleVR handling Close button in Stereo mode
Hello,
I'm trying to intercept the GoogleVR close button press so I can switch back to Mono. I've created the class below to attempt to catch the BackButtonPressed
flag. However it doesn't appear to ever change before the entire app is shutdown. Is BackButtonPressed
the correct way to catch the press of this button?
Specs:
GVR SDK: GoogleVR 1.3.0
Unity: Unity 5.6f3
Phone: Google Nexus 5X, OS 7.1.2
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class VideoPlayerControls : MonoBehaviour
{
...
/**
* Handle Cardboard back button press
*/
void Update ()
{
if (GvrViewer.Instance.BackButtonPressed)
{
print("BACK BUTTON PRESSED"); //This never gets displayed in Android logs
// Handle Switch to Mono - This will call VRSettings.LoadDeviceByName("None");
playlist.videos [0].cardboardMode = !playlist.videos [0].cardboardMode;
player = PlayerFactory.Init (playlist, aControlType);
player.SetUrl (playlist.videos [0].url);
}
}
...
}
Answer by jackj31416 · Jul 05, 2017 at 09:01 PM
I upgraded to GVR 1.6 and Unity 5.6.2f1 and removed all GvrViewer references. I'm able to detect the button press by checking for the ESC key.
/**
* Handle Cardboard back button press
*/
void Update ()
{
if (Input.GetKey(KeyCode.Escape))
{
print("CARDBOARD CLOSE BUTTON PRESSED");
playlist.videos [0].cardboardMode = false;
player = PlayerFactory.Init (playlist, aControlType);
player.SetUrl (playlist.videos [0].url);
}
}
Answer by Spidlee · Apr 20, 2017 at 06:50 PM
HI,
GvrViewer.Instance.BackButtonPressed, is indeed the way to check if [X] is pressed.
Have you tried the below to toggle VR on/off?
GvrViewer.Instance.VRModeEnabled = !GvrViewer.Instance.VRModeEnabled;
Prior to that Update call, VRSettings.enabled = true;
had already been called. However, it still wasn't triggering. It might have been a bug in the Unity integration with GVR 1.3.