in Networked Physics/Assets/Oculus/VR/Scripts/OVRManager.cs [1031:1349]
private void Update()
{
#if UNITY_EDITOR
if (_scriptsReloaded)
{
_scriptsReloaded = false;
instance = this;
Initialize();
}
#endif
if (OVRPlugin.shouldQuit)
Application.Quit();
if (AllowRecenter && OVRPlugin.shouldRecenter)
{
OVRManager.display.RecenterPose();
}
if (trackingOriginType != _trackingOriginType)
trackingOriginType = _trackingOriginType;
tracker.isEnabled = usePositionTracking;
OVRPlugin.rotation = useRotationTracking;
OVRPlugin.useIPDInPositionTracking = useIPDInPositionTracking;
// Dispatch HMD events.
isHmdPresent = OVRPlugin.hmdPresent;
if (useRecommendedMSAALevel && QualitySettings.antiAliasing != display.recommendedMSAALevel)
{
Debug.Log("The current MSAA level is " + QualitySettings.antiAliasing +
", but the recommended MSAA level is " + display.recommendedMSAALevel +
". Switching to the recommended level.");
QualitySettings.antiAliasing = display.recommendedMSAALevel;
}
if (monoscopic != _monoscopic)
{
monoscopic = _monoscopic;
}
if (_wasHmdPresent && !isHmdPresent)
{
try
{
if (HMDLost != null)
HMDLost();
}
catch (Exception e)
{
Debug.LogError("Caught Exception: " + e);
}
}
if (!_wasHmdPresent && isHmdPresent)
{
try
{
if (HMDAcquired != null)
HMDAcquired();
}
catch (Exception e)
{
Debug.LogError("Caught Exception: " + e);
}
}
_wasHmdPresent = isHmdPresent;
// Dispatch HMD mounted events.
isUserPresent = OVRPlugin.userPresent;
if (_wasUserPresent && !isUserPresent)
{
try
{
if (HMDUnmounted != null)
HMDUnmounted();
}
catch (Exception e)
{
Debug.LogError("Caught Exception: " + e);
}
}
if (!_wasUserPresent && isUserPresent)
{
try
{
if (HMDMounted != null)
HMDMounted();
}
catch (Exception e)
{
Debug.LogError("Caught Exception: " + e);
}
}
_wasUserPresent = isUserPresent;
// Dispatch VR Focus events.
hasVrFocus = OVRPlugin.hasVrFocus;
if (_hadVrFocus && !hasVrFocus)
{
try
{
if (VrFocusLost != null)
VrFocusLost();
}
catch (Exception e)
{
Debug.LogError("Caught Exception: " + e);
}
}
if (!_hadVrFocus && hasVrFocus)
{
try
{
if (VrFocusAcquired != null)
VrFocusAcquired();
}
catch (Exception e)
{
Debug.LogError("Caught Exception: " + e);
}
}
_hadVrFocus = hasVrFocus;
// Dispatch VR Input events.
bool hasInputFocus = OVRPlugin.hasInputFocus;
if (_hadInputFocus && !hasInputFocus)
{
try
{
if (InputFocusLost != null)
InputFocusLost();
}
catch (Exception e)
{
Debug.LogError("Caught Exception: " + e);
}
}
if (!_hadInputFocus && hasInputFocus)
{
try
{
if (InputFocusAcquired != null)
InputFocusAcquired();
}
catch (Exception e)
{
Debug.LogError("Caught Exception: " + e);
}
}
_hadInputFocus = hasInputFocus;
// Changing effective rendering resolution dynamically according performance
#if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN)
if (enableAdaptiveResolution)
{
#if UNITY_2017_2_OR_NEWER
if (UnityEngine.XR.XRSettings.eyeTextureResolutionScale < maxRenderScale)
{
// Allocate renderScale to max to avoid re-allocation
UnityEngine.XR.XRSettings.eyeTextureResolutionScale = maxRenderScale;
}
else
{
// Adjusting maxRenderScale in case app started with a larger renderScale value
maxRenderScale = Mathf.Max(maxRenderScale, UnityEngine.XR.XRSettings.eyeTextureResolutionScale);
}
minRenderScale = Mathf.Min(minRenderScale, maxRenderScale);
float minViewportScale = minRenderScale / UnityEngine.XR.XRSettings.eyeTextureResolutionScale;
float recommendedViewportScale = OVRPlugin.GetEyeRecommendedResolutionScale() / UnityEngine.XR.XRSettings.eyeTextureResolutionScale;
recommendedViewportScale = Mathf.Clamp(recommendedViewportScale, minViewportScale, 1.0f);
UnityEngine.XR.XRSettings.renderViewportScale = recommendedViewportScale;
#else
if (UnityEngine.VR.VRSettings.renderScale < maxRenderScale)
{
// Allocate renderScale to max to avoid re-allocation
UnityEngine.VR.VRSettings.renderScale = maxRenderScale;
}
else
{
// Adjusting maxRenderScale in case app started with a larger renderScale value
maxRenderScale = Mathf.Max(maxRenderScale, UnityEngine.VR.VRSettings.renderScale);
}
minRenderScale = Mathf.Min(minRenderScale, maxRenderScale);
float minViewportScale = minRenderScale / UnityEngine.VR.VRSettings.renderScale;
float recommendedViewportScale = OVRPlugin.GetEyeRecommendedResolutionScale() / UnityEngine.VR.VRSettings.renderScale;
recommendedViewportScale = Mathf.Clamp(recommendedViewportScale, minViewportScale, 1.0f);
UnityEngine.VR.VRSettings.renderViewportScale = recommendedViewportScale;
#endif
}
#endif
// Dispatch Audio Device events.
string audioOutId = OVRPlugin.audioOutId;
if (!prevAudioOutIdIsCached)
{
prevAudioOutId = audioOutId;
prevAudioOutIdIsCached = true;
}
else if (audioOutId != prevAudioOutId)
{
try
{
if (AudioOutChanged != null)
AudioOutChanged();
}
catch (Exception e)
{
Debug.LogError("Caught Exception: " + e);
}
prevAudioOutId = audioOutId;
}
string audioInId = OVRPlugin.audioInId;
if (!prevAudioInIdIsCached)
{
prevAudioInId = audioInId;
prevAudioInIdIsCached = true;
}
else if (audioInId != prevAudioInId)
{
try
{
if (AudioInChanged != null)
AudioInChanged();
}
catch (Exception e)
{
Debug.LogError("Caught Exception: " + e);
}
prevAudioInId = audioInId;
}
// Dispatch tracking events.
if (wasPositionTracked && !tracker.isPositionTracked)
{
try
{
if (TrackingLost != null)
TrackingLost();
}
catch (Exception e)
{
Debug.LogError("Caught Exception: " + e);
}
}
if (!wasPositionTracked && tracker.isPositionTracked)
{
try
{
if (TrackingAcquired != null)
TrackingAcquired();
}
catch (Exception e)
{
Debug.LogError("Caught Exception: " + e);
}
}
wasPositionTracked = tracker.isPositionTracked;
display.Update();
OVRInput.Update();
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if (enableMixedReality || prevEnableMixedReality)
{
Camera mainCamera = FindMainCamera();
if (Camera.main != null)
{
suppressDisableMixedRealityBecauseOfNoMainCameraWarning = false;
if (enableMixedReality)
{
OVRMixedReality.Update(this.gameObject, mainCamera, compositionMethod, useDynamicLighting, capturingCameraDevice, depthQuality);
}
if (prevEnableMixedReality && !enableMixedReality)
{
OVRMixedReality.Cleanup();
}
prevEnableMixedReality = enableMixedReality;
}
else
{
if (!suppressDisableMixedRealityBecauseOfNoMainCameraWarning)
{
Debug.LogWarning("Main Camera is not set, Mixed Reality disabled");
suppressDisableMixedRealityBecauseOfNoMainCameraWarning = true;
}
}
}
#endif
}