Skip to content

Commit 44bf4d1

Browse files
committed
Slight rework of model providers
1 parent 07ad30f commit 44bf4d1

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ public MicrosoftControllerModelProvider(Utilities.Handedness handedness)
2929
private readonly ControllerModel controllerModelProvider;
3030
#endif // MSFT_OPENXR_0_9_4_OR_NEWER
3131

32-
#if MSFT_OPENXR_0_9_4_OR_NEWER
32+
// Disables "This async method lacks 'await' operators and will run synchronously." when the correct OpenXR package isn't installed
33+
#pragma warning disable CS1998
3334
/// <summary>
3435
/// Attempts to load the glTF controller model from OpenXR.
3536
/// </summary>
3637
/// <returns>The controller model as a GameObject or null if it was unobtainable.</returns>
3738
public async Task<GameObject> TryGenerateControllerModelFromPlatformSDK()
3839
{
40+
GameObject gltfGameObject = null;
41+
42+
#if MSFT_OPENXR_0_9_4_OR_NEWER
3943
if (!controllerModelProvider.TryGetControllerModelKey(out ulong modelKey))
4044
{
4145
Debug.LogError("Failed to obtain controller model key from platform.");
@@ -57,15 +61,16 @@ public async Task<GameObject> TryGenerateControllerModelFromPlatformSDK()
5761
}
5862

5963
Utilities.Gltf.Schema.GltfObject gltfObject = GltfUtility.GetGltfObjectFromGlb(modelStream);
60-
GameObject gltfGameObject = await gltfObject.ConstructAsync();
64+
gltfGameObject = await gltfObject.ConstructAsync();
6165

6266
if (gltfGameObject != null)
6367
{
6468
ControllerModelDictionary.Add(modelKey, gltfGameObject);
6569
}
70+
#endif // MSFT_OPENXR_0_9_4_OR_NEWER
6671

6772
return gltfGameObject;
6873
}
69-
#endif // MSFT_OPENXR_0_9_4_OR_NEWER
74+
#pragma warning restore CS1998
7075
}
7176
}

Assets/MRTK/Providers/WindowsMixedReality/Shared/WindowsMixedRealityControllerModelProvider.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.MixedReality.Toolkit.Utilities;
5+
using System.Threading.Tasks;
6+
using UnityEngine;
57

68
#if WINDOWS_UWP
79
using Microsoft.MixedReality.Toolkit.Input;
810
using Microsoft.MixedReality.Toolkit.Utilities.Gltf.Serialization;
911
using System;
1012
using System.Collections.Generic;
11-
using System.Threading.Tasks;
12-
using UnityEngine;
1313
using Windows.Storage.Streams;
1414
using Windows.UI.Input.Spatial;
1515
#endif
@@ -32,13 +32,19 @@ public WindowsMixedRealityControllerModelProvider(Handedness handedness)
3232
private readonly SpatialInteractionSource spatialInteractionSource;
3333

3434
private static readonly Dictionary<string, GameObject> ControllerModelDictionary = new Dictionary<string, GameObject>(2);
35+
#endif // WINDOWS_UWP
3536

37+
// Disables "This async method lacks 'await' operators and will run synchronously." for non-UWP
38+
#pragma warning disable CS1998
3639
/// <summary>
3740
/// Attempts to load the glTF controller model from the Windows SDK.
3841
/// </summary>
3942
/// <returns>The controller model as a GameObject or null if it was unobtainable.</returns>
4043
public async Task<GameObject> TryGenerateControllerModelFromPlatformSDK()
4144
{
45+
GameObject gltfGameObject = null;
46+
47+
#if WINDOWS_UWP
4248
if (spatialInteractionSource == null)
4349
{
4450
return null;
@@ -70,7 +76,6 @@ public async Task<GameObject> TryGenerateControllerModelFromPlatformSDK()
7076
}
7177
}
7278

73-
GameObject gltfGameObject = null;
7479
if (fileBytes != null)
7580
{
7681
Utilities.Gltf.Schema.GltfObject gltfObject = GltfUtility.GetGltfObjectFromGlb(fileBytes);
@@ -80,10 +85,13 @@ public async Task<GameObject> TryGenerateControllerModelFromPlatformSDK()
8085
ControllerModelDictionary.Add(GenerateKey(spatialInteractionSource), gltfGameObject);
8186
}
8287
}
88+
#endif // WINDOWS_UWP
8389

8490
return gltfGameObject;
8591
}
92+
#pragma warning restore CS1998
8693

94+
#if WINDOWS_UWP
8795
private string GenerateKey(SpatialInteractionSource spatialInteractionSource)
8896
{
8997
return spatialInteractionSource.Controller.VendorId + "/" + spatialInteractionSource.Controller.ProductId + "/" + spatialInteractionSource.Controller.Version + "/" + spatialInteractionSource.Handedness;

0 commit comments

Comments
 (0)