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 . Core . Definitions . Diagnostics ;
45using Microsoft . MixedReality . Toolkit . Core . EventDatum . Diagnostics ;
6+ using Microsoft . MixedReality . Toolkit . Core . Interfaces ;
57using Microsoft . MixedReality . Toolkit . Core . Interfaces . Diagnostics ;
68using Microsoft . MixedReality . Toolkit . Core . Services ;
79using UnityEngine ;
@@ -12,31 +14,34 @@ namespace Microsoft.MixedReality.Toolkit.Services.DiagnosticsSystem
1214 /// <summary>
1315 /// The default implementation of the <see cref="Microsoft.MixedReality.Toolkit.Core.Interfaces.Diagnostics.IMixedRealityDiagnosticsSystem"/>
1416 /// </summary>
15- public class MixedRealityDiagnosticsSystem : BaseEventSystem , IMixedRealityDiagnosticsSystem
17+ public class MixedRealityDiagnosticsSystem : BaseCoreSystem , IMixedRealityDiagnosticsSystem
1618 {
19+ public MixedRealityDiagnosticsSystem (
20+ IMixedRealityServiceRegistrar registrar ,
21+ MixedRealityDiagnosticsProfile profile ,
22+ Transform playspace ) : base ( registrar , profile )
23+ {
24+ Playspace = playspace ;
25+ }
26+
1727 /// <summary>
1828 /// The parent object under which all visualization game objects will be placed.
1929 /// </summary>
2030 private GameObject diagnosticVisualizationParent = null ;
2131
2232 /// <summary>
23- /// Creates the parent for diagnostic visualizations so that the scene hierarchy does not get overly cluttered.
33+ /// Creates the diagnostic visualizations and parents them so that the scene hierarchy does not get overly cluttered.
2434 /// </summary>
25- /// <returns>
26- /// The <see href="https://docs.unity3d.com/ScriptReference/GameObject.html">GameObject</see> to which diagnostic visualizations will be parented.
27- /// </returns>
28- private GameObject CreateDiagnosticVisualizationParent ( )
35+ private void CreateVisualizations ( )
2936 {
3037 diagnosticVisualizationParent = new GameObject ( "Diagnostics" ) ;
31- diagnosticVisualizationParent . transform . parent = MixedRealityToolkit . Instance . MixedRealityPlayspace . transform ;
32- diagnosticVisualizationParent . SetActive ( MixedRealityToolkit . Instance . ActiveProfile . DiagnosticsSystemProfile . ShowDiagnostics ) ;
38+ diagnosticVisualizationParent . transform . parent = Playspace . transform ;
39+ diagnosticVisualizationParent . SetActive ( ShowDiagnostics ) ;
3340
3441 // visual profiler settings
3542 visualProfiler = diagnosticVisualizationParent . AddComponent < MixedRealityToolkitVisualProfiler > ( ) ;
3643 visualProfiler . WindowParent = diagnosticVisualizationParent . transform ;
37- visualProfiler . IsVisible = MixedRealityToolkit . Instance . ActiveProfile . DiagnosticsSystemProfile . ShowProfiler ;
38-
39- return diagnosticVisualizationParent ;
44+ visualProfiler . IsVisible = ShowProfiler ;
4045 }
4146
4247 private MixedRealityToolkitVisualProfiler visualProfiler = null ;
@@ -48,13 +53,16 @@ public override void Initialize()
4853 {
4954 if ( ! Application . isPlaying ) { return ; }
5055
56+ MixedRealityDiagnosticsProfile profile = ConfigurationProfile as MixedRealityDiagnosticsProfile ;
57+ if ( profile == null ) { return ; }
58+
5159 eventData = new DiagnosticsEventData ( EventSystem . current ) ;
5260
5361 // Apply profile settings
54- ShowDiagnostics = MixedRealityToolkit . Instance . ActiveProfile . DiagnosticsSystemProfile . ShowDiagnostics ;
55- ShowProfiler = MixedRealityToolkit . Instance . ActiveProfile . DiagnosticsSystemProfile . ShowProfiler ;
62+ ShowDiagnostics = profile . ShowDiagnostics ;
63+ ShowProfiler = profile . ShowProfiler ;
5664
57- diagnosticVisualizationParent = CreateDiagnosticVisualizationParent ( ) ;
65+ CreateVisualizations ( ) ;
5866 }
5967
6068 /// <inheritdoc />
@@ -79,6 +87,12 @@ public override void Destroy()
7987 #endregion IMixedRealityService
8088
8189 #region IMixedRealityDiagnosticsSystem
90+ /// <summary>
91+ /// The transform of the playspace scene object. We use this transform to parent
92+ /// diagnostic visualizations that teleport with the user and to perform calculations
93+ /// to ensure proper alignment with the world.
94+ /// </summary>
95+ private Transform Playspace = null ;
8296
8397 private bool showDiagnostics ;
8498
0 commit comments