@@ -95,28 +95,26 @@ public class SpatialMappingObserver : SpatialMappingSource
9595 /// </summary>
9696 public ObserverStates ObserverState { get ; private set ; }
9797
98+ /// <summary>
99+ /// Represents the center of the playspace.
100+ /// </summary>
101+ private Vector3 observerOrigin ;
102+
98103 protected override void Awake ( )
99104 {
100105 base . Awake ( ) ;
101106
102107 observer = new SurfaceObserver ( ) ;
103108 ObserverState = ObserverStates . Stopped ;
104- observer . SetVolumeAsAxisAlignedBox ( Vector3 . zero , Extents ) ;
105- }
106-
107- /// <summary>
108- /// Called when the GameObject is initialized.
109- /// </summary>
110- private void Start ( )
111- {
109+ observerOrigin = Vector3 . zero ;
112110 }
113111
114112 /// <summary>
115113 /// Can be called to override the default origin for the observed volume
116114 /// </summary>
117115 public void SetObserverOrigin ( Vector3 origin )
118116 {
119- observer . SetVolumeAsAxisAlignedBox ( origin , Extents ) ;
117+ observerOrigin = origin ;
120118 }
121119
122120 /// <summary>
@@ -141,6 +139,7 @@ private void Update()
141139 // update request, request updates for the spatial mapping data.
142140 else if ( surfaceWorkOutstanding == false && ( Time . time - updateTime ) >= TimeBetweenUpdates )
143141 {
142+ observer . SetVolumeAsAxisAlignedBox ( observerOrigin , Extents ) ;
144143 observer . Update ( SurfaceObserver_OnSurfaceChanged ) ;
145144 updateTime = Time . time ;
146145 }
@@ -155,6 +154,20 @@ public void StartObserving()
155154 if ( ObserverState != ObserverStates . Running )
156155 {
157156 Debug . Log ( "Starting the observer." ) ;
157+ // on device, this isn't necessary, but sometimes in the emulator the observer
158+ // won't realize that it hasn't already sent you the surfaces, and since the surfaces
159+ // don't really get updated in the emulator you'll end up getting no surfaces at all.
160+ if ( surfaces . Count == 0 )
161+ {
162+ if ( observer != null )
163+ {
164+ observer . Dispose ( ) ;
165+ observer = null ;
166+ }
167+
168+ observer = new SurfaceObserver ( ) ;
169+ }
170+
158171 ObserverState = ObserverStates . Running ;
159172
160173 // We want the first update immediately.
0 commit comments