// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using Microsoft.MixedReality.Toolkit.Input; using UnityEngine; namespace Microsoft.MixedReality.Toolkit.Diagnostics { /// /// Class that listens for and acts upon diagnostic system voice commands. /// [AddComponentMenu("Scripts/MRTK/Services/DiagnosticsSystemVoiceControls")] public class DiagnosticsSystemVoiceControls : MonoBehaviour, IMixedRealitySpeechHandler { bool registeredForInput = false; private void OnEnable() { if (!registeredForInput) { if (CoreServices.InputSystem != null) { CoreServices.InputSystem.RegisterHandler(this); registeredForInput = true; } } } private void OnDisable() { if (registeredForInput) { CoreServices.InputSystem.UnregisterHandler(this); registeredForInput = false; } } /// void IMixedRealitySpeechHandler.OnSpeechKeywordRecognized(SpeechEventData eventData) { switch (eventData.Command.Keyword.ToLower()) { case "toggle diagnostics": ToggleDiagnostics(); break; case "toggle profiler": ToggleProfiler(); break; } } /// /// Shows or hides all enabled diagnostics. /// public void ToggleDiagnostics() { if (CoreServices.DiagnosticsSystem != null) { CoreServices.DiagnosticsSystem.ShowDiagnostics = !CoreServices.DiagnosticsSystem.ShowDiagnostics; } } /// /// Shows or hides the profiler display. /// public void ToggleProfiler() { if (CoreServices.DiagnosticsSystem != null) { CoreServices.DiagnosticsSystem.ShowProfiler = !CoreServices.DiagnosticsSystem.ShowProfiler; } } } }