简体   繁体   中英

Unity Google Cardboard display issue on iOS

I've never encountered an issue like this before and everything I've tried to fix it has achieved nothing.

We have an app that uses Unity's built in Google Cardboard support that we have available on Android and iOS. The issue has never appeared on Android before, and also doesn't appear in a different project we have created using the same version of Unity (2018.1.1).

It appears the somehow when configuring the separate viewports for each eye it seems to get confused. The aspect ratio has been squished vertically and is stretching the displayed image. On top of this, the left and right eye appear to be facing in a cross eyed manor, where they should be facing more-or-less in the same direction. Here is an image representing the issue, with a line drawn around the current display area for each eye: iOS cardboard display

This picture is of an iPhone 6, however this has been replicated on multiple devices including iPhone 8, iPhone X, and a few others that I cannot recall. Like I mentioned previously this has never happened on Android and also does not appear on iOS in a similarly setup project.

I have a suspicion that it has something to do with the way my Unity scenes are setup so I'll give a brief description of how things work at the moment.

Scene 1 - Menu scene This is an entirely UI based scene (like most menus) and is setup in Portrait. It has a main camera that remains in standard mode (non-VR).

Scene 2 - Experience scene This scene switches into Landscape view using code Screen.orientation = ScreenOrientation.Landscape . It has one camera in the scene that is initially in standard mode (non-VR) but can be toggled into VR using a button with this code:

public void SetStereoViewState(bool isActive) {
    XRSettings.enabled = isActive;

    #if !UNITY_EDITOR

    // if device is a tablet (> 7" screen) always disable cardboard switch
    // otherwise display only when cardboard mode is inactive
    overlayCanvas.gameObject.SetActive(ScreenUtils.IsTabletDevice ? false : !isActive);

    // needed to fix the aspect ratio when switching back to mono mode
    vrCamera.ResetAspect();

    #endif

    Debug.Log("XRManager::SetStereoViewState | Enabling VR: " + isActive);
}

In a previous version of this app (running Unity 2017.2.0p2) this was never an issue, and is not an issue in a separate project also created in 2018.1.1.

What I've Tried So Far

  • camera.ResetAspect() - This was here to fix aspect issues when switching for VR to non-VR. I have enabled and disabled this when switching for every which way VR -> non-VR, non-VR -> VR etc. I have also delayed this until the next frame but without any change to the results
  • Enabling 'Cardboard' mode in the Landscape scene - The way I have always set my scene up in the past is to XRSettings.LoadDeviceByName({device_name}) at launch, in this case XRSettings.LoadDeviceByName("cardboard") but not enabling it with XRDevice.enabled = true until it is actually needed. | VR XRDevice.enabled = true - Non-VR XRDevice.enabled = false

Camera Setup I don't think it's relevant since VR works perfectly fine on Android, but here is my somewhat default camera is setup: Unity camera setup

I have considered setting up multiple cameras (left and right eye) but I can't see how this would make a difference as the aspect ratio is one of the issues. If anyone has experienced a similar issue and has a fix, or has any advice in how to approach the situation in a different way that would be awesome.

NOTE: Currently we are using Unity 2018.1.1 but I have also tried up to the most recent (at the time) 2018.1.5. A downgrade to 2017.xx is not really possibly due to HttpWebRequests and Apple's somewhat frustrating IPv6 requirements which are broken until Unity 2018.xx

FIXED

The issue is when loading 'cardboard' mode while in Portrait. Here is the code that I run at app launch to solve the issue:

private IEnumerator SetupCardboard() {
    Screen.orientation = ScreenOrientation.Landscape;
    XRSettings.LoadDeviceByName("cardboard");
    yield return null;
    Screen.orientation = ScreenOrientation.Portrait;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM