user21174554
user21174554

Reputation:

Google cardboard VR closing the whole application after pressing switching VR off button

Hi there Im using Unity 2022 and latest version of Google cardboard VR, Im trying to switch between VR and normal mode but when I press the close VR button after switching the view back to normal it closes the whole app, I searched in the scripts related to the VRController.cs and the functions it calls but I cant find anything regarding Application.Quit();

How can I switch the VR off without closing the application ? This is the script :

void Start()
{
    _mainCamera = Camera.main;
    Screen.sleepTimeout = SleepTimeout.NeverSleep;
    Screen.brightness = 1.0f;
 
}

void Update()
{
    
    if(_isVrModeEnabled && Api.IsCloseButtonPressed)
    {
        ExitVR();
    }
}
public void ToggleVR()
{
    if (_isVrModeEnabled)
    {
        ExitVR();
    }
    else
    {
        EnterVR();
    }
    // if (Api.HasNewDeviceParams())
    // {
    //     Api.ReloadDeviceParams();
    // }
}

private void EnterVR()
{
    StartCoroutine(StartXR());
    if (Api.HasNewDeviceParams())
    {
        Api.ReloadDeviceParams();
    }
}

private void ExitVR()
{
    StopXR();
}

private void StopXR()
{
    Debug.Log("Stopping XR...");
    XRGeneralSettings.Instance.Manager.StopSubsystems();
    Debug.Log("XR stopped.");

    Debug.Log("Deinitializing XR...");
    XRGeneralSettings.Instance.Manager.DeinitializeLoader();
    Debug.Log("XR deinitialized.");

    _mainCamera.ResetAspect();
    _mainCamera.fieldOfView = _defaultFieldOfView;
}

// Start is called before the first frame update
private IEnumerator StartXR()
{
    Debug.Log("Initializing XR...");
    yield return XRGeneralSettings.Instance.Manager.InitializeLoader();

    if (XRGeneralSettings.Instance.Manager.activeLoader == null)
    {
        Debug.LogError("Initializing XR Failed.");
    }
    else
    {
        Debug.Log("XR initialized.");

        Debug.Log("Starting XR...");
        XRGeneralSettings.Instance.Manager.StartSubsystems();
        Debug.Log("XR started.");
    }
}

private bool _isVrModeEnabled
{
    get { return XRGeneralSettings.Instance.Manager.isInitializationComplete; }
}

Upvotes: 0

Views: 87

Answers (1)

D_Central
D_Central

Reputation: 32

Suggest you make a Development Build, to check for possible errors while running the app. And add some Debug.Log lines to see if the code you think is running, or not.

Upvotes: 1

Related Questions