1
- using System ;
1
+ using System ;
2
2
using System . Runtime . InteropServices ;
3
3
using AOT ;
4
4
using UnityEngine ;
5
5
6
+ #if UNITY_2022_2_OR_NEWER || UNITY_2023_1_OR_NEWER
7
+ using UnityEngine . SubsystemsImplementation ;
8
+ #endif
9
+
6
10
namespace WebXR
7
11
{
8
- // TODO: we need an XRInputSubsystem implementation - this can only be done via native code
12
+ #if UNITY_2022_2_OR_NEWER || UNITY_2023_1_OR_NEWER
13
+ public class WebXRSubsystemDescriptor : SubsystemDescriptorWithProvider < WebXRSubsystem , WebXRSubsystemProvider >
14
+ {
15
+ public WebXRSubsystemDescriptor ( )
16
+ {
17
+ providerType = typeof ( WebXRSubsystem . Provider ) ;
18
+ }
19
+ }
20
+
21
+ public abstract class WebXRSubsystemProvider : SubsystemProvider < WebXRSubsystem > { }
22
+
23
+ public class WebXRSubsystem : SubsystemWithProvider < WebXRSubsystem , WebXRSubsystemDescriptor , WebXRSubsystemProvider >
24
+ {
25
+ public class Provider : WebXRSubsystemProvider
26
+ {
27
+ public override void Start ( ) { }
28
+ public override void Stop ( ) { }
29
+ public override void Destroy ( ) { }
30
+ }
31
+
32
+ [ RuntimeInitializeOnLoadMethod ( RuntimeInitializeLoadType . SubsystemRegistration ) ]
33
+ private static void RegisterDescriptor ( )
34
+ {
35
+ SubsystemDescriptorStore . RegisterDescriptor ( new WebXRSubsystemDescriptor ( ) {
36
+ id = typeof ( WebXRSubsystem ) . FullName
37
+ } ) ;
38
+ }
39
+
40
+ internal static WebXRSubsystem Instance ;
41
+ protected override void OnStart ( )
42
+ {
43
+ if ( Instance != null ) return ;
44
+ Debug . Log ( "Start " + nameof ( WebXRSubsystem ) ) ;
45
+ Instance = this ;
46
+ InternalStart ( ) ;
47
+ }
9
48
49
+ protected override void OnStop ( )
50
+ {
51
+ if ( Instance == null ) return ;
52
+ Debug . Log ( "Stop " + nameof ( WebXRSubsystem ) ) ;
53
+ Instance = null ;
54
+ }
55
+
56
+ protected override void OnDestroy ( )
57
+ {
58
+ if ( Instance == null ) return ;
59
+ Debug . Log ( "Destroy " + nameof ( WebXRSubsystem ) ) ;
60
+ Instance = null ;
61
+ }
62
+ #else
10
63
public class WebXRSubsystemDescriptor : SubsystemDescriptor < WebXRSubsystem >
11
64
{
12
65
}
@@ -51,6 +104,11 @@ protected override void OnDestroy()
51
104
Instance = null ;
52
105
}
53
106
107
+ private bool _running ;
108
+ public override bool running => _running ;
109
+
110
+ private static WebXRSubsystem Instance ;
111
+ #endif
54
112
private void UpdateControllersOnEnd ( )
55
113
{
56
114
if ( OnHandUpdate != null )
@@ -161,12 +219,7 @@ private void UpdateXRCameras()
161
219
}
162
220
}
163
221
164
- private bool _running ;
165
- public override bool running => _running ;
166
-
167
- private static WebXRSubsystem Instance ;
168
-
169
- private void InternalStart ( )
222
+ internal void InternalStart ( )
170
223
{
171
224
#if UNITY_WEBGL
172
225
Native . SetWebXREvents ( OnStartAR , OnStartVR , UpdateVisibilityState , OnEndXR , OnXRCapabilities , OnInputProfiles ) ;
@@ -570,4 +623,4 @@ bool GetHitTestPoseFromViewerHitTestPoseArray(ref WebXRHitPoseData hitPoseData)
570
623
return true ;
571
624
}
572
625
}
573
- }
626
+ }
0 commit comments