Skip to content

Commit 83005d8

Browse files
authored
Merge pull request #9868 from keveleigh/fix-auto-remoting
Fix automatic remoting for Windows XR Plugin
2 parents 78a9037 + 86d70fd commit 83005d8

17 files changed

+185
-42
lines changed

Assets/MRTK/Core/Definitions/Devices/ArticulatedHandDefinition.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,9 @@ public bool IsInPointingPose
131131
if (unityJointPoses.TryGetValue(TrackedHandJoint.Palm, out palmJoint))
132132
{
133133
Vector3 palmNormal = palmJoint.Rotation * (-1 * Vector3.up);
134-
if (cursorBeamBackwardTolerance >= 0)
134+
if (cursorBeamBackwardTolerance >= 0 && CameraCache.Main != null)
135135
{
136-
Vector3 cameraBackward = -CameraCache.Main.transform.forward;
137-
if (Vector3.Dot(palmNormal.normalized, cameraBackward) > cursorBeamBackwardTolerance)
136+
if (Vector3.Dot(palmNormal.normalized, -CameraCache.Main.transform.forward) > cursorBeamBackwardTolerance)
138137
{
139138
return false;
140139
}

Assets/MRTK/Providers/Oculus/XRSDK/MRTK.Oculus.asmdef

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"name": "Microsoft.MixedReality.Toolkit.Providers.XRSDK.Oculus",
3+
"rootNamespace": "",
34
"references": [
5+
"Microsoft.MixedReality.Toolkit.Async",
46
"Microsoft.MixedReality.Toolkit",
57
"Microsoft.MixedReality.Toolkit.Services.InputSystem",
68
"Microsoft.MixedReality.Toolkit.SDK",

Assets/MRTK/Providers/Oculus/XRSDK/OculusXRSDKDeviceManager.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.MixedReality.Toolkit.Utilities;
66
using Microsoft.MixedReality.Toolkit.XRSDK.Input;
77
using System;
8+
using UnityEngine;
89
using UnityEngine.XR;
910

1011
#if OCULUS_ENABLED
@@ -154,7 +155,7 @@ protected override SupportedControllerType GetCurrentControllerType(InputDevice
154155

155156
#endregion Controller Utilities
156157

157-
private bool IsActiveLoader =>
158+
private bool? IsActiveLoader =>
158159
#if OCULUS_ENABLED
159160
LoaderHelpers.IsLoaderActive<OculusLoader>();
160161
#else
@@ -164,18 +165,33 @@ protected override SupportedControllerType GetCurrentControllerType(InputDevice
164165
/// <inheritdoc/>
165166
public override void Enable()
166167
{
167-
if (!IsActiveLoader)
168+
if (!IsActiveLoader.HasValue)
169+
{
170+
IsEnabled = false;
171+
EnableIfLoaderBecomesActive();
172+
return;
173+
}
174+
else if (!IsActiveLoader.Value)
168175
{
169176
IsEnabled = false;
170177
return;
171178
}
172-
173-
base.Enable();
174179

175180
#if OCULUSINTEGRATION_PRESENT
176181
SetupInput();
177182
ConfigurePerformancePreferences();
178183
#endif // OCULUSINTEGRATION_PRESENT
184+
185+
base.Enable();
186+
}
187+
188+
private async void EnableIfLoaderBecomesActive()
189+
{
190+
await new WaitUntil(() => IsActiveLoader.HasValue);
191+
if (IsActiveLoader.Value)
192+
{
193+
Enable();
194+
}
179195
}
180196

181197
#if OCULUSINTEGRATION_PRESENT

Assets/MRTK/Providers/OpenXR/MRTK.OpenXR.asmdef

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"rootNamespace": "Microsoft.MixedReality.Toolkit.XRSDK.OpenXR",
44
"references": [
55
"Microsoft.MixedReality.OpenXR",
6+
"Microsoft.MixedReality.Toolkit.Async",
67
"Microsoft.MixedReality.Toolkit",
78
"Microsoft.MixedReality.Toolkit.Gltf",
89
"Microsoft.MixedReality.Toolkit.Providers.XRSDK",

Assets/MRTK/Providers/OpenXR/Scripts/OpenXRCameraSettings.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.MixedReality.Toolkit.CameraSystem;
55
using Microsoft.MixedReality.Toolkit.Utilities;
6+
using UnityEngine;
67

78
#if UNITY_OPENXR
89
using UnityEngine.XR.OpenXR;
@@ -36,7 +37,7 @@ public OpenXRCameraSettings(
3637
BaseCameraSettingsProfile profile = null) : base(cameraSystem, name, priority, profile)
3738
{ }
3839

39-
private bool IsActiveLoader =>
40+
private bool? IsActiveLoader =>
4041
#if UNITY_OPENXR
4142
LoaderHelpers.IsLoaderActive<OpenXRLoaderBase>();
4243
#else
@@ -50,14 +51,30 @@ public OpenXRCameraSettings(
5051
/// <inheritdoc />
5152
public override void Enable()
5253
{
53-
if (!IsActiveLoader)
54+
if (!IsActiveLoader.HasValue)
55+
{
56+
IsEnabled = false;
57+
EnableIfLoaderBecomesActive();
58+
return;
59+
}
60+
else if (!IsActiveLoader.Value)
5461
{
5562
IsEnabled = false;
5663
return;
5764
}
5865

59-
base.Enable();
6066
InitializeReprojectionUpdater();
67+
68+
base.Enable();
69+
}
70+
71+
private async void EnableIfLoaderBecomesActive()
72+
{
73+
await new WaitUntil(() => IsActiveLoader.HasValue);
74+
if (IsActiveLoader.Value)
75+
{
76+
Enable();
77+
}
6178
}
6279

6380
/// <inheritdoc/>

Assets/MRTK/Providers/OpenXR/Scripts/OpenXRDeviceManager.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.MixedReality.Toolkit.XRSDK.Input;
77
using System;
88
using Unity.Profiling;
9+
using UnityEngine;
910
using UnityEngine.XR;
1011

1112
#if UNITY_OPENXR
@@ -39,7 +40,7 @@ public OpenXRDeviceManager(
3940
uint priority = DefaultPriority,
4041
BaseMixedRealityProfile profile = null) : base(inputSystem, name, priority, profile) { }
4142

42-
private bool IsActiveLoader =>
43+
private bool? IsActiveLoader =>
4344
#if UNITY_OPENXR
4445
LoaderHelpers.IsLoaderActive<OpenXRLoaderBase>();
4546
#else
@@ -65,7 +66,13 @@ public OpenXRDeviceManager(
6566
/// <inheritdoc />
6667
public override void Enable()
6768
{
68-
if (!IsActiveLoader)
69+
if (!IsActiveLoader.HasValue)
70+
{
71+
IsEnabled = false;
72+
EnableIfLoaderBecomesActive();
73+
return;
74+
}
75+
else if (!IsActiveLoader.Value)
6976
{
7077
IsEnabled = false;
7178
return;
@@ -78,6 +85,15 @@ public override void Enable()
7885
base.Enable();
7986
}
8087

88+
private async void EnableIfLoaderBecomesActive()
89+
{
90+
await new WaitUntil(() => IsActiveLoader.HasValue);
91+
if (IsActiveLoader.Value)
92+
{
93+
Enable();
94+
}
95+
}
96+
8197
#if MSFT_OPENXR_0_9_4_OR_NEWER && WINDOWS_UWP
8298
/// <inheritdoc />
8399
public override void Initialize()

Assets/MRTK/Providers/OpenXR/Scripts/OpenXREyeGazeDataProvider.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public OpenXREyeGazeDataProvider(
4646
gazeSmoother.OnSaccadeY += GazeSmoother_OnSaccadeY;
4747
}
4848

49-
private bool IsActiveLoader =>
49+
private bool? IsActiveLoader =>
5050
#if UNITY_OPENXR
5151
LoaderHelpers.IsLoaderActive<OpenXRLoaderBase>();
5252
#else
@@ -99,7 +99,13 @@ public override void Initialize()
9999
/// <inheritdoc />
100100
public override void Enable()
101101
{
102-
if (!IsActiveLoader)
102+
if (!IsActiveLoader.HasValue)
103+
{
104+
IsEnabled = false;
105+
EnableIfLoaderBecomesActive();
106+
return;
107+
}
108+
else if (!IsActiveLoader.Value)
103109
{
104110
IsEnabled = false;
105111
return;
@@ -108,6 +114,15 @@ public override void Enable()
108114
base.Enable();
109115
}
110116

117+
private async void EnableIfLoaderBecomesActive()
118+
{
119+
await new WaitUntil(() => IsActiveLoader.HasValue);
120+
if (IsActiveLoader.Value)
121+
{
122+
Enable();
123+
}
124+
}
125+
111126
private void ReadProfile()
112127
{
113128
if (ConfigurationProfile == null)

Assets/MRTK/Providers/OpenXR/Scripts/OpenXRSpatialAwarenessMeshObserver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public OpenXRSpatialAwarenessMeshObserver(
3939
BaseMixedRealityProfile profile = null) : base(spatialAwarenessSystem, name, priority, profile)
4040
{ }
4141

42-
protected override bool IsActiveLoader =>
42+
protected override bool? IsActiveLoader =>
4343
#if MSFT_OPENXR_0_9_4_OR_NEWER
4444
LoaderHelpers.IsLoaderActive<OpenXRLoaderBase>();
4545
#else

Assets/MRTK/Providers/WindowsMixedReality/XRSDK/MRTK.WMR.XRSDK.asmdef

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality",
33
"references": [
4+
"Microsoft.MixedReality.Toolkit.Async",
45
"Microsoft.MixedReality.Toolkit",
56
"Microsoft.MixedReality.Toolkit.Editor.Utilities",
67
"Microsoft.MixedReality.Toolkit.Providers.WindowsMixedReality.Shared",

Assets/MRTK/Providers/WindowsMixedReality/XRSDK/WindowsMixedRealityCameraSettings.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.MixedReality.Toolkit.CameraSystem;
55
using Microsoft.MixedReality.Toolkit.Utilities;
66
using Microsoft.MixedReality.Toolkit.WindowsMixedReality;
7+
using UnityEngine;
78

89
namespace Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality
910
{
@@ -33,7 +34,7 @@ public WindowsMixedRealityCameraSettings(
3334
BaseCameraSettingsProfile profile = null) : base(cameraSystem, name, priority, profile)
3435
{ }
3536

36-
private bool IsActiveLoader =>
37+
private bool? IsActiveLoader =>
3738
#if WMR_ENABLED
3839
LoaderHelpers.IsLoaderActive("Windows MR Loader");
3940
#else
@@ -43,7 +44,13 @@ public WindowsMixedRealityCameraSettings(
4344
/// <inheritdoc />
4445
public override void Enable()
4546
{
46-
if (!IsActiveLoader)
47+
if (!IsActiveLoader.HasValue)
48+
{
49+
IsEnabled = false;
50+
EnableIfLoaderBecomesActive();
51+
return;
52+
}
53+
else if (!IsActiveLoader.Value)
4754
{
4855
IsEnabled = false;
4956
return;
@@ -52,6 +59,15 @@ public override void Enable()
5259
base.Enable();
5360
}
5461

62+
private async void EnableIfLoaderBecomesActive()
63+
{
64+
await new WaitUntil(() => IsActiveLoader.HasValue);
65+
if (IsActiveLoader.Value)
66+
{
67+
Enable();
68+
}
69+
}
70+
5571
#region IMixedRealityCameraSettings
5672

5773
/// <inheritdoc/>

0 commit comments

Comments
 (0)