55using Microsoft . MixedReality . Toolkit . Core . Definitions . Utilities ;
66using Microsoft . MixedReality . Toolkit . Core . EventDatum . Boundary ;
77using Microsoft . MixedReality . Toolkit . Core . Interfaces . BoundarySystem ;
8- using Microsoft . MixedReality . Toolkit . Core . Services ;
98using Microsoft . MixedReality . Toolkit . Core . Utilities ;
109using System . Collections ;
1110using System . Collections . Generic ;
1413using UnityEngine . Experimental . XR ;
1514using UnityEngine . XR ;
1615
17- namespace Microsoft . MixedReality . Toolkit . SDK . BoundarySystem
16+ namespace Microsoft . MixedReality . Toolkit . Core . Services . BoundarySystem
1817{
1918 /// <summary>
2019 /// The Boundary system controls the presentation and display of the users boundary in a scene.
2120 /// </summary>
22- public class MixedRealityBoundaryManager : BaseEventSystem , IMixedRealityBoundarySystem
21+ public class MixedRealityBoundarySystem : BaseEventSystem , IMixedRealityBoundarySystem
2322 {
2423 #region IMixedRealityService Implementation
2524
@@ -28,15 +27,8 @@ public class MixedRealityBoundaryManager : BaseEventSystem, IMixedRealityBoundar
2827 /// <inheritdoc/>
2928 public override void Initialize ( )
3029 {
31- base . Initialize ( ) ;
32- InitializeInternal ( ) ;
33- }
30+ if ( ! Application . isPlaying ) { return ; }
3431
35- /// <summary>
36- /// Performs initialization tasks for the BoundaryManager.
37- /// </summary>
38- private void InitializeInternal ( )
39- {
4032 boundaryEventData = new BoundaryEventData ( EventSystem . current ) ;
4133
4234 Scale = MixedRealityToolkit . Instance . ActiveProfile . TargetExperienceScale ;
@@ -76,129 +68,107 @@ private void InitializeInternal()
7668 RaiseBoundaryVisualizationChanged ( ) ;
7769 }
7870
79- /// <inheritdoc/>
80- public override void Reset ( )
81- {
82- base . Reset ( ) ;
83- InitializeInternal ( ) ;
84- }
85-
8671 public override void Destroy ( )
8772 {
88- // Cleanup game objects created during execution.
89- if ( Application . isPlaying )
73+ // First, detach the child objects (we are tracking them separately)
74+ // and clean up the parent.
75+ if ( boundaryVisualizationParent != null )
9076 {
91- // First, detach the child objects (we are tracking them separately)
92- // and clean up the parent.
93- if ( boundaryVisualizationParent != null )
77+ boundaryVisualizationParent . transform . DetachChildren ( ) ;
78+
79+ if ( Application . isEditor )
9480 {
95- boundaryVisualizationParent . transform . DetachChildren ( ) ;
96- if ( Application . isEditor )
97- {
98- Object . DestroyImmediate ( boundaryVisualizationParent ) ;
99- }
100- else
101- {
102- Object . Destroy ( boundaryVisualizationParent ) ;
103- }
104- boundaryVisualizationParent = null ;
81+ Object . DestroyImmediate ( boundaryVisualizationParent ) ;
10582 }
106-
107- // Next, clean up the detached children.
108- if ( currentFloorObject != null )
83+ else
10984 {
110- if ( Application . isEditor )
111- {
112- Object . DestroyImmediate ( currentFloorObject ) ;
113- }
114- else
115- {
116- Object . Destroy ( currentFloorObject ) ;
117- }
118- currentFloorObject = null ;
85+ Object . Destroy ( boundaryVisualizationParent ) ;
11986 }
12087
121- if ( currentPlayAreaObject != null )
88+ boundaryVisualizationParent = null ;
89+ }
90+
91+ // Next, clean up the detached children.
92+ if ( currentFloorObject != null )
93+ {
94+ if ( Application . isEditor )
12295 {
123- if ( Application . isEditor )
124- {
125- Object . DestroyImmediate ( currentPlayAreaObject ) ;
126- }
127- else
128- {
129- Object . Destroy ( currentPlayAreaObject ) ;
130- }
131- currentPlayAreaObject = null ;
96+ Object . DestroyImmediate ( currentFloorObject ) ;
13297 }
133-
134- if ( currentTrackedAreaObject != null )
98+ else
13599 {
136- if ( Application . isEditor )
137- {
138- Object . DestroyImmediate ( currentTrackedAreaObject ) ;
139- }
140- else
141- {
142- Object . Destroy ( currentTrackedAreaObject ) ;
143- }
144- currentTrackedAreaObject = null ;
100+ Object . Destroy ( currentFloorObject ) ;
145101 }
102+ currentFloorObject = null ;
103+ }
146104
147- if ( currentBoundaryWallObject != null )
105+ if ( currentPlayAreaObject != null )
106+ {
107+ if ( Application . isEditor )
148108 {
149- if ( Application . isEditor )
150- {
151- Object . DestroyImmediate ( currentBoundaryWallObject ) ;
152- }
153- else
154- {
155- Object . Destroy ( currentBoundaryWallObject ) ;
156- }
157- currentBoundaryWallObject = null ;
109+ Object . DestroyImmediate ( currentPlayAreaObject ) ;
158110 }
111+ else
112+ {
113+ Object . Destroy ( currentPlayAreaObject ) ;
114+ }
115+ currentPlayAreaObject = null ;
116+ }
159117
160- if ( currentCeilingObject != null )
118+ if ( currentTrackedAreaObject != null )
119+ {
120+ if ( Application . isEditor )
161121 {
162- if ( Application . isEditor )
163- {
164- Object . DestroyImmediate ( currentCeilingObject ) ;
165- }
166- else
167- {
168- Object . Destroy ( currentCeilingObject ) ;
169- }
170- currentCeilingObject = null ;
122+ Object . DestroyImmediate ( currentTrackedAreaObject ) ;
171123 }
124+ else
125+ {
126+ Object . Destroy ( currentTrackedAreaObject ) ;
127+ }
128+ currentTrackedAreaObject = null ;
129+ }
172130
173- showFloor = false ;
174- showPlayArea = false ;
175- showTrackedArea = false ;
176- showBoundaryWalls = false ;
177- showCeiling = false ;
131+ if ( currentBoundaryWallObject != null )
132+ {
133+ if ( Application . isEditor )
134+ {
135+ Object . DestroyImmediate ( currentBoundaryWallObject ) ;
136+ }
137+ else
138+ {
139+ Object . Destroy ( currentBoundaryWallObject ) ;
140+ }
141+ currentBoundaryWallObject = null ;
142+ }
178143
179- RaiseBoundaryVisualizationChanged ( ) ;
144+ if ( currentCeilingObject != null )
145+ {
146+ if ( Application . isEditor )
147+ {
148+ Object . DestroyImmediate ( currentCeilingObject ) ;
149+ }
150+ else
151+ {
152+ Object . Destroy ( currentCeilingObject ) ;
153+ }
154+ currentCeilingObject = null ;
180155 }
181- }
182156
183- /// <summary>
184- /// Creates the parent for boundary visualization objects that need to teleport with the user.
185- /// </summary>
186- /// <returns>
187- /// The <see cref="GameObject"/> to which boundary visualizations will be parented.
188- /// </returns>
189- private GameObject CreateBoundaryVisualizationParent ( )
190- {
191- GameObject visualizationParent = new GameObject ( "Boundary System Visualizations" ) ;
192- visualizationParent . transform . parent = MixedRealityToolkit . Instance . MixedRealityPlayspace ;
157+ showFloor = false ;
158+ showPlayArea = false ;
159+ showTrackedArea = false ;
160+ showBoundaryWalls = false ;
161+ showCeiling = false ;
193162
194- return visualizationParent ;
163+ RaiseBoundaryVisualizationChanged ( ) ;
195164 }
196165
197166 /// <summary>
198167 /// Raises an event to indicate that the visualization of the boundary has been changed by the boundary system.
199168 /// </summary>
200169 private void RaiseBoundaryVisualizationChanged ( )
201170 {
171+ if ( ! Application . isPlaying ) { return ; }
202172 boundaryEventData . Initialize ( this , ShowFloor , ShowPlayArea , ShowTrackedArea , ShowBoundaryWalls , ShowBoundaryCeiling ) ;
203173 HandleEvent ( boundaryEventData , OnVisualizationChanged ) ;
204174 }
@@ -286,7 +256,20 @@ public int GetHashCode(object obj)
286256 /// <summary>
287257 /// Parent <see cref="GameObject"/> which will encapsulate all of the teleportable boundary visualizations.
288258 /// </summary>
289- private GameObject BoundaryVisualizationParent => boundaryVisualizationParent ?? ( boundaryVisualizationParent = CreateBoundaryVisualizationParent ( ) ) ;
259+ private GameObject BoundaryVisualizationParent
260+ {
261+ get
262+ {
263+ if ( boundaryVisualizationParent != null )
264+ {
265+ return boundaryVisualizationParent ;
266+ }
267+
268+ var visualizationParent = new GameObject ( "Boundary System Visualizations" ) ;
269+ visualizationParent . transform . parent = MixedRealityToolkit . Instance . MixedRealityPlayspace ;
270+ return boundaryVisualizationParent = visualizationParent ;
271+ }
272+ }
290273
291274 /// <summary>
292275 /// Layer used to tell the (non-floor) boundary objects to not accept raycasts
@@ -512,6 +495,8 @@ public bool TryGetRectangularBoundsParams(out Vector2 center, out float angle, o
512495 /// <inheritdoc/>
513496 public GameObject GetFloorVisualization ( )
514497 {
498+ if ( ! Application . isPlaying ) { return null ; }
499+
515500 if ( currentFloorObject != null )
516501 {
517502 return currentFloorObject ;
@@ -530,8 +515,8 @@ public GameObject GetFloorVisualization()
530515 currentFloorObject . name = "Boundary System Floor" ;
531516 currentFloorObject . transform . localScale = new Vector3 ( floorScale . x , boundaryObjectThickness , floorScale . y ) ;
532517 currentFloorObject . transform . Translate ( new Vector3 (
533- MixedRealityToolkit . Instance . MixedRealityPlayspace . position . x ,
534- FloorHeight . Value - ( currentFloorObject . transform . localScale . y * 0.5f ) ,
518+ MixedRealityToolkit . Instance . MixedRealityPlayspace . position . x ,
519+ FloorHeight . Value - ( currentFloorObject . transform . localScale . y * 0.5f ) ,
535520 MixedRealityToolkit . Instance . MixedRealityPlayspace . position . z ) ) ;
536521 currentFloorObject . GetComponent < Renderer > ( ) . sharedMaterial = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . FloorMaterial ;
537522
@@ -541,6 +526,8 @@ public GameObject GetFloorVisualization()
541526 /// <inheritdoc/>
542527 public GameObject GetPlayAreaVisualization ( )
543528 {
529+ if ( ! Application . isPlaying ) { return null ; }
530+
544531 if ( currentPlayAreaObject != null )
545532 {
546533 return currentPlayAreaObject ;
@@ -581,6 +568,8 @@ public GameObject GetPlayAreaVisualization()
581568 /// <inheritdoc/>
582569 public GameObject GetTrackedAreaVisualization ( )
583570 {
571+ if ( ! Application . isPlaying ) { return null ; }
572+
584573 if ( currentTrackedAreaObject != null )
585574 {
586575 return currentTrackedAreaObject ;
@@ -625,9 +614,10 @@ public GameObject GetTrackedAreaVisualization()
625614 return currentTrackedAreaObject ;
626615 }
627616
628- /// <inheritdoc/>
629617 public GameObject GetBoundaryWallVisualization ( )
630618 {
619+ if ( ! Application . isPlaying ) { return null ; }
620+
631621 if ( currentBoundaryWallObject != null )
632622 {
633623 return currentBoundaryWallObject ;
@@ -674,6 +664,8 @@ public GameObject GetBoundaryWallVisualization()
674664 /// <inheritdoc/>
675665 public GameObject GetBoundaryCeilingVisualization ( )
676666 {
667+ if ( ! Application . isPlaying ) { return null ; }
668+
677669 if ( currentCeilingObject != null )
678670 {
679671 return currentCeilingObject ;
0 commit comments