} //END IsVRModeOn //----------------------------------// public static bool GetCurrentXRDevice( out XRModeHelper.XRDevices currentDevice ) //----------------------------------// { XRModeHelper.XRDevices device = default( XRModeHelper.XRDevices ); string deviceName = UnityEngine.XR.XRSettings.loadedDeviceName; if( string.IsNullOrEmpty( UnityEngine.XR.XRSettings.loadedDeviceName ) ) { deviceName = "none"; } foreach( XRModeHelper.XRDevices emn in Enum.GetValues( typeof(XRModeHelper.XRDevices) ) ) { if( EnumHelper.TryParseEnum<XRModeHelper.XRDevices>( deviceName, out device ) ) { currentDevice = device; return true; } } currentDevice = device; return false; } //END GetCurrentXRDevice
} //END _SetVRMode //----------------------------------// private IEnumerator LoadDevice( string newDevice, bool vrModeActive, bool useGazeInput, bool useMouseInput, bool useTouchInput ) //----------------------------------// { //If we're using a VR view, force the view into landscape left to prevent a camera FOV bug if( newDevice != "none" && Screen.orientation != ScreenOrientation.LandscapeLeft ) { Screen.orientation = ScreenOrientation.LandscapeLeft; yield return new WaitForSeconds(.1f); if( showDebug ) Debug.Log( "LoadDevice( split ), Set Screen.orientation to LandscapeLeft" ); } else { if( showDebug ) Debug.Log( "LoadDevice( " + newDevice + " ) else" ); } if( UnityEngine.XR.XRSettings.loadedDeviceName != newDevice ) { yield return null; UnityEngine.XR.XRSettings.LoadDeviceByName( newDevice ); if( showDebug ) Debug.Log( "XRMode.cs LoadDevice( " + newDevice + " ), VRSettings.enabled = " + vrModeActive ); } yield return null; if( newDevice == "none" ) { Screen.autorotateToLandscapeLeft = true; Screen.autorotateToLandscapeRight = true; Screen.autorotateToPortrait = true; Screen.autorotateToPortraitUpsideDown = true; Screen.orientation = ScreenOrientation.AutoRotation; yield return new WaitForSeconds( .1f ); if( showDebug ) Debug.Log( "LoadDevice( none ), Set Screen.orientation to Auto" ); } UnityEngine.XR.XRSettings.enabled = vrModeActive; //Set the currentHelper to the latest settings XRModeHelper.XRDevices deviceType = XRModeHelper.XRDevices.none; if( GetCurrentXRDevice( out deviceType ) ) { currentHelper = new XRModeHelper( Application.platform, deviceType, vrModeActive, useGazeInput, useMouseInput, useTouchInput ); } //Force cameras to deal with aspect ratio changes if( Camera.allCameras != null ) { foreach( Camera item in Camera.allCameras ) { item.ResetAspect(); } } SetDistortionBasedOnSettings(); } //END LoadDevice