123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using UnityEngine;
- using UnityEngine.Rendering;
- using UnityEngine.VR;
- public class OVRManager : MonoBehaviour
- {
- public static OVRManager instance { get; private set; }
- public static OVRDisplay display { get; private set; }
- public static OVRTracker tracker { get; private set; }
- public static OVRBoundary boundary { get; private set; }
- public static OVRProfile profile
- {
- get
- {
- if (OVRManager._profile == null)
- {
- OVRManager._profile = new OVRProfile();
- }
- return OVRManager._profile;
- }
- }
- private bool paused
- {
- get
- {
- return this._isPaused;
- }
- set
- {
- if (value == this._isPaused)
- {
- return;
- }
- this._isPaused = value;
- }
- }
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public static event Action HMDAcquired;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public static event Action HMDLost;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public static event Action HMDMounted;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public static event Action HMDUnmounted;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public static event Action VrFocusAcquired;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public static event Action VrFocusLost;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public static event Action AudioOutChanged;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public static event Action AudioInChanged;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public static event Action TrackingAcquired;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public static event Action TrackingLost;
- [Obsolete]
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public static event Action HSWDismissed;
- public static bool isHmdPresent
- {
- get
- {
- if (!OVRManager._isHmdPresentCached)
- {
- OVRManager._isHmdPresentCached = true;
- OVRManager._isHmdPresent = OVRPlugin.hmdPresent;
- }
- return OVRManager._isHmdPresent;
- }
- private set
- {
- OVRManager._isHmdPresentCached = true;
- OVRManager._isHmdPresent = value;
- }
- }
- public static string audioOutId
- {
- get
- {
- return OVRPlugin.audioOutId;
- }
- }
- public static string audioInId
- {
- get
- {
- return OVRPlugin.audioInId;
- }
- }
- public static bool hasVrFocus
- {
- get
- {
- if (!OVRManager._hasVrFocusCached)
- {
- OVRManager._hasVrFocusCached = true;
- OVRManager._hasVrFocus = OVRPlugin.hasVrFocus;
- }
- return OVRManager._hasVrFocus;
- }
- private set
- {
- OVRManager._hasVrFocusCached = true;
- OVRManager._hasVrFocus = value;
- }
- }
- [Obsolete]
- public static bool isHSWDisplayed
- {
- get
- {
- return false;
- }
- }
- [Obsolete]
- public static void DismissHSWDisplay()
- {
- }
- public bool chromatic
- {
- get
- {
- return OVRManager.isHmdPresent && OVRPlugin.chromatic;
- }
- set
- {
- if (!OVRManager.isHmdPresent)
- {
- return;
- }
- OVRPlugin.chromatic = value;
- }
- }
- public bool monoscopic
- {
- get
- {
- return !OVRManager.isHmdPresent || OVRPlugin.monoscopic;
- }
- set
- {
- if (!OVRManager.isHmdPresent)
- {
- return;
- }
- OVRPlugin.monoscopic = value;
- }
- }
- public int vsyncCount
- {
- get
- {
- if (!OVRManager.isHmdPresent)
- {
- return 1;
- }
- return OVRPlugin.vsyncCount;
- }
- set
- {
- if (!OVRManager.isHmdPresent)
- {
- return;
- }
- OVRPlugin.vsyncCount = value;
- }
- }
- public static float batteryLevel
- {
- get
- {
- if (!OVRManager.isHmdPresent)
- {
- return 1f;
- }
- return OVRPlugin.batteryLevel;
- }
- }
- public static float batteryTemperature
- {
- get
- {
- if (!OVRManager.isHmdPresent)
- {
- return 0f;
- }
- return OVRPlugin.batteryTemperature;
- }
- }
- public static int batteryStatus
- {
- get
- {
- if (!OVRManager.isHmdPresent)
- {
- return -1;
- }
- return (int)OVRPlugin.batteryStatus;
- }
- }
- public static float volumeLevel
- {
- get
- {
- if (!OVRManager.isHmdPresent)
- {
- return 0f;
- }
- return OVRPlugin.systemVolume;
- }
- }
- public static int cpuLevel
- {
- get
- {
- if (!OVRManager.isHmdPresent)
- {
- return 2;
- }
- return OVRPlugin.cpuLevel;
- }
- set
- {
- if (!OVRManager.isHmdPresent)
- {
- return;
- }
- OVRPlugin.cpuLevel = value;
- }
- }
- public static int gpuLevel
- {
- get
- {
- if (!OVRManager.isHmdPresent)
- {
- return 2;
- }
- return OVRPlugin.gpuLevel;
- }
- set
- {
- if (!OVRManager.isHmdPresent)
- {
- return;
- }
- OVRPlugin.gpuLevel = value;
- }
- }
- public static bool isPowerSavingActive
- {
- get
- {
- return OVRManager.isHmdPresent && OVRPlugin.powerSaving;
- }
- }
- public OVRManager.TrackingOrigin trackingOriginType
- {
- get
- {
- if (!OVRManager.isHmdPresent)
- {
- return this._trackingOriginType;
- }
- return (OVRManager.TrackingOrigin)OVRPlugin.GetTrackingOriginType();
- }
- set
- {
- if (!OVRManager.isHmdPresent)
- {
- return;
- }
- if (OVRPlugin.SetTrackingOriginType((OVRPlugin.TrackingOrigin)value))
- {
- this._trackingOriginType = value;
- }
- }
- }
- public bool isSupportedPlatform { get; private set; }
- public bool isUserPresent
- {
- get
- {
- if (!OVRManager._isUserPresentCached)
- {
- OVRManager._isUserPresentCached = true;
- OVRManager._isUserPresent = OVRPlugin.userPresent;
- }
- return OVRManager._isUserPresent;
- }
- private set
- {
- OVRManager._isUserPresentCached = true;
- OVRManager._isUserPresent = value;
- }
- }
- private void Awake()
- {
- if (OVRManager.instance != null)
- {
- base.enabled = false;
- UnityEngine.Object.DestroyImmediate(this);
- return;
- }
- OVRManager.instance = this;
- UnityEngine.Debug.Log(string.Concat(new object[]
- {
- "Unity v",
- Application.unityVersion,
- ", Oculus Utilities v",
- OVRPlugin.wrapperVersion,
- ", OVRPlugin v",
- OVRPlugin.version,
- ", SDK v",
- OVRPlugin.nativeSDKVersion,
- "."
- }));
- if (SystemInfo.graphicsDeviceType != GraphicsDeviceType.Direct3D11)
- {
- UnityEngine.Debug.LogWarning("VR rendering requires Direct3D11. Your graphics device: " + SystemInfo.graphicsDeviceType);
- }
- RuntimePlatform platform = Application.platform;
- this.isSupportedPlatform |= (platform == RuntimePlatform.Android);
- this.isSupportedPlatform |= (platform == RuntimePlatform.OSXEditor);
- this.isSupportedPlatform |= (platform == RuntimePlatform.OSXPlayer);
- this.isSupportedPlatform |= (platform == RuntimePlatform.WindowsEditor);
- this.isSupportedPlatform |= (platform == RuntimePlatform.WindowsPlayer);
- if (!this.isSupportedPlatform)
- {
- UnityEngine.Debug.LogWarning("This platform is unsupported");
- return;
- }
- if (OVRManager.display == null)
- {
- OVRManager.display = new OVRDisplay();
- }
- if (OVRManager.tracker == null)
- {
- OVRManager.tracker = new OVRTracker();
- }
- if (OVRManager.boundary == null)
- {
- OVRManager.boundary = new OVRBoundary();
- }
- if (this.resetTrackerOnLoad)
- {
- OVRManager.display.RecenterPose();
- }
- OVRPlugin.occlusionMesh = false;
- OVRPlugin.ignoreVrFocus = OVRManager.runInBackground;
- }
- private void Update()
- {
- this.paused = !OVRPlugin.hasVrFocus;
- if (OVRPlugin.shouldQuit)
- {
- Application.Quit();
- }
- if (OVRPlugin.shouldRecenter)
- {
- OVRManager.display.RecenterPose();
- }
- if (this.trackingOriginType != this._trackingOriginType)
- {
- this.trackingOriginType = this._trackingOriginType;
- }
- OVRManager.tracker.isEnabled = this.usePositionTracking;
- OVRPlugin.useIPDInPositionTracking = this.useIPDInPositionTracking;
- OVRManager.isHmdPresent = OVRPlugin.hmdPresent;
- if (this.useRecommendedMSAALevel && QualitySettings.antiAliasing != OVRManager.display.recommendedMSAALevel)
- {
- UnityEngine.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)
- {
- UnityEngine.Debug.LogError("Caught Exception: " + arg);
- }
- }
- if (!OVRManager._wasHmdPresent && OVRManager.isHmdPresent)
- {
- try
- {
- if (OVRManager.HMDAcquired != null)
- {
- OVRManager.HMDAcquired();
- }
- }
- catch (Exception arg2)
- {
- UnityEngine.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)
- {
- UnityEngine.Debug.LogError("Caught Exception: " + arg3);
- }
- }
- if (!OVRManager._wasUserPresent && this.isUserPresent)
- {
- try
- {
- if (OVRManager.HMDMounted != null)
- {
- OVRManager.HMDMounted();
- }
- }
- catch (Exception arg4)
- {
- UnityEngine.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)
- {
- UnityEngine.Debug.LogError("Caught Exception: " + arg5);
- }
- }
- if (!OVRManager._hadVrFocus && OVRManager.hasVrFocus)
- {
- try
- {
- if (OVRManager.VrFocusAcquired != null)
- {
- OVRManager.VrFocusAcquired();
- }
- }
- catch (Exception arg6)
- {
- UnityEngine.Debug.LogError("Caught Exception: " + arg6);
- }
- }
- OVRManager._hadVrFocus = OVRManager.hasVrFocus;
- if (this.enableAdaptiveResolution)
- {
- if (VRSettings.renderScale < this.maxRenderScale)
- {
- VRSettings.renderScale = this.maxRenderScale;
- }
- else
- {
- this.maxRenderScale = Mathf.Max(this.maxRenderScale, VRSettings.renderScale);
- }
- 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 arg7)
- {
- UnityEngine.Debug.LogError("Caught Exception: " + arg7);
- }
- 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 arg8)
- {
- UnityEngine.Debug.LogError("Caught Exception: " + arg8);
- }
- OVRManager.prevAudioInId = audioInId;
- }
- if (OVRManager.wasPositionTracked && !OVRManager.tracker.isPositionTracked)
- {
- try
- {
- if (OVRManager.TrackingLost != null)
- {
- OVRManager.TrackingLost();
- }
- }
- catch (Exception arg9)
- {
- UnityEngine.Debug.LogError("Caught Exception: " + arg9);
- }
- }
- if (!OVRManager.wasPositionTracked && OVRManager.tracker.isPositionTracked)
- {
- try
- {
- if (OVRManager.TrackingAcquired != null)
- {
- OVRManager.TrackingAcquired();
- }
- }
- catch (Exception arg10)
- {
- UnityEngine.Debug.LogError("Caught Exception: " + arg10);
- }
- }
- OVRManager.wasPositionTracked = OVRManager.tracker.isPositionTracked;
- OVRManager.display.Update();
- OVRInput.Update();
- }
- private void LateUpdate()
- {
- OVRHaptics.Process();
- }
- private void FixedUpdate()
- {
- OVRInput.FixedUpdate();
- }
- public void ReturnToLauncher()
- {
- OVRManager.PlatformUIConfirmQuit();
- }
- public static void PlatformUIConfirmQuit()
- {
- if (!OVRManager.isHmdPresent)
- {
- return;
- }
- OVRPlugin.ShowUI(OVRPlugin.PlatformUI.ConfirmQuit);
- }
- public static void PlatformUIGlobalMenu()
- {
- if (!OVRManager.isHmdPresent)
- {
- return;
- }
- OVRPlugin.ShowUI(OVRPlugin.PlatformUI.GlobalMenu);
- }
- private static OVRProfile _profile;
- private bool _isPaused;
- private IEnumerable<Camera> disabledCameras;
- private float prevTimeScale;
- private static bool _isHmdPresentCached = false;
- private static bool _isHmdPresent = false;
- private static bool _wasHmdPresent = false;
- private static bool _hasVrFocusCached = false;
- private static bool _hasVrFocus = false;
- private static bool _hadVrFocus = false;
- public bool queueAhead = true;
- public bool useRecommendedMSAALevel;
- public bool enableAdaptiveResolution;
- [Range(0.5f, 2f)]
- public float maxRenderScale = 1f;
- [Range(0.5f, 2f)]
- public float minRenderScale = 0.7f;
- [SerializeField]
- private OVRManager.TrackingOrigin _trackingOriginType;
- public bool usePositionTracking = true;
- public bool useIPDInPositionTracking = true;
- public bool resetTrackerOnLoad;
- private static bool _isUserPresentCached = false;
- private static bool _isUserPresent = false;
- private static bool _wasUserPresent = false;
- private static bool prevAudioOutIdIsCached = false;
- private static bool prevAudioInIdIsCached = false;
- private static string prevAudioOutId = string.Empty;
- private static string prevAudioInId = string.Empty;
- private static bool wasPositionTracked = false;
- [SerializeField]
- [HideInInspector]
- internal static bool runInBackground = false;
- public enum TrackingOrigin
- {
- EyeLevel,
- FloorLevel
- }
- }
|