diff --git a/.editorconfig b/.editorconfig index 7c511996a1..e497deceac 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,14 +3,12 @@ root = true -[*.{cs,py,json,cfg}] +[*.{json,cfg}] indent_style = space indent_size = 2 -[*.py] -indent_size = 4 - -[*.cs] +[*.{cs,py}] +indent_style = space indent_size = 4 # Microsoft .NET properties diff --git a/Assets/Editor/BuildTiltBrush.cs b/Assets/Editor/BuildTiltBrush.cs index ec851ee623..b000b54286 100644 --- a/Assets/Editor/BuildTiltBrush.cs +++ b/Assets/Editor/BuildTiltBrush.cs @@ -90,8 +90,8 @@ private static readonly List> kValidSdkTarget new KeyValuePair(SdkMode.SteamVR, BuildTarget.StandaloneLinux64), new KeyValuePair(SdkMode.SteamVR, BuildTarget.StandaloneOSX), #if OCULUS_SUPPORTED - new KeyValuePair(SdkMode.Oculus, BuildTarget.StandaloneWindows64), - new KeyValuePair(SdkMode.Oculus, BuildTarget.Android), + new KeyValuePair(SdkMode.Oculus, BuildTarget.StandaloneWindows64), + new KeyValuePair(SdkMode.Oculus, BuildTarget.Android), #endif // OCULUS_SUPPORTED new KeyValuePair(SdkMode.Gvr, BuildTarget.Android), }; @@ -156,7 +156,7 @@ public static SdkMode GuiSelectedSdk EditorPrefs.SetString(kMenuSdkPref, value.ToString()); Menu.SetChecked(kMenuSdkMonoscopic, false); #if OCULUS_SUPPORTED - Menu.SetChecked(kMenuSdkOculus, false); + Menu.SetChecked(kMenuSdkOculus, false); #endif // OCULUS_SUPPORTED Menu.SetChecked(kMenuSdkSteamVr, false); Menu.SetChecked(kMenuSdkGoogleVr, false); @@ -168,7 +168,7 @@ public static SdkMode GuiSelectedSdk break; case SdkMode.Oculus: #if OCULUS_SUPPORTED - Menu.SetChecked(kMenuSdkOculus, true); + Menu.SetChecked(kMenuSdkOculus, true); #endif // OCULUS_SUPPORTED break; case SdkMode.SteamVR: @@ -415,8 +415,8 @@ static void MenuItem_Sdk_Oculus() static bool MenuItem_Sdk_Oculus_Validate() { #if OCULUS_SUPPORTED - Menu.SetChecked(kMenuSdkOculus, GuiSelectedSdk == SdkMode.Oculus); - return true; + Menu.SetChecked(kMenuSdkOculus, GuiSelectedSdk == SdkMode.Oculus); + return true; #else return false; #endif @@ -707,11 +707,11 @@ static void CommandLine() #if OCULUS_SUPPORTED - // Call these once to create the files. Normally (i.e., in a GUI build), they're created with - // [UnityEditor.InitializeOnLoad], but in case they're missing, like in CI, make sure they're - // there! - OVRProjectConfig defaultOculusProjectConfig = OVRProjectConfig.GetProjectConfig(); - string useless_app_id = Assets.Oculus.VR.Editor.OVRPlatformToolSettings.AppID; + // Call these once to create the files. Normally (i.e., in a GUI build), they're created with + // [UnityEditor.InitializeOnLoad], but in case they're missing, like in CI, make sure they're + // there! + OVRProjectConfig defaultOculusProjectConfig = OVRProjectConfig.GetProjectConfig(); + string useless_app_id = Assets.Oculus.VR.Editor.OVRPlatformToolSettings.AppID; #endif { @@ -1527,19 +1527,19 @@ public static void OnPostProcessBuild(BuildTarget target, string path) // TODO: is it possible to embed loose files on iOS? looseFilesDest = null; #if UNITY_EDITOR_OSX && UNITY_IPHONE - string pbxPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; + string pbxPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; - PBXProject project = new PBXProject(); - project.ReadFromString(File.ReadAllText(pbxPath)); - string pbxTarget = project.TargetGuidByName("Unity-iPhone"); + PBXProject project = new PBXProject(); + project.ReadFromString(File.ReadAllText(pbxPath)); + string pbxTarget = project.TargetGuidByName("Unity-iPhone"); - // additional framework libs - project.AddFrameworkToProject(pbxTarget, "Security.framework", false); - project.AddFrameworkToProject(pbxTarget, "CoreData.framework", false); - // disable bitcode due to issue with Cardboard plugin (b/27129333) - project.SetBuildProperty(pbxTarget, "ENABLE_BITCODE", "false"); + // additional framework libs + project.AddFrameworkToProject(pbxTarget, "Security.framework", false); + project.AddFrameworkToProject(pbxTarget, "CoreData.framework", false); + // disable bitcode due to issue with Cardboard plugin (b/27129333) + project.SetBuildProperty(pbxTarget, "ENABLE_BITCODE", "false"); - File.WriteAllText(pbxPath, project.WriteToString()); + File.WriteAllText(pbxPath, project.WriteToString()); #else Die(5, "OS X required for building iOS target."); #endif @@ -1756,7 +1756,7 @@ public static void DoBackgroundBuild(TiltBuildOptions tiltOptions, bool interact string logFile = Path.Combine(rootCopyDir.FullName, "BackgroundBuild.log"); FileUtil.DeleteFileOrDirectory(logFile); #if UNITY_EDITOR_OSX - args.AppendFormat("--args "); + args.AppendFormat("--args "); #endif args.AppendFormat("-logFile {0} ", logFile); if (!interactive) { args.Append("-batchmode "); } @@ -1782,8 +1782,8 @@ public static void DoBackgroundBuild(TiltBuildOptions tiltOptions, bool interact StringBuilder unityPath = new StringBuilder(); unityPath.AppendFormat(EditorApplication.applicationPath); #if UNITY_EDITOR_OSX - // We want to run the inner Unity executable, not the GUI wrapper - unityPath.AppendFormat("/Contents/MacOS/Unity"); + // We want to run the inner Unity executable, not the GUI wrapper + unityPath.AppendFormat("/Contents/MacOS/Unity"); #endif process.StartInfo = new System.Diagnostics.ProcessStartInfo(unityPath.ToString(), args.ToString()); DetectBackgroundProcessExit(process); diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index 75837e0d32..3c7c3d9e8e 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -141,7 +141,7 @@ private class UserConfigChange // is being used (Oculus VR, Steam's Open VR, Monoscopic, etc.). public VrHardware VrHardware { - // This is set lazily the first time VrHardware is accesssed. + // This is set lazily the first time VrHardware is accessed. get { if (m_VrHardware == TiltBrush.VrHardware.Unset) @@ -224,8 +224,11 @@ public bool IsMobileHardware // Only sadness will ensue if the user tries to set Override.MobileHardware=true // but their editor platform is still set to Windows. #if UNITY_EDITOR && UNITY_ANDROID - get { return Application.platform == RuntimePlatform.Android - || SpoofMobileHardware.MobileHardware; } + get + { + return Application.platform == RuntimePlatform.Android + || SpoofMobileHardware.MobileHardware; + } #else get { return Application.platform == RuntimePlatform.Android; } #endif diff --git a/Assets/Scripts/Entitlement/OculusAuth.cs b/Assets/Scripts/Entitlement/OculusAuth.cs index 8676e14505..3254fdb356 100644 --- a/Assets/Scripts/Entitlement/OculusAuth.cs +++ b/Assets/Scripts/Entitlement/OculusAuth.cs @@ -20,50 +20,61 @@ namespace TiltBrush public class OculusAuth : MonoBehaviour { #if OCULUS_SUPPORTED - private bool m_authenticated = false; - // The App ID is a public identifier for the Tilt Brush app on the Oculus platform. It is - // analogous to Apple's App ID, which shows up in URLs related to the app. - private string m_TiltBrushOculusRiftAppId => App.Config.OculusSecrets?.ClientId; - private string m_TiltBrushOculusMobileAppId => App.Config.OculusMobileSecrets?.ClientId; + private bool m_authenticated = false; + // The App ID is a public identifier for the Tilt Brush app on the Oculus platform. It is + // analogous to Apple's App ID, which shows up in URLs related to the app. + private string m_TiltBrushOculusRiftAppId => App.Config.OculusSecrets?.ClientId; + private string m_TiltBrushOculusMobileAppId => App.Config.OculusMobileSecrets?.ClientId; - private void Awake() { - string id = App.Config.IsMobileHardware - ? m_TiltBrushOculusMobileAppId - : m_TiltBrushOculusRiftAppId; - if (string.IsNullOrEmpty(id)) { - return; - } - Oculus.Platform.Core.AsyncInitialize(id); - Oculus.Platform.Entitlements.IsUserEntitledToApplication().OnComplete(EntitlementCallback); - } + private void Awake() + { + string id = App.Config.IsMobileHardware + ? m_TiltBrushOculusMobileAppId + : m_TiltBrushOculusRiftAppId; + if (string.IsNullOrEmpty(id)) + { + return; + } + Oculus.Platform.Core.AsyncInitialize(id); + Oculus.Platform.Entitlements.IsUserEntitledToApplication().OnComplete(EntitlementCallback); + } - public void Update() { - Oculus.Platform.Request.RunCallbacks(); - } + public void Update() + { + Oculus.Platform.Request.RunCallbacks(); + } - private void EntitlementCallback(Oculus.Platform.Message msg) - { - string strMsg; - if (msg.IsError) { - if (msg.GetError() != null) { - strMsg = msg.GetError().Message; - } else { - strMsg = "Authentication failed"; - } - } else { - m_authenticated = true; - strMsg = ""; - } + private void EntitlementCallback(Oculus.Platform.Message msg) + { + string strMsg; + if (msg.IsError) + { + if (msg.GetError() != null) + { + strMsg = msg.GetError().Message; + } + else + { + strMsg = "Authentication failed"; + } + } + else + { + m_authenticated = true; + strMsg = ""; + } - if (strMsg != string.Empty) { - Debug.Log(strMsg, this); - } + if (strMsg != string.Empty) + { + Debug.Log(strMsg, this); + } - if (!m_authenticated) { - Debug.Log("User not authenticated! You must be logged in to continue."); - Application.Quit(); - } - } + if (!m_authenticated) + { + Debug.Log("User not authenticated! You must be logged in to continue."); + Application.Quit(); + } + } #endif // OCULUS_SUPPORTED } } // namespace TiltBrush diff --git a/Assets/Scripts/GUI/SketchbookPanel.cs b/Assets/Scripts/GUI/SketchbookPanel.cs index c5b1178b98..a728fe9eef 100644 --- a/Assets/Scripts/GUI/SketchbookPanel.cs +++ b/Assets/Scripts/GUI/SketchbookPanel.cs @@ -335,10 +335,10 @@ protected override void RefreshPage() bool notSupported = false; #if UNITY_ANDROID && OCULUS_SUPPORTED - notSupported = !polyDown && !outOfDate && OVRPlugin.GetSystemHeadsetType() == OVRPlugin.SystemHeadset.Oculus_Quest - && (m_CurrentSketchSet == SketchSetType.Curated - || m_CurrentSketchSet == SketchSetType.Liked); - m_NotSupportedMessage.SetActive(notSupported); + notSupported = !polyDown && !outOfDate && OVRPlugin.GetSystemHeadsetType() == OVRPlugin.SystemHeadset.Oculus_Quest + && (m_CurrentSketchSet == SketchSetType.Curated + || m_CurrentSketchSet == SketchSetType.Liked); + m_NotSupportedMessage.SetActive(notSupported); #endif if (outOfDate || polyDown || notSupported) diff --git a/Assets/Scripts/Input/OculusControllerInfo.cs b/Assets/Scripts/Input/OculusControllerInfo.cs index f00bd289e7..3497512887 100644 --- a/Assets/Scripts/Input/OculusControllerInfo.cs +++ b/Assets/Scripts/Input/OculusControllerInfo.cs @@ -17,7 +17,7 @@ #if !OCULUS_SUPPORTED using OVRInput_Controller = System.Int32; #else // !OCULUS_SUPPORTED - using OVRInput_Controller = OVRInput.Controller; +using OVRInput_Controller = OVRInput.Controller; #endif // OCULUS_SUPPORTED namespace TiltBrush @@ -33,170 +33,193 @@ public class OculusControllerInfo : ControllerInfo public OVRInput_Controller m_ControllerType = 0; #if OCULUS_SUPPORTED - public OculusControllerInfo(BaseControllerBehavior behavior, bool isLeftHand) - : base(behavior) { - m_ControllerType = isLeftHand ? OVRInput.Controller.LTouch : OVRInput.Controller.RTouch; - } - - /// Updates IsTrackedObjectValid and Behavior.transform - public void UpdatePosesAndValidity() { - // OVRInput.Controller.Touch checks both (LTouch | RTouch) - bool bothTouchControllersConnected = - (OVRInput.GetConnectedControllers() & OVRInput.Controller.Touch) - == OVRInput.Controller.Touch; - OVRInput.Controller input = m_ControllerType; - IsTrackedObjectValid = OVRInput.GetControllerOrientationTracked(input) || - OVRInput.GetControllerPositionTracked(input) && - bothTouchControllersConnected; - Transform t = Behavior.transform; - t.localRotation = OVRInput.GetLocalControllerRotation(input); - t.localPosition = OVRInput.GetLocalControllerPosition(input); - } - - // Was InputManager.GetTriggerRatio() - public override float GetTriggerRatio() { - return OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, m_ControllerType); - } - - private OVRInput.Button MapVrInput(VrInput input) { - switch (input) { - case VrInput.Directional: - case VrInput.Thumbstick: - case VrInput.Touchpad: - return OVRInput.Button.PrimaryThumbstick; - - case VrInput.Trigger: - return OVRInput.Button.PrimaryIndexTrigger; - - case VrInput.Grip: - return OVRInput.Button.PrimaryHandTrigger; - - case VrInput.Button04: - return OVRInput.Button.One; - - case VrInput.Button01: - case VrInput.Button06: - // Pad_Left, Pad_Down, Full pad, (X,A) - return OVRInput.Button.One; - - case VrInput.Button02: - case VrInput.Button03: - case VrInput.Button05: - // Pad_Right, Pad_Up, Application button, (Y,B) - return OVRInput.Button.Two; - - case VrInput.Any: - return OVRInput.Button.One - | OVRInput.Button.Two - | OVRInput.Button.PrimaryThumbstick - | OVRInput.Button.PrimaryIndexTrigger - | OVRInput.Button.PrimaryHandTrigger - ; - } + public OculusControllerInfo(BaseControllerBehavior behavior, bool isLeftHand) + : base(behavior) + { + m_ControllerType = isLeftHand ? OVRInput.Controller.LTouch : OVRInput.Controller.RTouch; + } - // Should never get here. - return OVRInput.Button.None; - } - - private OVRInput.Touch MapVrTouch(VrInput input) { - switch (input) { - case VrInput.Button01: - case VrInput.Button04: - case VrInput.Button06: - return OVRInput.Touch.One; - case VrInput.Button02: - case VrInput.Button03: - case VrInput.Button05: - return OVRInput.Touch.Two; - case VrInput.Directional: - case VrInput.Thumbstick: - case VrInput.Touchpad: - return OVRInput.Touch.PrimaryThumbstick; - case VrInput.Any: - return OVRInput.Touch.One | - OVRInput.Touch.Two | - OVRInput.Touch.PrimaryThumbstick; - default: - Debug.Assert(false, string.Format("Invalid touch button enum: {0}", input.ToString())); - return OVRInput.Touch.None; - } - } - - // Not filtered - public override Vector2 GetPadValue() { - return GetThumbStickValue(); - } - - // Not filtered - public override Vector2 GetThumbStickValue() { - return OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, m_ControllerType); - } - - public override Vector2 GetPadValueDelta() { - return new Vector2(GetScrollXDelta(), GetScrollYDelta()); - } - - public override float GetGripValue() { - // Raw value in [0, 1] - return OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, m_ControllerType); - } - - public override float GetTriggerValue() { - return OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, m_ControllerType); - } - - public override float GetScrollXDelta() { - if (IsTrackedObjectValid) { - return OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, m_ControllerType).x; - } - return 0.0f; - } + /// Updates IsTrackedObjectValid and Behavior.transform + public void UpdatePosesAndValidity() + { + // OVRInput.Controller.Touch checks both (LTouch | RTouch) + bool bothTouchControllersConnected = + (OVRInput.GetConnectedControllers() & OVRInput.Controller.Touch) + == OVRInput.Controller.Touch; + OVRInput.Controller input = m_ControllerType; + IsTrackedObjectValid = OVRInput.GetControllerOrientationTracked(input) || + OVRInput.GetControllerPositionTracked(input) && + bothTouchControllersConnected; + Transform t = Behavior.transform; + t.localRotation = OVRInput.GetLocalControllerRotation(input); + t.localPosition = OVRInput.GetLocalControllerPosition(input); + } - public override float GetScrollYDelta() { - if (IsTrackedObjectValid) { - return OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, m_ControllerType).y; - } - return 0.0f; - } - - /// Returns the value of the specified button (level trigger). - public override bool GetVrInput(VrInput input) { - if (!m_IsValid) { return false; } - - switch (input) { - case VrInput.Grip: - // This is the old behavior of GetControllerGrip() which was merged into GetVrInput() - return OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, m_ControllerType) > - App.VrSdk.AnalogGripBinaryThreshold_Rift; - default: - return OVRInput.Get(MapVrInput(input), m_ControllerType); - } - } - - /// Returns true if the specified button was just pressed (rising-edge trigger). - public override bool GetVrInputDown(VrInput input) { - if (!m_IsValid) { return false; } - return OVRInput.GetDown(MapVrInput(input), m_ControllerType); - } - - public override bool GetVrInputTouch(VrInput input) { - if (!m_IsValid) { return false; } - return OVRInput.Get(MapVrTouch(input), m_ControllerType); - } - - public override void TriggerControllerHaptics(float seconds) { - if (m_VibrationCoroutine != null) { - App.Instance.StopCoroutine(m_VibrationCoroutine); - } + // Was InputManager.GetTriggerRatio() + public override float GetTriggerRatio() + { + return OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, m_ControllerType); + } + + private OVRInput.Button MapVrInput(VrInput input) + { + switch (input) + { + case VrInput.Directional: + case VrInput.Thumbstick: + case VrInput.Touchpad: + return OVRInput.Button.PrimaryThumbstick; + + case VrInput.Trigger: + return OVRInput.Button.PrimaryIndexTrigger; + + case VrInput.Grip: + return OVRInput.Button.PrimaryHandTrigger; + + case VrInput.Button04: + return OVRInput.Button.One; + + case VrInput.Button01: + case VrInput.Button06: + // Pad_Left, Pad_Down, Full pad, (X,A) + return OVRInput.Button.One; + + case VrInput.Button02: + case VrInput.Button03: + case VrInput.Button05: + // Pad_Right, Pad_Up, Application button, (Y,B) + return OVRInput.Button.Two; + + case VrInput.Any: + return OVRInput.Button.One + | OVRInput.Button.Two + | OVRInput.Button.PrimaryThumbstick + | OVRInput.Button.PrimaryIndexTrigger + | OVRInput.Button.PrimaryHandTrigger + ; + } + + // Should never get here. + return OVRInput.Button.None; + } + + private OVRInput.Touch MapVrTouch(VrInput input) + { + switch (input) + { + case VrInput.Button01: + case VrInput.Button04: + case VrInput.Button06: + return OVRInput.Touch.One; + case VrInput.Button02: + case VrInput.Button03: + case VrInput.Button05: + return OVRInput.Touch.Two; + case VrInput.Directional: + case VrInput.Thumbstick: + case VrInput.Touchpad: + return OVRInput.Touch.PrimaryThumbstick; + case VrInput.Any: + return OVRInput.Touch.One | + OVRInput.Touch.Two | + OVRInput.Touch.PrimaryThumbstick; + default: + Debug.Assert(false, string.Format("Invalid touch button enum: {0}", input.ToString())); + return OVRInput.Touch.None; + } + } + + // Not filtered + public override Vector2 GetPadValue() + { + return GetThumbStickValue(); + } + + // Not filtered + public override Vector2 GetThumbStickValue() + { + return OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, m_ControllerType); + } + + public override Vector2 GetPadValueDelta() + { + return new Vector2(GetScrollXDelta(), GetScrollYDelta()); + } - App.Instance.StartCoroutine(DoVibration(m_ControllerType, seconds)); - } + public override float GetGripValue() + { + // Raw value in [0, 1] + return OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, m_ControllerType); + } + + public override float GetTriggerValue() + { + return OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, m_ControllerType); + } + + public override float GetScrollXDelta() + { + if (IsTrackedObjectValid) + { + return OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, m_ControllerType).x; + } + return 0.0f; + } + + public override float GetScrollYDelta() + { + if (IsTrackedObjectValid) + { + return OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, m_ControllerType).y; + } + return 0.0f; + } + + /// Returns the value of the specified button (level trigger). + public override bool GetVrInput(VrInput input) + { + if (!m_IsValid) { return false; } + + switch (input) + { + case VrInput.Grip: + // This is the old behavior of GetControllerGrip() which was merged into GetVrInput() + return OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, m_ControllerType) > + App.VrSdk.AnalogGripBinaryThreshold_Rift; + default: + return OVRInput.Get(MapVrInput(input), m_ControllerType); + } + } + + /// Returns true if the specified button was just pressed (rising-edge trigger). + public override bool GetVrInputDown(VrInput input) + { + if (!m_IsValid) { return false; } + return OVRInput.GetDown(MapVrInput(input), m_ControllerType); + } + + public override bool GetVrInputTouch(VrInput input) + { + if (!m_IsValid) { return false; } + return OVRInput.Get(MapVrTouch(input), m_ControllerType); + } + + public override void TriggerControllerHaptics(float seconds) + { + if (m_VibrationCoroutine != null) + { + App.Instance.StopCoroutine(m_VibrationCoroutine); + } - private IEnumerator DoVibration(OVRInput.Controller controller, float duration) { - OVRInput.SetControllerVibration(1, App.VrSdk.VrControls.HapticsAmplitudeScale, controller); - yield return new WaitForSeconds(App.VrSdk.VrControls.HapticsDurationScale * duration); - OVRInput.SetControllerVibration(0, 0, controller); - } + App.Instance.StartCoroutine(DoVibration(m_ControllerType, seconds)); + } + + private IEnumerator DoVibration(OVRInput.Controller controller, float duration) + { + OVRInput.SetControllerVibration(1, App.VrSdk.VrControls.HapticsAmplitudeScale, controller); + yield return new WaitForSeconds(App.VrSdk.VrControls.HapticsDurationScale * duration); + OVRInput.SetControllerVibration(0, 0, controller); + } #else // OCULUS_SUPPORTED public OculusControllerInfo(BaseControllerBehavior behavior, bool isLeftHand) diff --git a/Assets/Scripts/VrSdk.cs b/Assets/Scripts/VrSdk.cs index 13a5d0dd7d..8bc18b1976 100644 --- a/Assets/Scripts/VrSdk.cs +++ b/Assets/Scripts/VrSdk.cs @@ -91,7 +91,7 @@ public class VrSdk : MonoBehaviour // Oculus Overlay #if OCULUS_SUPPORTED - private OVROverlay m_OVROverlay; + private OVROverlay m_OVROverlay; #endif // OCULUS_SUPPORTED // Mobile Overlay @@ -167,36 +167,37 @@ void Awake() m_OverlayMode = OverlayMode.Steam; } #if OCULUS_SUPPORTED - else if (App.Config.m_SdkMode == SdkMode.Oculus) { - m_OverlayMode = OverlayMode.OVR; - var gobj = new GameObject("Oculus Overlay"); - gobj.transform.SetParent(m_VrSystem.transform, worldPositionStays: false); - m_OVROverlay = gobj.AddComponent(); - m_OVROverlay.isDynamic = true; - m_OVROverlay.compositionDepth = 0; - m_OVROverlay.currentOverlayType = OVROverlay.OverlayType.Overlay; - m_OVROverlay.currentOverlayShape = OVROverlay.OverlayShape.Quad; - m_OVROverlay.noDepthBufferTesting = true; - m_OVROverlay.enabled = false; - } + else if (App.Config.m_SdkMode == SdkMode.Oculus) + { + m_OverlayMode = OverlayMode.OVR; + var gobj = new GameObject("Oculus Overlay"); + gobj.transform.SetParent(m_VrSystem.transform, worldPositionStays: false); + m_OVROverlay = gobj.AddComponent(); + m_OVROverlay.isDynamic = true; + m_OVROverlay.compositionDepth = 0; + m_OVROverlay.currentOverlayType = OVROverlay.OverlayType.Overlay; + m_OVROverlay.currentOverlayShape = OVROverlay.OverlayShape.Quad; + m_OVROverlay.noDepthBufferTesting = true; + m_OVROverlay.enabled = false; + } #endif // OCULUS_SUPPORTED if (App.Config.m_SdkMode == SdkMode.Oculus) { #if OCULUS_SUPPORTED - // ---------------------------------------------------------------------------------------- // - // OculusVR - // ---------------------------------------------------------------------------------------- // - OVRManager manager = gameObject.AddComponent(); - manager.trackingOriginType = OVRManager.TrackingOrigin.FloorLevel; - manager.useRecommendedMSAALevel = false; - - SetControllerStyle(TiltBrush.ControllerStyle.OculusTouch); - // adding components to the VR Camera needed for fading view and getting controller poses. - m_VrCamera.gameObject.AddComponent(); - m_VrCamera.gameObject.AddComponent(); - - gameObject.AddComponent(); + // ---------------------------------------------------------------------------------------- // + // OculusVR + // ---------------------------------------------------------------------------------------- // + OVRManager manager = gameObject.AddComponent(); + manager.trackingOriginType = OVRManager.TrackingOrigin.FloorLevel; + manager.useRecommendedMSAALevel = false; + + SetControllerStyle(TiltBrush.ControllerStyle.OculusTouch); + // adding components to the VR Camera needed for fading view and getting controller poses. + m_VrCamera.gameObject.AddComponent(); + m_VrCamera.gameObject.AddComponent(); + + gameObject.AddComponent(); #endif // OCULUS_SUPPORTED } else if (App.Config.m_SdkMode == SdkMode.SteamVR) @@ -296,10 +297,10 @@ void Start() else if (App.Config.m_SdkMode == SdkMode.Oculus) { #if OCULUS_SUPPORTED - OculusHandTrackingManager.NewPosesApplied += OnNewPoses; - // We shouldn't call this frequently, hence the local cache and callbacks. - OVRManager.VrFocusAcquired += () => { OnInputFocus(true); }; - OVRManager.VrFocusLost += () => { OnInputFocus(false); }; + OculusHandTrackingManager.NewPosesApplied += OnNewPoses; + // We shouldn't call this frequently, hence the local cache and callbacks. + OVRManager.VrFocusAcquired += () => { OnInputFocus(true); }; + OVRManager.VrFocusLost += () => { OnInputFocus(false); }; #endif // OCULUS_SUPPORTED } else if (App.Config.m_SdkMode == SdkMode.Gvr) @@ -413,11 +414,12 @@ public string GetDisplayIdentifier() else if (App.Config.m_SdkMode == SdkMode.Oculus) { #if OCULUS_SUPPORTED - OVRPlugin.AppPerfStats perfStats = OVRPlugin.GetAppPerfStats(); - if (perfStats.FrameStatsCount > 0) { - return perfStats.FrameStats[0].AppDroppedFrameCount; - } - return 0; + OVRPlugin.AppPerfStats perfStats = OVRPlugin.GetAppPerfStats(); + if (perfStats.FrameStatsCount > 0) + { + return perfStats.FrameStats[0].AppDroppedFrameCount; + } + return 0; #endif // OCULUS_SUPPORTED } @@ -429,7 +431,7 @@ public void ResetPerfStats() if (App.Config.m_SdkMode == SdkMode.Oculus) { #if OCULUS_SUPPORTED - OVRPlugin.ResetAppPerfStats(); + OVRPlugin.ResetAppPerfStats(); #endif // OCULUS_SUPPORTED } } @@ -470,10 +472,10 @@ private void RefreshRoomBoundsCache() if (App.Config.m_SdkMode == SdkMode.Oculus) { #if OCULUS_SUPPORTED - // N points, clockwise winding (but axis is undocumented), undocumented convexity - // In practice, it's clockwise looking along Y- - points_RS = OVRManager.boundary.GetGeometry(OVRBoundary.BoundaryType.OuterBoundary) - .Select(v => UnityFromOculus(v)).ToArray(); + // N points, clockwise winding (but axis is undocumented), undocumented convexity + // In practice, it's clockwise looking along Y- + points_RS = OVRManager.boundary.GetGeometry(OVRBoundary.BoundaryType.OuterBoundary) + .Select(v => UnityFromOculus(v)).ToArray(); #endif // OCULUS_SUPPORTED } else if (App.Config.m_SdkMode == SdkMode.SteamVR) @@ -870,7 +872,7 @@ public bool OverlayEnabled return m_SteamVROverlay.gameObject.activeSelf; case OverlayMode.OVR: #if OCULUS_SUPPORTED - return m_OVROverlay.enabled; + return m_OVROverlay.enabled; #else return false; #endif // OCULUS_SUPPORTED @@ -889,7 +891,7 @@ public bool OverlayEnabled break; case OverlayMode.OVR: #if OCULUS_SUPPORTED - m_OVROverlay.enabled = value; + m_OVROverlay.enabled = value; #endif // OCULUS_SUPPORTED break; case OverlayMode.Mobile: @@ -909,7 +911,7 @@ public void SetOverlayTexture(Texture tex) break; case OverlayMode.OVR: #if OCULUS_SUPPORTED - m_OVROverlay.textures = new[] { tex }; + m_OVROverlay.textures = new[] { tex }; #endif // OCULUS_SUPPORTED break; } @@ -933,9 +935,9 @@ public void PositionOverlay(float distance, float height) break; case OverlayMode.OVR: #if OCULUS_SUPPORTED - vOverlayPosition += (vOverlayDirection * distance / 10); - m_OVROverlay.transform.position = vOverlayPosition; - m_OVROverlay.transform.forward = vOverlayDirection; + vOverlayPosition += (vOverlayDirection * distance / 10); + m_OVROverlay.transform.position = vOverlayPosition; + m_OVROverlay.transform.forward = vOverlayDirection; #endif // OCULUS_SUPPORTED break; } @@ -1040,9 +1042,10 @@ public bool IsHmdInitialized() return true; } #if OCULUS_SUPPORTED - else if (App.Config.m_SdkMode == SdkMode.Oculus && !OVRManager.isHmdPresent) { - return false; - } + else if (App.Config.m_SdkMode == SdkMode.Oculus && !OVRManager.isHmdPresent) + { + return false; + } #endif // OCULUS_SUPPORTED /* else if (App.Config.m_SdkMode == SdkMode.Wmr && somehow check for Wmr headset ) { return false; @@ -1156,27 +1159,33 @@ public void RestorePoseTracking() // Performance Methods // -------------------------------------------------------------------------------------------- // #if OCULUS_SUPPORTED - public void SetFixedFoveation(int level) { - Debug.Assert(level >= 0 && level <= 3); - if (App.Config.IsMobileHardware && !SpoofMobileHardware.MobileHardware - && App.Config.m_SdkMode == SdkMode.Oculus) { - OVRManager.tiledMultiResLevel = (OVRManager.TiledMultiResLevel) level; - } - } + public void SetFixedFoveation(int level) + { + Debug.Assert(level >= 0 && level <= 3); + if (App.Config.IsMobileHardware && !SpoofMobileHardware.MobileHardware + && App.Config.m_SdkMode == SdkMode.Oculus) + { + OVRManager.tiledMultiResLevel = (OVRManager.TiledMultiResLevel)level; + } + } - /// Gets GPU utilization 0 .. 1 if supported, otherwise returns 0. - public float GetGpuUtilization() { - if (App.Config.m_SdkMode == SdkMode.Oculus && OVRManager.gpuUtilSupported) { - return OVRManager.gpuUtilLevel; - } - return 0; - } + /// Gets GPU utilization 0 .. 1 if supported, otherwise returns 0. + public float GetGpuUtilization() + { + if (App.Config.m_SdkMode == SdkMode.Oculus && OVRManager.gpuUtilSupported) + { + return OVRManager.gpuUtilLevel; + } + return 0; + } - public void SetGpuClockLevel(int level) { - if (App.Config.m_SdkMode == SdkMode.Oculus && App.Config.IsMobileHardware) { - OVRManager.gpuLevel = level; - } - } + public void SetGpuClockLevel(int level) + { + if (App.Config.m_SdkMode == SdkMode.Oculus && App.Config.IsMobileHardware) + { + OVRManager.gpuLevel = level; + } + } #else // OCULUS_SUPPORTED public void SetFixedFoveation(int level) {