/// <summary> /// Recenters the head pose. /// </summary> public void RecenterPose() { VR.InputTracking.Recenter(); if (RecenteredPose != null) { RecenteredPose(); } #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN OVRMixedReality.RecenterPose(); #endif }
/// <summary> /// Recenters the head pose. /// </summary> public void RecenterPose() { #if UNITY_2017_2_OR_NEWER UnityEngine.XR.InputTracking.Recenter(); #else VR.InputTracking.Recenter(); #endif if (RecenteredPose != null) { RecenteredPose(); } #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN OVRMixedReality.RecenterPose(); #endif }
/// <summary> /// Recenters the head pose. /// </summary> public void RecenterPose() { InputTracking.Recenter(); // The current poses are cached for the current frame and won't be updated immediately // after UnityEngine.VR.InputTracking.Recenter(). So we need to wait until next frame // to trigger the RecenteredPose delegate. The application could expect the correct pose // when the RecenteredPose delegate get called. recenterRequested = true; recenterRequestedFrameCount = Time.frameCount; #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN OVRMixedReality.RecenterPose(); #endif }
/// <summary> /// Recenters the head pose. /// </summary> public void RecenterPose() { #if USING_XR_SDK XRInputSubsystem currentInputSubsystem = OVRManager.GetCurrentInputSubsystem(); if (currentInputSubsystem != null) { currentInputSubsystem.TryRecenter(); } #elif !REQUIRES_XR_SDK InputTracking.Recenter(); #endif // The current poses are cached for the current frame and won't be updated immediately // after UnityEngine.VR.InputTracking.Recenter(). So we need to wait until next frame // to trigger the RecenteredPose delegate. The application could expect the correct pose // when the RecenteredPose delegate get called. recenterRequested = true; recenterRequestedFrameCount = Time.frameCount; #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN OVRMixedReality.RecenterPose(); #endif }
private void Update() { #if UNITY_EDITOR if (_scriptsReloaded) { _scriptsReloaded = false; instance = this; Initialize(); } #endif if (OVRPlugin.shouldQuit) { Application.Quit(); } if (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 (_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; // Changing effective rendering resolution dynamically according performance #if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN) && UNITY_5_4_OR_NEWER if (enableAdaptiveResolution) { 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; } #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 (enableMixedReality || prevEnableMixedReality) { Camera mainCamera = FindMainCamera(); if (Camera.main != null) { if (enableMixedReality) { OVRMixedReality.directCompositionChromaToleranceA = greenScreenColorToleranceA; OVRMixedReality.directCompositionChromaToleranceB = greenScreenColorToleranceB; OVRMixedReality.directCompositionChromaShadows = greenScreenColorShadows; OVRMixedReality.directCompositionChromaAlphaCutoff = greenScreenColorAlphaCutoff; OVRMixedReality.Update(this.gameObject, mainCamera, useDirectComposition); } if (prevEnableMixedReality && !enableMixedReality) { OVRMixedReality.Cleanup(); } prevEnableMixedReality = enableMixedReality; } else { Debug.LogWarning("Main Camera is not set, Mixed Reality disabled"); } } }
private void OnDisable() { OVRMixedReality.Cleanup(); }
private void Update() { if (OVRPlugin.shouldQuit) { Application.Quit(); } if (this.AllowRecenter && OVRPlugin.shouldRecenter) { OVRManager.display.RecenterPose(); } if (this.trackingOriginType != this._trackingOriginType) { this.trackingOriginType = this._trackingOriginType; } OVRManager.tracker.isEnabled = this.usePositionTracking; OVRPlugin.rotation = this.useRotationTracking; OVRPlugin.useIPDInPositionTracking = this.useIPDInPositionTracking; OVRManager.isHmdPresent = OVRPlugin.hmdPresent; if (this.useRecommendedMSAALevel && QualitySettings.antiAliasing != OVRManager.display.recommendedMSAALevel) { Debug.Log(string.Concat(new object[] { "The current MSAA level is ", QualitySettings.antiAliasing, ", but the recommended MSAA level is ", OVRManager.display.recommendedMSAALevel, ". Switching to the recommended level." })); QualitySettings.antiAliasing = OVRManager.display.recommendedMSAALevel; } if (OVRManager._wasHmdPresent && !OVRManager.isHmdPresent) { try { if (OVRManager.HMDLost != null) { OVRManager.HMDLost(); } } catch (Exception arg) { Debug.LogError("Caught Exception: " + arg); } } if (!OVRManager._wasHmdPresent && OVRManager.isHmdPresent) { try { if (OVRManager.HMDAcquired != null) { OVRManager.HMDAcquired(); } } catch (Exception arg2) { Debug.LogError("Caught Exception: " + arg2); } } OVRManager._wasHmdPresent = OVRManager.isHmdPresent; this.isUserPresent = OVRPlugin.userPresent; if (OVRManager._wasUserPresent && !this.isUserPresent) { try { if (OVRManager.HMDUnmounted != null) { OVRManager.HMDUnmounted(); } } catch (Exception arg3) { Debug.LogError("Caught Exception: " + arg3); } } if (!OVRManager._wasUserPresent && this.isUserPresent) { try { if (OVRManager.HMDMounted != null) { OVRManager.HMDMounted(); } } catch (Exception arg4) { Debug.LogError("Caught Exception: " + arg4); } } OVRManager._wasUserPresent = this.isUserPresent; OVRManager.hasVrFocus = OVRPlugin.hasVrFocus; if (OVRManager._hadVrFocus && !OVRManager.hasVrFocus) { try { if (OVRManager.VrFocusLost != null) { OVRManager.VrFocusLost(); } } catch (Exception arg5) { Debug.LogError("Caught Exception: " + arg5); } } if (!OVRManager._hadVrFocus && OVRManager.hasVrFocus) { try { if (OVRManager.VrFocusAcquired != null) { OVRManager.VrFocusAcquired(); } } catch (Exception arg6) { Debug.LogError("Caught Exception: " + arg6); } } OVRManager._hadVrFocus = OVRManager.hasVrFocus; bool hasInputFocus = OVRPlugin.hasInputFocus; if (OVRManager._hadInputFocus && !hasInputFocus) { try { if (OVRManager.InputFocusLost != null) { OVRManager.InputFocusLost(); } } catch (Exception arg7) { Debug.LogError("Caught Exception: " + arg7); } } if (!OVRManager._hadInputFocus && hasInputFocus) { try { if (OVRManager.InputFocusAcquired != null) { OVRManager.InputFocusAcquired(); } } catch (Exception arg8) { Debug.LogError("Caught Exception: " + arg8); } } OVRManager._hadInputFocus = hasInputFocus; if (this.enableAdaptiveResolution) { if (VRSettings.renderScale < this.maxRenderScale) { VRSettings.renderScale = this.maxRenderScale; } else { this.maxRenderScale = Mathf.Max(this.maxRenderScale, VRSettings.renderScale); } this.minRenderScale = Mathf.Min(this.minRenderScale, this.maxRenderScale); float min = this.minRenderScale / VRSettings.renderScale; float num = OVRPlugin.GetEyeRecommendedResolutionScale() / VRSettings.renderScale; num = Mathf.Clamp(num, min, 1f); VRSettings.renderViewportScale = num; } string audioOutId = OVRPlugin.audioOutId; if (!OVRManager.prevAudioOutIdIsCached) { OVRManager.prevAudioOutId = audioOutId; OVRManager.prevAudioOutIdIsCached = true; } else if (audioOutId != OVRManager.prevAudioOutId) { try { if (OVRManager.AudioOutChanged != null) { OVRManager.AudioOutChanged(); } } catch (Exception arg9) { Debug.LogError("Caught Exception: " + arg9); } OVRManager.prevAudioOutId = audioOutId; } string audioInId = OVRPlugin.audioInId; if (!OVRManager.prevAudioInIdIsCached) { OVRManager.prevAudioInId = audioInId; OVRManager.prevAudioInIdIsCached = true; } else if (audioInId != OVRManager.prevAudioInId) { try { if (OVRManager.AudioInChanged != null) { OVRManager.AudioInChanged(); } } catch (Exception arg10) { Debug.LogError("Caught Exception: " + arg10); } OVRManager.prevAudioInId = audioInId; } if (OVRManager.wasPositionTracked && !OVRManager.tracker.isPositionTracked) { try { if (OVRManager.TrackingLost != null) { OVRManager.TrackingLost(); } } catch (Exception arg11) { Debug.LogError("Caught Exception: " + arg11); } } if (!OVRManager.wasPositionTracked && OVRManager.tracker.isPositionTracked) { try { if (OVRManager.TrackingAcquired != null) { OVRManager.TrackingAcquired(); } } catch (Exception arg12) { Debug.LogError("Caught Exception: " + arg12); } } OVRManager.wasPositionTracked = OVRManager.tracker.isPositionTracked; OVRManager.display.Update(); OVRInput.Update(); if (this.enableMixedReality || OVRManager.prevEnableMixedReality) { Camera mainCamera = this.FindMainCamera(); if (Camera.main != null) { this.suppressDisableMixedRealityBecauseOfNoMainCameraWarning = false; if (this.enableMixedReality) { OVRMixedReality.Update(base.gameObject, mainCamera, this.compositionMethod, this.useDynamicLighting, this.capturingCameraDevice, this.depthQuality); } if (OVRManager.prevEnableMixedReality && !this.enableMixedReality) { OVRMixedReality.Cleanup(); } OVRManager.prevEnableMixedReality = this.enableMixedReality; } else if (!this.suppressDisableMixedRealityBecauseOfNoMainCameraWarning) { Debug.LogWarning("Main Camera is not set, Mixed Reality disabled"); this.suppressDisableMixedRealityBecauseOfNoMainCameraWarning = true; } } }
private void OnDisable() { #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN OVRMixedReality.Cleanup(); #endif }
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 }