Skip to content

Commit dd5eaf5

Browse files
authored
Merge pull request De-Panther#276 from De-Panther/fix_subsystemregistration
Fix SubsystemRegistration not exist after xr.management version 4.3.1
2 parents f416ee8 + 0e8267a commit dd5eaf5

File tree

5 files changed

+90
-3
lines changed

5 files changed

+90
-3
lines changed

Packages/webxr/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Fixed
1010
- Issues when using more than one WebXRManager components.
11+
- Missing SubsystemRegistration when using newer versions of Unity XR Management package.
1112

1213
## [0.16.0] - 2023-02-02
1314
### Added

Packages/webxr/Runtime/Scripts/WebXRManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ public enum WebXRVisibilityState
1111
}
1212

1313
[DefaultExecutionOrder(-2020)]
14+
#if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
15+
public class WebXRManager : SubsystemLifecycleManager<WebXRSubsystem, WebXRSubsystemDescriptor, WebXRSubsystemProvider>
16+
#else
1417
public class WebXRManager : SubsystemLifecycleManager<WebXRSubsystem, WebXRSubsystemDescriptor>
18+
#endif
1519
{
1620
private static readonly Rect defaultRect = new Rect(0, 0, 1, 1);
1721

Packages/webxr/Runtime/WebXR.asmdef

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "WebXR",
3+
"rootNamespace": "",
34
"references": [
45
"Unity.XR.Management",
56
"Unity.Subsystem.Registration"
@@ -11,6 +12,12 @@
1112
"precompiledReferences": [],
1213
"autoReferenced": false,
1314
"defineConstraints": [],
14-
"versionDefines": [],
15+
"versionDefines": [
16+
{
17+
"name": "com.unity.xr.management",
18+
"expression": "4.3.1",
19+
"define": "UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER"
20+
}
21+
],
1522
"noEngineReferences": false
1623
}

Packages/webxr/Runtime/XRPlugin/WebXRSubsystem.cs

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,54 @@
1-
using System;
21
using System.Runtime.InteropServices;
32
using AOT;
43
using UnityEngine;
4+
#if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
5+
using UnityEngine.SubsystemsImplementation;
6+
#endif
57

68
namespace WebXR
79
{
810
// TODO: we need an XRInputSubsystem implementation - this can only be done via native code
911

12+
#if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
13+
public abstract class WebXRSubsystemProvider : SubsystemProvider<WebXRSubsystem> { }
14+
15+
public class WebXRSubsystemDescriptor : SubsystemDescriptorWithProvider<WebXRSubsystem, WebXRSubsystemProvider>
16+
{
17+
public WebXRSubsystemDescriptor()
18+
{
19+
providerType = typeof(WebXRSubsystem.Provider);
20+
}
21+
}
22+
#else
1023
public class WebXRSubsystemDescriptor : SubsystemDescriptor<WebXRSubsystem>
1124
{
1225
}
26+
#endif
1327

28+
#if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
29+
public class WebXRSubsystem : SubsystemWithProvider<WebXRSubsystem, WebXRSubsystemDescriptor, WebXRSubsystemProvider>
30+
#else
1431
public class WebXRSubsystem : Subsystem<WebXRSubsystemDescriptor>
32+
#endif
1533
{
34+
#if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
35+
public class Provider : WebXRSubsystemProvider
36+
{
37+
public override void Start() { }
38+
public override void Stop() { }
39+
public override void Destroy() { }
40+
}
41+
#endif
42+
1643
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
1744
private static void RegisterDescriptor()
1845
{
46+
#if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
47+
SubsystemDescriptorStore.RegisterDescriptor(new WebXRSubsystemDescriptor()
48+
{
49+
id = typeof(WebXRSubsystem).FullName
50+
});
51+
#else
1952
var res = SubsystemRegistration.CreateDescriptor(new WebXRSubsystemDescriptor()
2053
{
2154
id = typeof(WebXRSubsystem).FullName,
@@ -24,8 +57,18 @@ private static void RegisterDescriptor()
2457
if (res)
2558
Debug.Log("Registered " + nameof(WebXRSubsystemDescriptor));
2659
else Debug.Log("Failed registering " + nameof(WebXRSubsystemDescriptor));
60+
#endif
2761
}
2862

63+
#if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
64+
protected override void OnStart()
65+
{
66+
if (Instance != null) return;
67+
Debug.Log("Start " + nameof(WebXRSubsystem));
68+
Instance = this;
69+
InternalStart();
70+
}
71+
#else
2972
public override void Start()
3073
{
3174
if (running) return;
@@ -34,22 +77,41 @@ public override void Start()
3477
Instance = this;
3578
InternalStart();
3679
}
80+
#endif
3781

82+
#if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
83+
protected override void OnStop()
84+
{
85+
if (Instance == null) return;
86+
Debug.Log("Stop " + nameof(WebXRSubsystem));
87+
Instance = null;
88+
}
89+
#else
3890
public override void Stop()
3991
{
4092
if (!_running) return;
4193
Debug.Log("Stop " + nameof(WebXRSubsystem));
4294
_running = false;
4395
Instance = null;
4496
}
97+
#endif
4598

99+
#if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
100+
protected override void OnDestroy()
101+
{
102+
if (Instance == null) return;
103+
Debug.Log("Destroy " + nameof(WebXRSubsystem));
104+
Instance = null;
105+
}
106+
#else
46107
protected override void OnDestroy()
47108
{
48109
if (!running) return;
49110
Debug.Log("Destroy " + nameof(WebXRSubsystem));
50111
_running = false;
51112
Instance = null;
52113
}
114+
#endif
53115

54116
private void UpdateControllersOnEnd()
55117
{
@@ -161,8 +223,10 @@ private void UpdateXRCameras()
161223
}
162224
}
163225

226+
#if !UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
164227
private bool _running;
165228
public override bool running => _running;
229+
#endif
166230

167231
private static WebXRSubsystem Instance;
168232

@@ -570,4 +634,4 @@ bool GetHitTestPoseFromViewerHitTestPoseArray(ref WebXRHitPoseData hitPoseData)
570634
return true;
571635
}
572636
}
573-
}
637+
}

Packages/webxr/Runtime/XRPlugin/XRSystemLifecycleManager.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22
using UnityEngine;
33
using UnityEngine.XR.Management;
44

5+
#if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
6+
using UnityEngine.SubsystemsImplementation;
7+
#endif
8+
59
namespace WebXR
610
{
11+
#if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
12+
public class SubsystemLifecycleManager<TSubsystem, TSubsystemDescriptor,TProvider> : MonoBehaviour
13+
where TSubsystem : SubsystemWithProvider<TSubsystem, TSubsystemDescriptor,TProvider>, new()
14+
where TSubsystemDescriptor : SubsystemDescriptorWithProvider
15+
where TProvider : SubsystemProvider<TSubsystem>
16+
#else
717
public class SubsystemLifecycleManager<TSubsystem, TSubsystemDescriptor> : MonoBehaviour
818
where TSubsystem : Subsystem<TSubsystemDescriptor>
919
where TSubsystemDescriptor : SubsystemDescriptor<TSubsystem>
20+
#endif
1021
{
1122
/// <summary>
1223
/// Get the <c>TSubsystem</c> whose lifetime this component manages.

0 commit comments

Comments
 (0)