Skip to content

Commit d26e5fc

Browse files
authored
Merge pull request #9644 from keveleigh/diagnostics-mrc
Fix some diagnostics panel bugs
2 parents 707cb16 + f715782 commit d26e5fc

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

Assets/MRTK/Services/DiagnosticsSystem/MixedRealityToolkitVisualProfiler.cs

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616
namespace Microsoft.MixedReality.Toolkit.Diagnostics
1717
{
1818
/// <summary>
19-
///
20-
/// ABOUT: The VisualProfiler provides a drop in, single file, solution for viewing
19+
/// The VisualProfiler provides a drop in, single file, solution for viewing
2120
/// your Windows Mixed Reality Unity application's frame rate and memory usage. Missed
2221
/// frames are displayed over time to visually find problem areas. Memory is reported
2322
/// as current, peak and max usage in a bar graph.
24-
///
25-
/// USAGE: To use this profiler simply add this script as a component of any GameObject in
26-
/// your Unity scene. The profiler is initially enabled (toggle-able via the initiallyActive
27-
/// property), but can be toggled via the enabled/disable voice commands keywords.
28-
///
2923
/// </summary>
24+
/// <remarks>
25+
/// <para>To use this profiler simply add this script as a component of any GameObject in
26+
/// your Unity scene. The profiler is initially enabled (toggle-able via the initiallyActive
27+
/// property), but can be toggled via the enabled/disable voice commands keywords.</para>
28+
/// </remarks>
3029
[AddComponentMenu("Scripts/MRTK/Services/MixedRealityToolkitVisualProfiler")]
3130
public class MixedRealityToolkitVisualProfiler : MonoBehaviour
3231
{
@@ -58,7 +57,7 @@ public bool IsVisible
5857

5958
private bool ShouldShowProfiler =>
6059
#if WINDOWS_UWP
61-
(appCapture == null || !appCapture.IsCapturingVideo || showProfilerDuringMRC) &&
60+
(!appCaptureIsCapturingVideo || showProfilerDuringMRC) &&
6261
#endif // WINDOWS_UWP
6362
isVisible;
6463

@@ -217,6 +216,7 @@ private struct FrameRateColor
217216
private Mesh quadMesh;
218217

219218
#if WINDOWS_UWP
219+
private bool appCaptureIsCapturingVideo = false;
220220
private AppCapture appCapture;
221221
#endif // WINDOWS_UWP
222222

@@ -289,11 +289,23 @@ private void Start()
289289

290290
#if WINDOWS_UWP
291291
appCapture = AppCapture.GetForCurrentView();
292+
if (appCapture != null)
293+
{
294+
appCaptureIsCapturingVideo = appCapture.IsCapturingVideo;
295+
appCapture.CapturingChanged += AppCapture_CapturingChanged;
296+
}
292297
#endif // WINDOWS_UWP
293298
}
294299

295300
private void OnDestroy()
296301
{
302+
#if WINDOWS_UWP
303+
if (appCapture != null)
304+
{
305+
appCapture.CapturingChanged -= AppCapture_CapturingChanged;
306+
}
307+
#endif // WINDOWS_UWP
308+
297309
if (window != null)
298310
{
299311
Destroy(window.gameObject);
@@ -437,18 +449,36 @@ private void LateUpdate()
437449
}
438450

439451
// Update visibility state.
440-
window.gameObject.SetActive(ShouldShowProfiler);
441-
memoryStats.gameObject.SetActive(memoryStatsVisible);
452+
if (window.gameObject.activeSelf != ShouldShowProfiler)
453+
{
454+
window.gameObject.SetActive(ShouldShowProfiler);
455+
}
456+
457+
if (memoryStats.gameObject.activeSelf != memoryStatsVisible)
458+
{
459+
memoryStats.gameObject.SetActive(memoryStatsVisible);
460+
}
442461
}
443462
}
444463

464+
#if WINDOWS_UWP
465+
private void AppCapture_CapturingChanged(AppCapture sender, object args) => appCaptureIsCapturingVideo = sender.IsCapturingVideo;
466+
private float previousFieldOfView = -1.0f;
467+
#endif // WINDOWS_UWP
468+
445469
private static readonly ProfilerMarker CalculateWindowPositionPerfMarker = new ProfilerMarker("[MRTK] MixedRealityToolkitVisualProfiler.CalculateWindowPosition");
446470

447471
private Vector3 CalculateWindowPosition(Transform cameraTransform)
448472
{
449473
using (CalculateWindowPositionPerfMarker.Auto())
450474
{
451-
float windowDistance = Mathf.Max(16.0f / CameraCache.Main.fieldOfView, CameraCache.Main.nearClipPlane + 0.25f);
475+
float windowDistance =
476+
#if WINDOWS_UWP
477+
Mathf.Max(16.0f / (appCaptureIsCapturingVideo ? previousFieldOfView : previousFieldOfView = CameraCache.Main.fieldOfView), Mathf.Max(CameraCache.Main.nearClipPlane, 0.5f));
478+
#else
479+
Mathf.Max(16.0f / CameraCache.Main.fieldOfView, Mathf.Max(CameraCache.Main.nearClipPlane, 0.5f));
480+
#endif // WINDOWS_UWP
481+
452482
Vector3 position = cameraTransform.position + (cameraTransform.forward * windowDistance);
453483
Vector3 horizontalOffset = cameraTransform.right * windowOffset.x;
454484
Vector3 verticalOffset = cameraTransform.up * windowOffset.y;
@@ -632,8 +662,15 @@ private void BuildWindow()
632662
}
633663
}
634664

635-
window.gameObject.SetActive(ShouldShowProfiler);
636-
memoryStats.gameObject.SetActive(memoryStatsVisible);
665+
if (window.gameObject.activeSelf != ShouldShowProfiler)
666+
{
667+
window.gameObject.SetActive(ShouldShowProfiler);
668+
}
669+
670+
if (memoryStats.gameObject.activeSelf != memoryStatsVisible)
671+
{
672+
memoryStats.gameObject.SetActive(memoryStatsVisible);
673+
}
637674
}
638675

639676
private void BuildFrameRateStrings()

0 commit comments

Comments
 (0)