Skip to content

Commit 5a979c2

Browse files
Merge branch 'mrtk_development' into vNEXT-MouseNotifications
# Conflicts: # Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Pointers/BaseControllerPointer.cs
2 parents 8ed60df + 4598c39 commit 5a979c2

File tree

103 files changed

+1525
-396
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1525
-396
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ Assets/ThirdParty/
5454
Assets/ThirdParty.meta
5555
Assets/TextMesh Pro.meta
5656
Assets/TextMesh Pro/
57+
--Version/

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.MixedReality.Toolkit.Core.Managers;
88
using Microsoft.MixedReality.Toolkit.Core.Utilities;
99
using System.Collections.Generic;
10+
using Microsoft.MixedReality.Toolkit.Core.Utilities.Async;
1011
using UnityEngine;
1112
using UnityEngine.Experimental.XR;
1213

@@ -17,9 +18,6 @@ namespace Microsoft.MixedReality.Toolkit.Examples.Demos
1718
/// </summary>
1819
public class BoundaryVisualizationDemo : MonoBehaviour, IMixedRealityBoundaryHandler
1920
{
20-
private IMixedRealityBoundarySystem BoundaryManager => boundaryManager ?? (boundaryManager = MixedRealityManager.Instance.GetManager<IMixedRealityBoundarySystem>());
21-
private IMixedRealityBoundarySystem boundaryManager = null;
22-
2321
private GameObject markerParent;
2422
private readonly List<GameObject> markers = new List<GameObject>();
2523

@@ -50,7 +48,7 @@ private void Awake()
5048
private void Start()
5149
{
5250

53-
if (BoundaryManager != null)
51+
if (MixedRealityManager.BoundarySystem != null)
5452
{
5553
if (markers.Count == 0)
5654
{
@@ -61,24 +59,25 @@ private void Start()
6159

6260
private void Update()
6361
{
64-
if (BoundaryManager != null)
62+
if (MixedRealityManager.BoundarySystem != null)
6563
{
66-
BoundaryManager.ShowFloor = showFloor;
67-
BoundaryManager.ShowPlayArea = showPlayArea;
68-
BoundaryManager.ShowTrackedArea = showTrackedArea;
69-
BoundaryManager.ShowBoundaryWalls = showBoundaryWalls;
70-
BoundaryManager.ShowBoundaryCeiling = showBoundaryCeiling;
64+
MixedRealityManager.BoundarySystem.ShowFloor = showFloor;
65+
MixedRealityManager.BoundarySystem.ShowPlayArea = showPlayArea;
66+
MixedRealityManager.BoundarySystem.ShowTrackedArea = showTrackedArea;
67+
MixedRealityManager.BoundarySystem.ShowBoundaryWalls = showBoundaryWalls;
68+
MixedRealityManager.BoundarySystem.ShowBoundaryCeiling = showBoundaryCeiling;
7169
}
7270
}
7371

74-
private void OnEnable()
72+
private async void OnEnable()
7573
{
76-
BoundaryManager.Register(gameObject);
74+
await new WaitUntil(() => MixedRealityManager.BoundarySystem != null);
75+
MixedRealityManager.BoundarySystem.Register(gameObject);
7776
}
7877

7978
private void OnDisable()
8079
{
81-
BoundaryManager.Unregister(gameObject);
80+
MixedRealityManager.BoundarySystem?.Unregister(gameObject);
8281
}
8382

8483
#endregion MonoBehaviour Implementation
@@ -105,7 +104,7 @@ private void AddMarkers()
105104
float widthRect;
106105
float heightRect;
107106

108-
if (!BoundaryManager.TryGetRectangularBoundsParams(out centerRect, out angleRect, out widthRect, out heightRect))
107+
if (!MixedRealityManager.BoundarySystem.TryGetRectangularBoundsParams(out centerRect, out angleRect, out widthRect, out heightRect))
109108
{
110109
// If we have no boundary manager or rectangular bounds we will show no indicators
111110
return;
@@ -136,12 +135,12 @@ private void AddMarkers()
136135

137136
Material material = null;
138137
// Check inscribed rectangle first
139-
if (BoundaryManager.Contains(position, Boundary.Type.PlayArea))
138+
if (MixedRealityManager.BoundarySystem.Contains(position, Boundary.Type.PlayArea))
140139
{
141140
material = visualizationProfile.PlayAreaMaterial;
142141
}
143142
// Then check geometry
144-
else if (BoundaryManager.Contains(position, Boundary.Type.TrackedArea))
143+
else if (MixedRealityManager.BoundarySystem.Contains(position, Boundary.Type.TrackedArea))
145144
{
146145
material = visualizationProfile.TrackedAreaMaterial;
147146
}

Assets/MixedRealityToolkit-SDK/Features/Diagnostics.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System;
5+
using System.Linq;
6+
using System.Diagnostics;
7+
8+
namespace Microsoft.MixedReality.Toolkit.SDK.DiagnosticsSystem
9+
{
10+
internal class CpuUseTracker
11+
{
12+
private TimeSpan? processorTime;
13+
private Process currentProcess = Process.GetCurrentProcess();
14+
private TimeSpan[] readings = new TimeSpan[20];
15+
int index = 0;
16+
17+
public void Reset()
18+
{
19+
processorTime = null;
20+
}
21+
22+
public double GetReadingInMs()
23+
{
24+
if (!processorTime.HasValue)
25+
{
26+
processorTime = currentProcess.TotalProcessorTime;
27+
return 0;
28+
}
29+
30+
var currentTime = currentProcess.TotalProcessorTime;
31+
var diff = currentTime - processorTime.Value;
32+
processorTime = currentTime;
33+
34+
readings[index] = diff;
35+
index = (index + 1) % readings.Length;
36+
37+
return Math.Round(readings.Average(t => t.TotalMilliseconds), 2);
38+
}
39+
}
40+
}

Assets/MixedRealityToolkit-SDK/Features/Diagnostics/CpuUseTracker.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using Microsoft.MixedReality.Toolkit.Core.EventDatum.Diagnostics;
5+
using Microsoft.MixedReality.Toolkit.Core.Interfaces.Diagnostics;
6+
using System;
7+
using System.Text;
8+
using UnityEngine;
9+
10+
namespace Microsoft.MixedReality.Toolkit.SDK.DiagnosticsSystem
11+
{
12+
/// <summary>
13+
/// Behavior class for showing Diagnostic information. Implements <see cref="IMixedRealityDiagnosticsHandler"/>
14+
/// to manage setting updates.
15+
/// </summary>
16+
public class DiagnosticsHandler : MonoBehaviour, IMixedRealityDiagnosticsHandler
17+
{
18+
private bool showCpu;
19+
private bool ShowCpu
20+
{
21+
get { return showCpu; }
22+
set
23+
{
24+
if (showCpu != value)
25+
{
26+
showCpu = value;
27+
if (!showCpu)
28+
{
29+
cpuUseTracker.Reset();
30+
}
31+
}
32+
}
33+
}
34+
35+
private bool ShowFps { get; set; }
36+
private bool ShowMemory { get; set; }
37+
38+
private bool isShowingInformation;
39+
40+
private CpuUseTracker cpuUseTracker = new CpuUseTracker();
41+
private MemoryUseTracker memoryUseTracker = new MemoryUseTracker();
42+
private FpsUseTracker fpsUseTracker = new FpsUseTracker();
43+
StringBuilder displayText = new StringBuilder();
44+
45+
private GUIStyle style = new GUIStyle()
46+
{
47+
alignment = TextAnchor.UpperLeft,
48+
normal = new GUIStyleState()
49+
{
50+
textColor = new Color(0, 0, 0.5f, 1)
51+
}
52+
};
53+
54+
private Rect rect = new Rect();
55+
56+
/// <summary>
57+
/// Updates the diagnostic settings
58+
/// </summary>
59+
/// <param name="eventData"><see cref="DiagnosticsEventData"/> coming in</param>
60+
public void OnDiagnosticSettingsChanged(DiagnosticsEventData eventData)
61+
{
62+
this.ShowCpu = eventData.ShowCpu;
63+
this.ShowMemory = eventData.ShowMemory;
64+
this.ShowFps = eventData.ShowFps;
65+
this.enabled = eventData.Visible;
66+
}
67+
68+
private void UpdateIsShowingInformation()
69+
{
70+
isShowingInformation = ShowCpu ||
71+
ShowFps ||
72+
ShowMemory;
73+
}
74+
75+
private void Update()
76+
{
77+
UpdateIsShowingInformation();
78+
79+
if (!isShowingInformation)
80+
{
81+
return;
82+
}
83+
84+
displayText.Clear();
85+
86+
if (ShowFps)
87+
{
88+
var timeInSeconds = fpsUseTracker.GetFpsInSeconds();
89+
displayText.AppendLine($"Fps: {Math.Round(1.0f / timeInSeconds, 2)}");
90+
displayText.AppendLine($"Frame Time: {Math.Round(timeInSeconds * 1000, 2)} ms");
91+
}
92+
93+
if (ShowCpu)
94+
{
95+
var reading = cpuUseTracker.GetReadingInMs();
96+
displayText.AppendLine($"CPU Time: {reading} ms");
97+
}
98+
99+
if (ShowMemory)
100+
{
101+
var reading = memoryUseTracker.GetReading();
102+
displayText.AppendLine($"Memory: {Math.Round(BytesToMB(reading.GCMemoryInBytes), 2)} MB");
103+
}
104+
}
105+
106+
private void OnGUI()
107+
{
108+
if (!isShowingInformation || displayText.Length == 0)
109+
{
110+
return;
111+
}
112+
113+
int w = Screen.width, h = Screen.height;
114+
115+
rect.Set(0, 0, w, h * 2 / 100);
116+
117+
style.fontSize = h * 2 / 100;
118+
GUI.Label(rect, displayText.ToString(), style);
119+
}
120+
121+
private static float BytesToMB(long bytes)
122+
{
123+
return bytes / (float)(1024 * 1024);
124+
}
125+
}
126+
}

Assets/MixedRealityToolkit-SDK/Features/Diagnostics/DiagnosticsHandler.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System.Linq;
5+
using UnityEngine;
6+
7+
namespace Microsoft.MixedReality.Toolkit.SDK.DiagnosticsSystem
8+
{
9+
internal class FpsUseTracker
10+
{
11+
private int index = 0;
12+
private float[] timings = new float[10];
13+
14+
public float GetFpsInSeconds()
15+
{
16+
timings[index] = Time.unscaledDeltaTime;
17+
index = (index + 1) % timings.Length;
18+
19+
return timings.Average();
20+
}
21+
}
22+
}

Assets/MixedRealityToolkit-SDK/Features/Diagnostics/FpsUseTracker.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)