Skip to content

Commit 063351c

Browse files
finished up boundary events
1 parent 8a93b62 commit 063351c

File tree

6 files changed

+91
-14
lines changed

6 files changed

+91
-14
lines changed

Assets/MixedRealityToolkit-Examples/Demos/Boundary/Scripts/BoundaryIndicatorDemo.cs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using System.Collections.Generic;
45
using Microsoft.MixedReality.Toolkit.Internal.Definitions.BoundarySystem;
6+
using Microsoft.MixedReality.Toolkit.Internal.EventDatum.Boundary;
57
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.BoundarySystem;
68
using Microsoft.MixedReality.Toolkit.Internal.Managers;
79
using UnityEngine;
@@ -12,22 +14,52 @@ namespace Microsoft.MixedReality.Toolkit.Examples.Demos
1214
/// <summary>
1315
/// Demo class to show different ways of using the boundary API.
1416
/// </summary>
15-
public class BoundaryIndicatorDemo : MonoBehaviour
17+
public class BoundaryIndicatorDemo : MonoBehaviour, IMixedRealityBoundaryHandler
1618
{
17-
/// <summary>
18-
/// Boundary system implementation.
19-
/// </summary
20-
private IMixedRealityBoundarySystem boundaryManager = null;
2119
private IMixedRealityBoundarySystem BoundaryManager => boundaryManager ?? (boundaryManager = MixedRealityManager.Instance.GetManager<IMixedRealityBoundarySystem>());
20+
private IMixedRealityBoundarySystem boundaryManager = null;
21+
22+
private readonly List<GameObject> markers = new List<GameObject>();
23+
24+
#region MonoBehaviour Implementation
25+
26+
private void OnEnable()
27+
{
28+
BoundaryManager.Register(gameObject);
29+
}
2230

23-
private void Start()
31+
private void OnDisable()
2432
{
25-
if (MixedRealityManager.HasActiveProfile && MixedRealityManager.Instance.ActiveProfile.IsBoundarySystemEnabled)
33+
BoundaryManager.Unregister(gameObject);
34+
}
35+
36+
#endregion MonoBehaviour Implementation
37+
38+
#region IMixedRealityBoundaryHandler Implementation
39+
40+
/// <inheritdoc />
41+
public void OnBoundaryVisualizationChanged(BoundaryEventData eventData)
42+
{
43+
if (eventData.IsPlatformRenderingEnabled)
2644
{
27-
AddIndicators();
45+
if (markers.Count == 0)
46+
{
47+
AddIndicators();
48+
}
49+
}
50+
else
51+
{
52+
for (int i = 0; i < markers.Count; i++)
53+
{
54+
Destroy(markers[i]);
55+
}
56+
57+
markers.Clear();
2858
}
2959
}
3060

61+
#endregion IMixedRealityBoundaryHandler Implementation
62+
3163
/// <summary>
3264
/// Displays the boundary as an array of spheres where spheres in the
3365
/// bounds are a different color.
@@ -39,7 +71,8 @@ private void AddIndicators()
3971
float angleRect;
4072
float widthRect;
4173
float heightRect;
42-
if ((BoundaryManager == null) || !BoundaryManager.TryGetRectangularBoundsParams(out centerRect, out angleRect, out widthRect, out heightRect))
74+
75+
if (!BoundaryManager.TryGetRectangularBoundsParams(out centerRect, out angleRect, out widthRect, out heightRect))
4376
{
4477
// If we have no boundary manager or rectangular bounds we will show no indicators
4578
return;
@@ -87,6 +120,8 @@ private void AddIndicators()
87120
}
88121

89122
marker.GetComponent<MeshRenderer>().sharedMaterial = material;
123+
124+
markers.Add(marker);
90125
}
91126
}
92127
}

Assets/MixedRealityToolkit-SDK/Features/Boundary/Scripts/MixedRealityBoundarySystem.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.BoundarySystem;
66
using Microsoft.MixedReality.Toolkit.Internal.Managers;
77
using Microsoft.MixedReality.Toolkit.Internal.Utilities;
8+
using System.Collections;
89
using System.Collections.Generic;
910
using UnityEngine;
1011
using UnityEngine.EventSystems;
@@ -87,6 +88,29 @@ public override void Unregister(GameObject listener)
8788

8889
#endregion
8990

91+
#region IMixedRealityEventSource Implementation
92+
93+
/// <inheritdoc />
94+
bool IEqualityComparer.Equals(object x, object y)
95+
{
96+
// There shouldn't be other Boundary Managers to compare to.
97+
return false;
98+
}
99+
100+
/// <inheritdoc />
101+
public int GetHashCode(object obj)
102+
{
103+
return Mathf.Abs(SourceName.GetHashCode());
104+
}
105+
106+
/// <inheritdoc />
107+
public uint SourceId { get; } = 0;
108+
109+
/// <inheritdoc />
110+
public string SourceName { get; } = "Mixed Reality Boundary System";
111+
112+
#endregion IMixedRealityEventSource Implementation
113+
90114
#region IMixedRealityBoundarySystem Implementation
91115

