From 083ba1e3eacf905fc4dab24b3624adef5bfc0224 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Tue, 8 Aug 2017 10:32:57 -0700 Subject: [PATCH 1/2] fixed cross platform support from last refactor PR --- .../HoloToolkit/Input/Scripts/HandGuidance.cs | 4 +-- .../HoloToolkit/Input/Scripts/InputManager.cs | 29 +++++++++++-------- .../Microphone/DictationInputManager.cs | 14 ++++----- .../Input/Scripts/Voice/KeywordManager.cs | 2 +- .../RemoteMapping/RemoteMappingManager.cs | 4 +-- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/Assets/HoloToolkit/Input/Scripts/HandGuidance.cs b/Assets/HoloToolkit/Input/Scripts/HandGuidance.cs index 46b439edab6..3833d5172a1 100644 --- a/Assets/HoloToolkit/Input/Scripts/HandGuidance.cs +++ b/Assets/HoloToolkit/Input/Scripts/HandGuidance.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using UnityEngine; #if UNITY_WSA +using UnityEngine; using UnityEngine.VR.WSA.Input; #endif @@ -14,6 +14,7 @@ namespace HoloToolkit.Unity.InputModule /// public class HandGuidance : Singleton { +#if UNITY_WSA [Tooltip("The Cursor object the HandGuidanceIndicator will be positioned around.")] public GameObject Cursor; @@ -31,7 +32,6 @@ public class HandGuidance : Singleton private uint? currentlyTrackedHand = null; -#if UNITY_WSA protected override void Awake() { base.Awake(); diff --git a/Assets/HoloToolkit/Input/Scripts/InputManager.cs b/Assets/HoloToolkit/Input/Scripts/InputManager.cs index f653e78fb39..bec595b0728 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputManager.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputManager.cs @@ -45,8 +45,11 @@ public class InputManager : Singleton private ManipulationEventData manipulationEventData; private HoldEventData holdEventData; private NavigationEventData navigationEventData; + +#if UNITY_WSA || UNITY_STANDALONE_WIN private SpeechKeywordRecognizedEventData speechKeywordRecognizedEventData; private DictationEventData dictationEventData; +#endif /// /// Indicates if input is currently enabled or not. @@ -184,11 +187,13 @@ private void InitializeEventDatas() manipulationEventData = new ManipulationEventData(EventSystem.current); navigationEventData = new NavigationEventData(EventSystem.current); holdEventData = new HoldEventData(EventSystem.current); +#if UNITY_WSA || UNITY_STANDALONE_WIN speechKeywordRecognizedEventData = new SpeechKeywordRecognizedEventData(EventSystem.current); dictationEventData = new DictationEventData(EventSystem.current); +#endif } - #region Unity Methods +#region Unity Methods private void Start() { @@ -217,7 +222,7 @@ protected override void OnDestroy() UnregisterGazeManager(); } - #endregion // Unity Methods +#endregion // Unity Methods public void HandleEvent(BaseEventData eventData, ExecuteEvents.EventFunction eventHandler) where T : IEventSystemHandler @@ -450,7 +455,7 @@ public void RaiseSourceLost(IInputSource source, uint sourceId) HandleEvent(sourceStateEventData, OnSourceLostEventHandler); } - #region Manipulation Events +#region Manipulation Events private static readonly ExecuteEvents.EventFunction OnManipulationStartedEventHandler = delegate (IManipulationHandler handler, BaseEventData eventData) @@ -516,9 +521,9 @@ public void RaiseManipulationCanceled(IInputSource source, uint sourceId, Vector HandleEvent(manipulationEventData, OnManipulationCanceledEventHandler); } - #endregion // Manipulation Events +#endregion // Manipulation Events - #region Hold Events +#region Hold Events private static readonly ExecuteEvents.EventFunction OnHoldStartedEventHandler = delegate (IHoldHandler handler, BaseEventData eventData) @@ -568,9 +573,9 @@ public void RaiseHoldCanceled(IInputSource source, uint sourceId) HandleEvent(holdEventData, OnHoldCanceledEventHandler); } - #endregion // Hold Events +#endregion // Hold Events - #region Navigation Events +#region Navigation Events private static readonly ExecuteEvents.EventFunction OnNavigationStartedEventHandler = delegate (INavigationHandler handler, BaseEventData eventData) @@ -636,10 +641,10 @@ public void RaiseNavigationCanceled(IInputSource source, uint sourceId, Vector3 HandleEvent(navigationEventData, OnNavigationCanceledEventHandler); } - #endregion // Navigation Events +#endregion // Navigation Events #if UNITY_WSA || UNITY_STANDALONE_WIN - #region Speech Events +#region Speech Events private static readonly ExecuteEvents.EventFunction OnSpeechKeywordRecognizedEventHandler = delegate (ISpeechHandler handler, BaseEventData eventData) @@ -664,9 +669,9 @@ public void RaiseSpeechKeywordPhraseRecognized(IInputSource source, uint sourceI handler.OnDictationHypothesis(casted); }; - #endregion // Speech Events +#endregion // Speech Events - #region Dictation Events +#region Dictation Events public void RaiseDictationHypothesis(IInputSource source, uint sourceId, string dictationHypothesis, AudioClip dictationAudioClip = null) { @@ -725,7 +730,7 @@ public void RaiseDictationError(IInputSource source, uint sourceId, string dicta HandleEvent(dictationEventData, OnDictationErrorEventHandler); } - #endregion // Dictation Events +#endregion // Dictation Events #endif } } diff --git a/Assets/HoloToolkit/Input/Scripts/Microphone/DictationInputManager.cs b/Assets/HoloToolkit/Input/Scripts/Microphone/DictationInputManager.cs index f956e6c83f7..1f478a6a93c 100644 --- a/Assets/HoloToolkit/Input/Scripts/Microphone/DictationInputManager.cs +++ b/Assets/HoloToolkit/Input/Scripts/Microphone/DictationInputManager.cs @@ -2,10 +2,10 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. using System.Collections; -using System.Text; using UnityEngine; #if UNITY_WSA || UNITY_STANDALONE_WIN +using System.Text; using UnityEngine.Windows.Speech; #endif @@ -17,6 +17,7 @@ namespace HoloToolkit.Unity.InputModule /// public class DictationInputManager : Singleton, IInputSource { +#if UNITY_WSA || UNITY_STANDALONE_WIN /// /// Caches the text currently being displayed in dictation display text. /// @@ -47,12 +48,12 @@ public class DictationInputManager : Singleton, IInputSou /// Audio clip of the last dictation session. /// private static AudioClip dictationAudioClip; -#if UNITY_WSA || UNITY_STANDALONE_WIN + private static DictationRecognizer dictationRecognizer; -#endif + private static bool isTransitioning; - private static bool hasFailed; +#endif #region Unity Methods @@ -187,6 +188,7 @@ public static IEnumerator StopRecording() } #region Dictation Recognizer Callbacks +#if UNITY_WSA || UNITY_STANDALONE_WIN /// /// This event is fired while the user is talking. As the recognizer listens, it provides text of what it's heard so far. @@ -200,7 +202,6 @@ private static void DictationRecognizer_DictationHypothesis(string text) InputManager.Instance.RaiseDictationHypothesis(Instance, 0, dictationResult); } -#if UNITY_WSA || UNITY_STANDALONE_WIN /// /// This event is fired after the user pauses, typically at the end of a sentence. The full recognized string is returned here. /// @@ -234,7 +235,6 @@ private static void DictationRecognizer_DictationComplete(DictationCompletionCau textSoFar = null; dictationResult = string.Empty; } -#endif /// /// This event is fired when an error occurs. @@ -249,7 +249,7 @@ private static void DictationRecognizer_DictationError(string error, int hresult textSoFar = null; dictationResult = string.Empty; } - +#endif #endregion // Dictation Recognizer Callbacks #region IInputSource Implementation diff --git a/Assets/HoloToolkit/Input/Scripts/Voice/KeywordManager.cs b/Assets/HoloToolkit/Input/Scripts/Voice/KeywordManager.cs index 4cc816ca49c..34e59aebb36 100644 --- a/Assets/HoloToolkit/Input/Scripts/Voice/KeywordManager.cs +++ b/Assets/HoloToolkit/Input/Scripts/Voice/KeywordManager.cs @@ -47,8 +47,8 @@ public enum RecognizerStartBehavior { AutoStart, ManualStart }; [Tooltip("An array of string keywords and UnityEvents, to be set in the Inspector.")] public KeywordAndResponse[] KeywordsAndResponses; - private readonly Dictionary responses = new Dictionary(); #if UNITY_WSA || UNITY_STANDALONE_WIN + private readonly Dictionary responses = new Dictionary(); private KeywordRecognizer keywordRecognizer; void Start() diff --git a/Assets/HoloToolkit/SpatialMapping/Scripts/RemoteMapping/RemoteMappingManager.cs b/Assets/HoloToolkit/SpatialMapping/Scripts/RemoteMapping/RemoteMappingManager.cs index 9230c51ebd1..76b12e69b28 100644 --- a/Assets/HoloToolkit/SpatialMapping/Scripts/RemoteMapping/RemoteMappingManager.cs +++ b/Assets/HoloToolkit/SpatialMapping/Scripts/RemoteMapping/RemoteMappingManager.cs @@ -32,20 +32,20 @@ public partial class RemoteMappingManager : Singleton /// Used for voice commands. /// private KeywordRecognizer keywordRecognizer; -#endif /// /// Collection of supported keywords and their associated actions. /// private Dictionary keywordCollection; +#endif // Use this for initialization. private void Start() { +#if UNITY_WSA || UNITY_STANDALONE_WIN // Create our keyword collection. keywordCollection = new Dictionary { { SendMeshesKeyword, SendMeshes } }; -#if UNITY_WSA || UNITY_STANDALONE_WIN // Tell the KeywordRecognizer about our keywords. keywordRecognizer = new KeywordRecognizer(keywordCollection.Keys.ToArray()); // Register a callback for the KeywordRecognizer and start recognizing. From e5a98628afba667f8c137b851493c934dcbc048b Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Fri, 11 Aug 2017 21:26:30 -0700 Subject: [PATCH 2/2] Fixed formatting. --- .../HoloToolkit/Input/Scripts/InputManager.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Assets/HoloToolkit/Input/Scripts/InputManager.cs b/Assets/HoloToolkit/Input/Scripts/InputManager.cs index bec595b0728..839fbc67fa4 100644 --- a/Assets/HoloToolkit/Input/Scripts/InputManager.cs +++ b/Assets/HoloToolkit/Input/Scripts/InputManager.cs @@ -193,7 +193,7 @@ private void InitializeEventDatas() #endif } -#region Unity Methods + #region Unity Methods private void Start() { @@ -222,7 +222,7 @@ protected override void OnDestroy() UnregisterGazeManager(); } -#endregion // Unity Methods + #endregion // Unity Methods public void HandleEvent(BaseEventData eventData, ExecuteEvents.EventFunction eventHandler) where T : IEventSystemHandler @@ -455,7 +455,7 @@ public void RaiseSourceLost(IInputSource source, uint sourceId) HandleEvent(sourceStateEventData, OnSourceLostEventHandler); } -#region Manipulation Events + #region Manipulation Events private static readonly ExecuteEvents.EventFunction OnManipulationStartedEventHandler = delegate (IManipulationHandler handler, BaseEventData eventData) @@ -521,9 +521,9 @@ public void RaiseManipulationCanceled(IInputSource source, uint sourceId, Vector HandleEvent(manipulationEventData, OnManipulationCanceledEventHandler); } -#endregion // Manipulation Events + #endregion // Manipulation Events -#region Hold Events + #region Hold Events private static readonly ExecuteEvents.EventFunction OnHoldStartedEventHandler = delegate (IHoldHandler handler, BaseEventData eventData) @@ -573,9 +573,9 @@ public void RaiseHoldCanceled(IInputSource source, uint sourceId) HandleEvent(holdEventData, OnHoldCanceledEventHandler); } -#endregion // Hold Events + #endregion // Hold Events -#region Navigation Events + #region Navigation Events private static readonly ExecuteEvents.EventFunction OnNavigationStartedEventHandler = delegate (INavigationHandler handler, BaseEventData eventData) @@ -641,10 +641,10 @@ public void RaiseNavigationCanceled(IInputSource source, uint sourceId, Vector3 HandleEvent(navigationEventData, OnNavigationCanceledEventHandler); } -#endregion // Navigation Events + #endregion // Navigation Events #if UNITY_WSA || UNITY_STANDALONE_WIN -#region Speech Events + #region Speech Events private static readonly ExecuteEvents.EventFunction OnSpeechKeywordRecognizedEventHandler = delegate (ISpeechHandler handler, BaseEventData eventData) @@ -669,9 +669,9 @@ public void RaiseSpeechKeywordPhraseRecognized(IInputSource source, uint sourceI handler.OnDictationHypothesis(casted); }; -#endregion // Speech Events + #endregion // Speech Events -#region Dictation Events + #region Dictation Events public void RaiseDictationHypothesis(IInputSource source, uint sourceId, string dictationHypothesis, AudioClip dictationAudioClip = null) { @@ -730,7 +730,7 @@ public void RaiseDictationError(IInputSource source, uint sourceId, string dicta HandleEvent(dictationEventData, OnDictationErrorEventHandler); } -#endregion // Dictation Events + #endregion // Dictation Events #endif } }