Skip to content

Commit

Permalink
Merge pull request #1107 from leapmotion/develop
Browse files Browse the repository at this point in the history
Pending Hotfixes for Release 4.5.0
  • Loading branch information
vabrador authored May 1, 2020
2 parents 6a90380 + f57e175 commit d306081
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,17 @@ 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 "
+ "using LeapXRServiceProvider instead of LeapServiceProvider. (If your Leap "
+ "is not mounted to your headset, you can safely ignore this warning.)",
MessageType.Warning);
}
#endif

base.OnInspectorGUI();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -237,7 +237,7 @@ protected virtual void OnEnable() {
preCullCamera = GetComponent<Camera>();
}

#if UNITY_2018_2_OR_NEWER
#if UNITY_2019_1_OR_NEWER
if (GraphicsSettings.renderPipelineAsset != null) {
RenderPipelineManager.beginCameraRendering -= onBeginRendering;
RenderPipelineManager.beginCameraRendering += onBeginRendering;
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Plugins/LeapMotion/Core/Scripts/Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 45 additions & 16 deletions Assets/Plugins/LeapMotion/Core/Scripts/Utils/XRSupportUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<InputDevice>();
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;
}
Expand Down Expand Up @@ -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<InputDevice>();
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() {
Expand All @@ -177,11 +199,18 @@ public static string GetLoadedDeviceName() {
#endif
}

/// <summary> Returns whether there's a floor available. </summary>
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<InputDevice>();
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
}

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit d306081

Please sign in to comment.