@@ -41,7 +41,26 @@ public GenericXRSDKSpatialMeshObserver(
41
41
BaseMixedRealityProfile profile = null ) : base ( spatialAwarenessSystem , name , priority , profile )
42
42
{ }
43
43
44
- protected virtual bool ? IsActiveLoader => true ;
44
+ private IReadOnlyList < GenericXRSDKSpatialMeshObserver > observersCache ;
45
+
46
+ protected virtual bool ? IsActiveLoader
47
+ {
48
+ get
49
+ {
50
+ #if XR_MANAGEMENT_ENABLED
51
+ if ( XRGeneralSettings . Instance != null
52
+ && XRGeneralSettings . Instance . Manager != null
53
+ && XRGeneralSettings . Instance . Manager . activeLoader != null )
54
+ {
55
+ return true ;
56
+ }
57
+
58
+ return null ;
59
+ #else
60
+ return false ;
61
+ #endif
62
+ }
63
+ }
45
64
46
65
/// <inheritdoc />
47
66
public override void Enable ( )
@@ -58,6 +77,7 @@ public override void Enable()
58
77
return ;
59
78
}
60
79
80
+ ConfigureObserverVolume ( ) ;
61
81
base . Enable ( ) ;
62
82
}
63
83
@@ -73,30 +93,16 @@ private async void EnableIfLoaderBecomesActive()
73
93
#region BaseSpatialObserver Implementation
74
94
75
95
private XRMeshSubsystem meshSubsystem ;
76
-
77
- /// <summary>
78
- /// Creates the XRMeshSubsystem and handles the desired startup behavior.
79
- /// </summary>
80
- protected override void CreateObserver ( )
81
- {
82
- if ( Service == null
96
+ private XRMeshSubsystem MeshSubsystem => meshSubsystem != null && meshSubsystem . running
97
+ ? meshSubsystem :
83
98
#if XR_MANAGEMENT_ENABLED
84
- || XRGeneralSettings . Instance == null || XRGeneralSettings . Instance . Manager == null || XRGeneralSettings . Instance . Manager . activeLoader == null
85
- #endif // XR_MANAGEMENT_ENABLED
86
- ) { return ; }
87
-
88
- #if XR_MANAGEMENT_ENABLED
89
- meshSubsystem = XRGeneralSettings . Instance . Manager . activeLoader . GetLoadedSubsystem < XRMeshSubsystem > ( ) ;
99
+ meshSubsystem = IsActiveLoader ?? false
100
+ ? XRGeneralSettings . Instance . Manager . activeLoader . GetLoadedSubsystem < XRMeshSubsystem > ( )
101
+ : null ;
90
102
#else
91
103
meshSubsystem = XRSubsystemHelpers . MeshSubsystem ;
92
104
#endif // XR_MANAGEMENT_ENABLED
93
105
94
- if ( meshSubsystem != null )
95
- {
96
- ConfigureObserverVolume ( ) ;
97
- }
98
- }
99
-
100
106
/// <summary>
101
107
/// Implements proper cleanup of the SurfaceObserver.
102
108
/// </summary>
@@ -119,15 +125,15 @@ protected override int LookupTriangleDensity(SpatialAwarenessMeshLevelOfDetail l
119
125
{
120
126
// For non-custom levels, the enum value is the appropriate triangles per cubic meter.
121
127
int level = ( int ) levelOfDetail ;
122
- if ( meshSubsystem != null )
128
+ if ( MeshSubsystem != null )
123
129
{
124
130
if ( levelOfDetail == SpatialAwarenessMeshLevelOfDetail . Unlimited )
125
131
{
126
- meshSubsystem . meshDensity = 1 ;
132
+ MeshSubsystem . meshDensity = 1 ;
127
133
}
128
134
else
129
135
{
130
- meshSubsystem . meshDensity = level / ( float ) SpatialAwarenessMeshLevelOfDetail . Fine ; // For now, map Coarse to 0.0 and Fine to 1.0
136
+ MeshSubsystem . meshDensity = level / ( float ) SpatialAwarenessMeshLevelOfDetail . Fine ; // For now, map Coarse to 0.0 and Fine to 1.0
131
137
}
132
138
}
133
139
return level ;
@@ -215,9 +221,9 @@ public override void Resume()
215
221
216
222
using ( ResumePerfMarker . Auto ( ) )
217
223
{
218
- if ( meshSubsystem != null && ! meshSubsystem . running )
224
+ if ( MeshSubsystem != null && ! MeshSubsystem . running )
219
225
{
220
- meshSubsystem . Start ( ) ;
226
+ MeshSubsystem . Start ( ) ;
221
227
}
222
228
223
229
// We want the first update immediately.
@@ -241,9 +247,9 @@ public override void Suspend()
241
247
242
248
using ( SuspendPerfMarker . Auto ( ) )
243
249
{
244
- if ( meshSubsystem != null && meshSubsystem . running )
250
+ if ( MeshSubsystem != null && MeshSubsystem . running )
245
251
{
246
- meshSubsystem . Stop ( ) ;
252
+ MeshSubsystem . Stop ( ) ;
247
253
}
248
254
249
255
// UpdateObserver keys off of this value to stop observing.
@@ -293,7 +299,7 @@ public override void ClearObservations()
293
299
/// </summary>
294
300
private void UpdateObserver ( )
295
301
{
296
- if ( Service == null || meshSubsystem == null ) { return ; }
302
+ if ( Service == null || MeshSubsystem == null ) { return ; }
297
303
298
304
using ( UpdateObserverPerfMarker . Auto ( ) )
299
305
{
@@ -325,7 +331,7 @@ private void UpdateObserver()
325
331
// The application can update the observer volume at any time, make sure we are using the latest.
326
332
ConfigureObserverVolume ( ) ;
327
333
328
- if ( meshSubsystem . TryGetMeshInfos ( meshInfos ) )
334
+ if ( MeshSubsystem . TryGetMeshInfos ( meshInfos ) )
329
335
{
330
336
UpdateMeshes ( meshInfos ) ;
331
337
}
@@ -368,7 +374,7 @@ private void RequestMesh(MeshId meshId)
368
374
newMesh . GameObject . SetActive ( true ) ;
369
375
}
370
376
371
- meshSubsystem . GenerateMeshAsync ( meshId , newMesh . Filter . mesh , newMesh . Collider , MeshVertexAttributes . Normals , ( MeshGenerationResult meshGenerationResult ) => MeshGenerationAction ( meshGenerationResult ) ) ;
377
+ MeshSubsystem . GenerateMeshAsync ( meshId , newMesh . Filter . mesh , newMesh . Collider , MeshVertexAttributes . Normals , ( MeshGenerationResult meshGenerationResult ) => MeshGenerationAction ( meshGenerationResult ) ) ;
372
378
outstandingMeshObject = newMesh ;
373
379
}
374
380
}
@@ -439,7 +445,7 @@ protected void ReclaimMeshObject(SpatialAwarenessMeshObject availableMeshObject)
439
445
/// </summary>
440
446
protected virtual void ConfigureObserverVolume ( )
441
447
{
442
- if ( meshSubsystem == null
448
+ if ( MeshSubsystem == null
443
449
|| ( oldObserverOrigin == ObserverOrigin
444
450
&& oldObservationExtents == ObservationExtents
445
451
&& oldObserverVolumeType == ObserverVolumeType ) )
@@ -453,7 +459,7 @@ protected virtual void ConfigureObserverVolume()
453
459
switch ( ObserverVolumeType )
454
460
{
455
461
case VolumeType . AxisAlignedCube :
456
- meshSubsystem . SetBoundingVolume ( ObserverOrigin , ObservationExtents ) ;
462
+ MeshSubsystem . SetBoundingVolume ( ObserverOrigin , ObservationExtents ) ;
457
463
break ;
458
464
459
465
default :
@@ -590,7 +596,7 @@ public override void Initialize()
590
596
{
591
597
base . Initialize ( ) ;
592
598
593
- if ( Service == null || meshSubsystem == null ) { return ; }
599
+ if ( Service == null || MeshSubsystem == null ) { return ; }
594
600
595
601
if ( RuntimeSpatialMeshPrefab != null )
596
602
{
0 commit comments