92116
/// <inheritdoc/>
@@ -266,6 +290,7 @@ public GameObject CreateFloorPlaneVisualization()
266290
private InscribedRectangle rectangularBounds = null;
267291

268292
private GameObject currentPlayArea;
293+
269294
private GameObject currentFloorPlane;
270295

271296
/// <summary>

Assets/MixedRealityToolkit-SDK/Profiles/DefaultMixedRealityConfigurationProfile.asset

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ MonoBehaviour:
1212
m_Name: DefaultMixedRealityConfigurationProfile
1313
m_EditorClassIdentifier:
1414
initialManagerTypes:
15-
- reference: Microsoft.MixedReality.Toolkit.SDK.BoundarySystem.MixedRealityBoundaryManager,
16-
Microsoft.MixedReality.Toolkit.SDK
1715
- reference: Microsoft.MixedReality.Toolkit.SDK.Input.MixedRealityInputManager,
1816
Microsoft.MixedReality.Toolkit.SDK
17+
- reference: Microsoft.MixedReality.Toolkit.SDK.BoundarySystem.MixedRealityBoundaryManager,
18+
Microsoft.MixedReality.Toolkit.SDK
1919
targetExperienceScale: 3
2020
enableCameraProfile: 1
2121
cameraProfile: {fileID: 11400000, guid: b9a895b32a50a7f45b1e4da728d50741, type: 2}
@@ -35,6 +35,6 @@ MonoBehaviour:
3535
boundarySystemType:
3636
reference: Microsoft.MixedReality.Toolkit.SDK.BoundarySystem.MixedRealityBoundaryManager,
3737
Microsoft.MixedReality.Toolkit.SDK
38-
enablePlatformBoundaryRendering: 0
38+
enablePlatformBoundaryRendering: 1
3939
boundaryVisualizationProfile: {fileID: 11400000, guid: c1f4aa213e301a446aca3858e6f4ad17,
4040
type: 2}

Assets/MixedRealityToolkit/_Core/EventDatum/Boundary/BoundaryEventData.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.BoundarySystem;
45
using UnityEngine.EventSystems;
56

67
namespace Microsoft.MixedReality.Toolkit.Internal.EventDatum.Boundary
@@ -10,12 +11,21 @@ namespace Microsoft.MixedReality.Toolkit.Internal.EventDatum.Boundary
1011
/// </summary>
1112
public class BoundaryEventData : GenericBaseEventData
1213
{
14+
/// <summary>
15+
/// The new state of the Boundary systems platform rendering.
16+
/// </summary>
17+
public bool IsPlatformRenderingEnabled { get; private set; }
18+
1319
/// <summary>
1420
/// Constructor.
1521
/// </summary>
1622
/// <param name="eventSystem"></param>
17-
public BoundaryEventData(EventSystem eventSystem) : base(eventSystem)
23+
public BoundaryEventData(EventSystem eventSystem) : base(eventSystem) { }
24+
25+
public void Initialize(IMixedRealityBoundarySystem boundarySystem, bool isPlatformRenderingEnabled)
1826
{
27+
base.BaseInitialize(boundarySystem);
28+
IsPlatformRenderingEnabled = isPlatformRenderingEnabled;
1929
}
2030
}
2131
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using Microsoft.MixedReality.Toolkit.Internal.EventDatum.Boundary;
45
using UnityEngine.EventSystems;
56

67
namespace Microsoft.MixedReality.Toolkit.Internal.Interfaces.BoundarySystem
78
{
89
public interface IMixedRealityBoundaryHandler : IEventSystemHandler
910
{
11+
/// <summary>
12+
/// Raised when the boundary visualization has changed.
13+
/// </summary>
14+
/// <param name="eventData"></param>
15+
void OnBoundaryVisualizationChanged(BoundaryEventData eventData);
1016
}
1117
}

Assets/MixedRealityToolkit/_Core/Interfaces/BoundarySystem/IMixedRealityBoundarySystem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using Microsoft.MixedReality.Toolkit.Internal.Definitions.Utilities;
5+
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.Events;
56
using UnityEngine;
67
using UnityEngine.Experimental.XR;
78

@@ -11,7 +12,7 @@ namespace Microsoft.MixedReality.Toolkit.Internal.Interfaces.BoundarySystem
1112
/// Manager interface for a Boundary system in the Mixed Reality Toolkit
1213
/// All replacement systems for providing Boundary functionality should derive from this interface
1314
/// </summary>
14-
public interface IMixedRealityBoundarySystem : IMixedRealityManager
15+
public interface IMixedRealityBoundarySystem : IMixedRealityEventSystem, IMixedRealityEventSource
1516
{
1617
/// <summary>
1718
/// The scale (ex: World Scale) of the experience.

0 commit comments

Comments
 (0)