diff --git a/Assets/Plugins/LeapMotion/Core/Editor/LeapServiceProviderEditor.cs b/Assets/Plugins/LeapMotion/Core/Editor/LeapServiceProviderEditor.cs index d2db2e9373..9ae4399a87 100644 --- a/Assets/Plugins/LeapMotion/Core/Editor/LeapServiceProviderEditor.cs +++ b/Assets/Plugins/LeapMotion/Core/Editor/LeapServiceProviderEditor.cs @@ -62,6 +62,9 @@ private void frameOptimizationWarning(SerializedProperty property) { } public override void OnInspectorGUI() { + #if UNITY_2019_3_OR_NEWER + // Easily tracking VR-enabled-or-not requires an XR package installed, so remove this warning for now. + #else if (UnityEditor.PlayerSettings.virtualRealitySupported && !isVRProvider) { EditorGUILayout.HelpBox( "VR support is enabled. If your Leap is mounted to your headset, you should be " @@ -69,6 +72,7 @@ public override void OnInspectorGUI() { + "is not mounted to your headset, you can safely ignore this warning.)", MessageType.Warning); } + #endif base.OnInspectorGUI(); } diff --git a/Assets/Plugins/LeapMotion/Core/Scripts/LeapXRServiceProvider.cs b/Assets/Plugins/LeapMotion/Core/Scripts/LeapXRServiceProvider.cs index 137cd46b7f..d4168f183f 100644 --- a/Assets/Plugins/LeapMotion/Core/Scripts/LeapXRServiceProvider.cs +++ b/Assets/Plugins/LeapMotion/Core/Scripts/LeapXRServiceProvider.cs @@ -11,7 +11,7 @@ using System; using Leap.Unity.Attributes; -#if UNITY_2018_2_OR_NEWER +#if UNITY_2019_1_OR_NEWER using UnityEngine.Rendering; #endif @@ -237,7 +237,7 @@ protected virtual void OnEnable() { preCullCamera = GetComponent(); } - #if UNITY_2018_2_OR_NEWER + #if UNITY_2019_1_OR_NEWER if (GraphicsSettings.renderPipelineAsset != null) { RenderPipelineManager.beginCameraRendering -= onBeginRendering; RenderPipelineManager.beginCameraRendering += onBeginRendering; @@ -254,7 +254,7 @@ protected virtual void OnEnable() { protected virtual void OnDisable() { resetShaderTransforms(); - #if UNITY_2018_2_OR_NEWER + #if UNITY_2019_1_OR_NEWER if (GraphicsSettings.renderPipelineAsset != null) { RenderPipelineManager.beginCameraRendering -= onBeginRendering; } else { @@ -335,7 +335,9 @@ void LateUpdate() { Shader.SetGlobalMatrix("_LeapGlobalWarpedOffset", imageMatWarp); } + #if UNITY_2019_1_OR_NEWER protected virtual void onBeginRendering(ScriptableRenderContext context, Camera camera) { onPreCull(camera); } + #endif protected virtual void onPreCull(Camera preCullingCamera) { if (preCullingCamera != preCullCamera) { diff --git a/Assets/Plugins/LeapMotion/Core/Scripts/Utils/Utils.cs b/Assets/Plugins/LeapMotion/Core/Scripts/Utils/Utils.cs index 056a5e0e0f..bf24b7e745 100644 --- a/Assets/Plugins/LeapMotion/Core/Scripts/Utils/Utils.cs +++ b/Assets/Plugins/LeapMotion/Core/Scripts/Utils/Utils.cs @@ -2301,7 +2301,7 @@ public static void DrawCone(Vector3 origin, TextureFormat.EAC_R_SIGNED, TextureFormat.EAC_RG, TextureFormat.EAC_RG_SIGNED - #if !UNITY_2019_1_OR_NEWER + #if !UNITY_2018_2_OR_NEWER , TextureFormat.ETC_RGB4_3DS, TextureFormat.ETC_RGBA8_3DS diff --git a/Assets/Plugins/LeapMotion/Core/Scripts/Utils/XRSupportUtil.cs b/Assets/Plugins/LeapMotion/Core/Scripts/Utils/XRSupportUtil.cs index 6377572991..f84dc4412d 100644 --- a/Assets/Plugins/LeapMotion/Core/Scripts/Utils/XRSupportUtil.cs +++ b/Assets/Plugins/LeapMotion/Core/Scripts/Utils/XRSupportUtil.cs @@ -7,6 +7,7 @@ * between Ultraleap and you, your company or other organization. * ******************************************************************************/ +using System.Collections.Generic; using UnityEngine; #if UNITY_2017_2_OR_NEWER @@ -46,19 +47,32 @@ public static bool IsXRDevicePresent() { static bool outputPresenceWarning = false; public static bool IsUserPresent(bool defaultPresence = true) { - #if UNITY_2017_2_OR_NEWER - var userPresence = XRDevice.userPresence; - if (userPresence == UserPresenceState.Present) { - return true; - } else if (!outputPresenceWarning && userPresence == UserPresenceState.Unsupported) { - Debug.LogWarning("XR UserPresenceState unsupported (XR support is probably disabled)."); - outputPresenceWarning = true; - } + #if UNITY_2019_3_OR_NEWER + var devices = new List(); + InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices); + if (devices.Count == 0 && !outputPresenceWarning) { + Debug.LogWarning("No head-mounted devices found. Possibly no HMD is available to the XR system."); + outputPresenceWarning = true; + } + if (devices.Count != 0) { + var device = devices[0]; + if (device.TryGetFeatureValue(CommonUsages.userPresence, out var userPresent)) { + return userPresent; + } + } + #elif UNITY_2017_2_OR_NEWER + var userPresence = XRDevice.userPresence; + if (userPresence == UserPresenceState.Present) { + return true; + } else if (!outputPresenceWarning && userPresence == UserPresenceState.Unsupported) { + Debug.LogWarning("XR UserPresenceState unsupported (XR support is probably disabled)."); + outputPresenceWarning = true; + } #else - if (!outputPresenceWarning){ - Debug.LogWarning("XR UserPresenceState is only supported in 2017.2 and newer."); - outputPresenceWarning = true; - } + if (!outputPresenceWarning){ + Debug.LogWarning("XR UserPresenceState is only supported in 2017.2 and newer."); + outputPresenceWarning = true; + } #endif return defaultPresence; } @@ -166,7 +180,15 @@ public static Quaternion GetXRNodeLocalRotation(int node) { } public static void Recenter() { - InputTracking.Recenter(); + #if UNITY_2019_3_OR_NEWER + var devices = new List(); + InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices); + if (devices.Count == 0) return; + var hmdDevice = devices[0]; + hmdDevice.subsystem.TryRecenter(); + #else + InputTracking.Recenter(); + #endif } public static string GetLoadedDeviceName() { @@ -177,11 +199,18 @@ public static string GetLoadedDeviceName() { #endif } + /// Returns whether there's a floor available. public static bool IsRoomScale() { - #if UNITY_2017_2_OR_NEWER - return XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale; + #if UNITY_2019_3_OR_NEWER + var devices = new List(); + InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices); + if (devices.Count == 0) return false; + var hmdDevice = devices[0]; + return hmdDevice.subsystem.GetTrackingOriginMode().HasFlag(TrackingOriginModeFlags.Floor); + #elif UNITY_2017_2_OR_NEWER + return XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale; #else - return VRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale; + return VRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale; #endif } diff --git a/README.md b/README.md index a96d2097ec..2590005ef1 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ To download Leap Motion's latest stable modules as .unitypackages, visit [our Un **UnityModules packages from our developer website support Unity 5.6.2, 2017.1-4, and 2018.1.** Newer versions of Unity are usually perfectly safe to use. If you encounter errors or warnings with newer Unity versions, please report them as an Issue. +Since Unity Modules 4.5.0, our [releases page][releases] on this repository is the official source for distribution. This version of UnityModules fixes compilation warnings in Unity 2019 and includes some fixes for newer Unity features like the Scriptable Render Pipeline (in 2019.1 and beyond). + **The UnityModules *repository* expects Unity 2017.3 and up.** If you are sourcing UnityModules directly from this repository, your mileage may vary with earlier versions of Unity. ## License @@ -20,3 +22,4 @@ This repository contains code for Leap Motion's Unity Modules, easy-to-use tools [devsite]: https://developer.leapmotion.com/unity/ "Leap Motion Unity Developer site" [wiki]: https://github.com/leapmotion/UnityModules/wiki "Leap Motion Unity Modules Wiki" [sdkagreement]: https://developer.leapmotion.com/sdk_agreement "Leap Motion Developer SDK Agreement" +[releases]: https://github.com/leapmotion/UnityModules/releases