1
- using System ;
2
1
using System . Runtime . InteropServices ;
3
2
using AOT ;
4
3
using UnityEngine ;
4
+ #if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
5
+ using UnityEngine . SubsystemsImplementation ;
6
+ #endif
5
7
6
8
namespace WebXR
7
9
{
8
10
// TODO: we need an XRInputSubsystem implementation - this can only be done via native code
9
11
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
10
23
public class WebXRSubsystemDescriptor : SubsystemDescriptor < WebXRSubsystem >
11
24
{
12
25
}
26
+ #endif
13
27
28
+ #if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
29
+ public class WebXRSubsystem : SubsystemWithProvider < WebXRSubsystem , WebXRSubsystemDescriptor , WebXRSubsystemProvider >
30
+ #else
14
31
public class WebXRSubsystem : Subsystem < WebXRSubsystemDescriptor >
32
+ #endif
15
33
{
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
+
16
43
[ RuntimeInitializeOnLoadMethod ( RuntimeInitializeLoadType . SubsystemRegistration ) ]
17
44
private static void RegisterDescriptor ( )
18
45
{
46
+ #if UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
47
+ SubsystemDescriptorStore . RegisterDescriptor ( new WebXRSubsystemDescriptor ( )
48
+ {
49
+ id = typeof ( WebXRSubsystem ) . FullName
50
+ } ) ;
51
+ #else
19
52
var res = SubsystemRegistration . CreateDescriptor ( new WebXRSubsystemDescriptor ( )
20
53
{
21
54
id = typeof ( WebXRSubsystem ) . FullName ,
@@ -24,8 +57,18 @@ private static void RegisterDescriptor()
24
57
if ( res )
25
58
Debug . Log ( "Registered " + nameof ( WebXRSubsystemDescriptor ) ) ;
26
59
else Debug . Log ( "Failed registering " + nameof ( WebXRSubsystemDescriptor ) ) ;
60
+ #endif
27
61
}
28
62
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
29
72
public override void Start ( )
30
73
{
31
74
if ( running ) return ;
@@ -34,22 +77,41 @@ public override void Start()
34
77
Instance = this ;
35
78
InternalStart ( ) ;
36
79
}
80
+ #endif
37
81
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
38
90
public override void Stop ( )
39
91
{
40
92
if ( ! _running ) return ;
41
93
Debug . Log ( "Stop " + nameof ( WebXRSubsystem ) ) ;
42
94
_running = false ;
43
95
Instance = null ;
44
96
}
97
+ #endif
45
98
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
46
107
protected override void OnDestroy ( )
47
108
{
48
109
if ( ! running ) return ;
49
110
Debug . Log ( "Destroy " + nameof ( WebXRSubsystem ) ) ;
50
111
_running = false ;
51
112
Instance = null ;
52
113
}
114
+ #endif
53
115
54
116
private void UpdateControllersOnEnd ( )
55
117
{
@@ -161,8 +223,10 @@ private void UpdateXRCameras()
161
223
}
162
224
}
163
225
226
+ #if ! UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER
164
227
private bool _running ;
165
228
public override bool running => _running ;
229
+ #endif
166
230
167
231
private static WebXRSubsystem Instance ;
168
232
@@ -570,4 +634,4 @@ bool GetHitTestPoseFromViewerHitTestPoseArray(ref WebXRHitPoseData hitPoseData)
570
634
return true ;
571
635
}
572
636
}
573
- }
637
+ }
0 commit comments