1212namespace Microsoft . MixedReality . Toolkit . Examples . Demos
1313{
1414 /// <summary>
15- /// Demo class to show different ways of using the boundary API .
15+ /// Demo class to show different ways of using the boundary system and visualizing the data .
1616 /// </summary>
17- public class BoundaryIndicatorDemo : MonoBehaviour , IMixedRealityBoundaryHandler
17+ public class BoundaryVisualizationDemo : MonoBehaviour , IMixedRealityBoundaryHandler
1818 {
1919 private IMixedRealityBoundarySystem BoundaryManager => boundaryManager ?? ( boundaryManager = MixedRealityManager . Instance . GetManager < IMixedRealityBoundarySystem > ( ) ) ;
2020 private IMixedRealityBoundarySystem boundaryManager = null ;
2121
2222 private readonly List < GameObject > markers = new List < GameObject > ( ) ;
2323
24- #region MonoBehaviour Implementation
24+ [ SerializeField ]
25+ private bool showFloor = true ;
2526
26- private void OnEnable ( )
27- {
28- BoundaryManager . Register ( gameObject ) ;
29- }
27+ [ SerializeField ]
28+ private bool showPlayArea = true ;
29+
30+ #region MonoBehaviour Implementation
3031
3132 private void Start ( )
3233 {
33- if ( BoundaryManager != null && BoundaryManager . EnablePlatformBoundaryRendering )
34+ if ( BoundaryManager != null )
3435 {
3536 if ( markers . Count == 0 )
3637 {
37- AddIndicators ( ) ;
38+ AddMarkers ( ) ;
3839 }
3940 }
4041 }
4142
43+ private void Update ( )
44+ {
45+ if ( BoundaryManager != null )
46+ {
47+ BoundaryManager . ShowFloor = showFloor ;
48+ BoundaryManager . ShowPlayArea = showPlayArea ;
49+ }
50+ }
51+
52+ private void OnEnable ( )
53+ {
54+ BoundaryManager . Register ( gameObject ) ;
55+ }
56+
4257 private void OnDisable ( )
4358 {
4459 BoundaryManager . Unregister ( gameObject ) ;
@@ -51,22 +66,7 @@ private void OnDisable()
5166 /// <inheritdoc />
5267 public void OnBoundaryVisualizationChanged ( BoundaryEventData eventData )
5368 {
54- if ( eventData . IsPlatformRenderingEnabled )
55- {
56- if ( markers . Count == 0 )
57- {
58- AddIndicators ( ) ;
59- }
60- }
61- else
62- {
63- for ( int i = 0 ; i < markers . Count ; i ++ )
64- {
65- Destroy ( markers [ i ] ) ;
66- }
67-
68- markers . Clear ( ) ;
69- }
69+ Debug . Log ( "[BoundaryVisualizationDemo] Boundary visualization changed." ) ;
7070 }
7171
7272 #endregion IMixedRealityBoundaryHandler Implementation
@@ -75,7 +75,7 @@ public void OnBoundaryVisualizationChanged(BoundaryEventData eventData)
7575 /// Displays the boundary as an array of spheres where spheres in the
7676 /// bounds are a different color.
7777 /// </summary>
78- private void AddIndicators ( )
78+ private void AddMarkers ( )
7979 {
8080 // Get the rectangular bounds.
8181 Vector2 centerRect ;
@@ -111,14 +111,8 @@ private void AddIndicators()
111111 {
112112 Vector3 offset = new Vector3 ( xIndex * indicatorDistance , 0.0f , yIndex * indicatorDistance ) ;
113113 Vector3 position = corner + offset ;
114- GameObject marker = GameObject . CreatePrimitive ( PrimitiveType . Sphere ) ;
115- marker . transform . SetParent ( transform ) ;
116- marker . transform . position = position ;
117- marker . transform . localScale = Vector3 . one * indicatorScale ;
118-
119- // Get the desired material for the marker.
120- Material material = visualizationProfile . FloorPlaneMaterial ;
121114
115+ Material material = null ;
122116 // Check inscribed rectangle first
123117 if ( BoundaryManager . Contains ( position , Boundary . Type . PlayArea ) )
124118 {
@@ -130,9 +124,16 @@ private void AddIndicators()
130124 material = visualizationProfile . TrackedAreaMaterial ;
131125 }
132126
133- marker . GetComponent < MeshRenderer > ( ) . sharedMaterial = material ;
134-
135- markers . Add ( marker ) ;
127+ if ( material != null )
128+ {
129+ GameObject marker = GameObject . CreatePrimitive ( PrimitiveType . Sphere ) ;
130+ marker . name = "Boundary Demo Marker" ;
131+ marker . transform . SetParent ( transform ) ;
132+ marker . transform . position = position ;
133+ marker . transform . localScale = Vector3 . one * indicatorScale ;
134+ marker . GetComponent < MeshRenderer > ( ) . sharedMaterial = material ;
135+ markers . Add ( marker ) ;
136+ }
136137 }
137138 }
138139 }
0 commit comments