1
\$\begingroup\$

When I build a game using Unity 2017.2.0f3 and the Cardboard SDK (using XR settings) and run it on my device, I see two controls overlaid on the screen, a cross and a gear:

enter image description here

Currently, pressing the cross control does nothing. I'd like to make the cross exit VR mode when pressed.

\$\endgroup\$
0

3 Answers 3

3
+50
\$\begingroup\$

When clicking ✕ (close), your Unity app should get an escape key press notification & you should be able to handle it the same way as an actual key down event. For example, to quit, you would do this:

void Update(){
  if(Input.GetKeyDown(KeyCode.Escape)){
    // close icon pressed, place appropriate code here
    Application.Quit();
  }
}

There was an error that prevented this; make sure Unity & your various SDKs are patched & up to date.

\$\endgroup\$
1
  • \$\begingroup\$ Someone anonymously edited attempted to edit this answer with the statement "it is not work, I think it maybe block be due to Cardboard SDK." If you run into a problem with the answer, leave some feedback (as a comment, not an edit) describing the situation. \$\endgroup\$
    – Pikalek
    Commented Feb 28, 2019 at 14:45
0
\$\begingroup\$

It looks like a simple UI. I suppose you need to find right Canvas in the Unity3d Editor window and add OnClickEvent to these elements (cross and settings icons). If cross is containing button component you will simply need to add OnClickEvent that will escape VR mode.

\$\endgroup\$
7
  • \$\begingroup\$ this canvas generated by Unity. How can I have access to it? \$\endgroup\$ Commented Mar 1, 2018 at 13:11
  • \$\begingroup\$ You need to find this Canvas in Unity3d Hierarchy window. If you see these elements in Editor window mode (Scene) just click on them and they will be selected in hierarchy window. \$\endgroup\$
    – Bogdan
    Commented Mar 1, 2018 at 13:44
  • \$\begingroup\$ I can't view it in Unity3d Hierarchy window. It is generated by Unity automatically on mobile device. What I need is some access to Unity automatically generated UI(VR UI, in this case). \$\endgroup\$ Commented Mar 1, 2018 at 13:54
  • \$\begingroup\$ @GuardFromUA it's probably an old gui system. You should find the code that displays those. I'm not familiar with old system but as far as my experience goes it's created via code. \$\endgroup\$ Commented Mar 1, 2018 at 14:03
  • \$\begingroup\$ @CandidMoon I searched and can't find it... \$\endgroup\$ Commented Mar 1, 2018 at 14:07
0
\$\begingroup\$

Here i am writing my solution

using UnityEngine;
using Google.XR.Cardboard;
using UnityEngine.XR.Management;
using System.Threading.Tasks;
public class UISettingsVR : MonoBehaviour
{
void Start()
{
}
/// <summary>
/// Gets a value indicating whether the VR mode is enabled.
/// </summary>
private bool _isVrModeEnabled
{
    get
    {
        return 
        XRGeneralSettings.Instance.Manager.isInitializationComplete;
    }
}


/// <summary>
/// Update is called once per frame.
/// </summary>
public void Update()
{

    if (XRGeneralSettings.Instance == null ||
        XRGeneralSettings.Instance.Manager == null)
        return;

    if (_isVrModeEnabled)
    {
        if (Api.IsCloseButtonPressed)
        {
            ActivateTwoD();
       //Do YOUR STUFF

            
        }

        if (Api.IsGearButtonPressed)
        {
            Api.ScanDeviceParams();
        }

        Api.UpdateScreenParams();
    }
}

public void ActivateVR() 
{
}

public  void ActivateTwoD()
{
}
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .