|
16 | 16 | namespace Microsoft.MixedReality.Toolkit.Diagnostics
|
17 | 17 | {
|
18 | 18 | /// <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 |
21 | 20 | /// your Windows Mixed Reality Unity application's frame rate and memory usage. Missed
|
22 | 21 | /// frames are displayed over time to visually find problem areas. Memory is reported
|
23 | 22 | /// 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 |
| - /// |
29 | 23 | /// </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> |
30 | 29 | [AddComponentMenu("Scripts/MRTK/Services/MixedRealityToolkitVisualProfiler")]
|
31 | 30 | public class MixedRealityToolkitVisualProfiler : MonoBehaviour
|
32 | 31 | {
|
@@ -58,7 +57,7 @@ public bool IsVisible
|
58 | 57 |
|
59 | 58 | private bool ShouldShowProfiler =>
|
60 | 59 | #if WINDOWS_UWP
|
61 |
| - (appCapture == null || !appCapture.IsCapturingVideo || showProfilerDuringMRC) && |
| 60 | + (!appCaptureIsCapturingVideo || showProfilerDuringMRC) && |
62 | 61 | #endif // WINDOWS_UWP
|
63 | 62 | isVisible;
|
64 | 63 |
|
@@ -217,6 +216,7 @@ private struct FrameRateColor
|
217 | 216 | private Mesh quadMesh;
|
218 | 217 |
|
219 | 218 | #if WINDOWS_UWP
|
| 219 | + private bool appCaptureIsCapturingVideo = false; |
220 | 220 | private AppCapture appCapture;
|
221 | 221 | #endif // WINDOWS_UWP
|
222 | 222 |
|
@@ -289,11 +289,23 @@ private void Start()
|
289 | 289 |
|
290 | 290 | #if WINDOWS_UWP
|
291 | 291 | appCapture = AppCapture.GetForCurrentView();
|
| 292 | + if (appCapture != null) |
| 293 | + { |
| 294 | + appCaptureIsCapturingVideo = appCapture.IsCapturingVideo; |
| 295 | + appCapture.CapturingChanged += AppCapture_CapturingChanged; |
| 296 | + } |
292 | 297 | #endif // WINDOWS_UWP
|
293 | 298 | }
|
294 | 299 |
|
295 | 300 | private void OnDestroy()
|
296 | 301 | {
|
| 302 | +#if WINDOWS_UWP |
| 303 | + if (appCapture != null) |
| 304 | + { |
| 305 | + appCapture.CapturingChanged -= AppCapture_CapturingChanged; |
| 306 | + } |
| 307 | +#endif // WINDOWS_UWP |
| 308 | + |
297 | 309 | if (window != null)
|
298 | 310 | {
|
299 | 311 | Destroy(window.gameObject);
|
@@ -437,18 +449,36 @@ private void LateUpdate()
|
437 | 449 | }
|
438 | 450 |
|
439 | 451 | // 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 | + } |
442 | 461 | }
|
443 | 462 | }
|
444 | 463 |
|
| 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 | + |
445 | 469 | private static readonly ProfilerMarker CalculateWindowPositionPerfMarker = new ProfilerMarker("[MRTK] MixedRealityToolkitVisualProfiler.CalculateWindowPosition");
|
446 | 470 |
|
447 | 471 | private Vector3 CalculateWindowPosition(Transform cameraTransform)
|
448 | 472 | {
|
449 | 473 | using (CalculateWindowPositionPerfMarker.Auto())
|
450 | 474 | {
|
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 | + |
452 | 482 | Vector3 position = cameraTransform.position + (cameraTransform.forward * windowDistance);
|
453 | 483 | Vector3 horizontalOffset = cameraTransform.right * windowOffset.x;
|
454 | 484 | Vector3 verticalOffset = cameraTransform.up * windowOffset.y;
|
@@ -632,8 +662,15 @@ private void BuildWindow()
|
632 | 662 | }
|
633 | 663 | }
|
634 | 664 |
|
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 | + } |
637 | 674 | }
|
638 | 675 |
|
639 | 676 | private void BuildFrameRateStrings()
|
|
0 commit comments