Skip to content

Commit bbb8438

Browse files
committed
Merge from HoloToolkit/master to matthejo/master
2 parents 2547689 + 4e20a8e commit bbb8438

File tree

134 files changed

+130314
-127795
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+130314
-127795
lines changed

Assets/HoloToolkit-Examples/SharingWithUNET/Scripts/PlayerController.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ private void Start()
7878
transform.SetParent(sharedWorldAnchorTransform);
7979
}
8080

81+
private void OnDestroy()
82+
{
83+
if (isLocalPlayer)
84+
{
85+
InputManager.Instance.RemoveGlobalListener(gameObject);
86+
}
87+
}
88+
8189
private void Update()
8290
{
8391
// If we aren't the local player, we just need to make sure that the position of this object is set properly

Assets/HoloToolkit-Examples/SpatialUnderstanding/SpatialUnderstanding-FeatureOverview/Scripts/AppState.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using HoloToolkit.Unity;
66
using System;
77
using HoloToolkit.Unity.InputModule;
8+
using HoloToolkit.Unity.SpatialMapping;
89

910
namespace HoloToolkit.Examples.SpatialUnderstandingFeatureOverview
1011
{
@@ -199,13 +200,18 @@ private void Start()
199200
InputManager.Instance.AddGlobalListener(gameObject);
200201
}
201202

202-
private void Update_DebugDisplay(float deltaTime)
203+
protected override void OnDestroy()
204+
{
205+
InputManager.Instance.RemoveGlobalListener(gameObject);
206+
}
207+
208+
private void Update_DebugDisplay(float deltaTime)
209+
{
210+
// Basic checks
211+
if (DebugDisplay == null)
203212
{
204-
// Basic checks
205-
if (DebugDisplay == null)
206-
{
207-
return;
208-
}
213+
return;
214+
}
209215

210216
// Update display text
211217
DebugDisplay.text = PrimaryText;

Assets/HoloToolkit/Input/Animations/Cursor/CursorSimple.controller

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ AnimatorStateTransition:
8181
m_ExitTime: 0.33066684
8282
m_HasExitTime: 0
8383
m_HasFixedDuration: 1
84-
m_InterruptionSource: 0
84+
m_InterruptionSource: 2
8585
m_OrderedInterruption: 1
8686
m_CanTransitionToSelf: 1
8787
--- !u!1101 &1101000011538347200
@@ -156,7 +156,7 @@ AnimatorStateTransition:
156156
m_ExitTime: 0.17148435
157157
m_HasExitTime: 0
158158
m_HasFixedDuration: 1
159-
m_InterruptionSource: 0
159+
m_InterruptionSource: 2
160160
m_OrderedInterruption: 1
161161
m_CanTransitionToSelf: 1
162162
--- !u!1101 &1101000011705696456

Assets/HoloToolkit/Input/README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Game objects that want to consume input events can implement one or many **input
1717
- **IManipulationHandler** for the Windows manipulation gesture.
1818
- **INavigationnHandler** for the Windows navigation gesture.
1919
- **ISourceStateHandler** for the source detected and source lost events.
20+
- **ISpeechHandler** for voice commands.
2021

2122
The **input manager** listens to the various events coming from the input sources, and also takes into account the gaze. Currently, that gaze is always coming from the GazeManager class, but this could be extended to support multiple gaze sources if the need arises.
2223

@@ -189,16 +190,30 @@ or in your Visual Studio Package.appxmanifest capabilities.
189190
**RecognizerStart** Set this to determine whether the keyword recognizer will start immediately or if it should wait for your code to tell it to start.
190191

191192
#### Voice
192-
##### KeywordManager.cs
193-
Allows you to specify keywords and methods in the Unity Inspector, instead of registering them explicitly in code.
194-
**IMPORTANT**: Please make sure to add the microphone capability in your app, in Unity under
193+
194+
**IMPORTANT**: Please make sure to add the Microphone capabilities in your app, in Unity under
195195
Edit -> Project Settings -> Player -> Settings for Windows Store -> Publishing Settings -> Capabilities
196196
or in your Visual Studio Package.appxmanifest capabilities.
197197

198+
##### KeywordManager.cs
199+
Allows you to specify keywords and methods in the Unity Inspector, instead of registering them explicitly in code.
200+
198201
**_KeywordsAndResponses_** Set the size as the number of keywords you'd like to listen for, then specify the keywords and method responses to complete the array.
199202

200203
**RecognizerStart** Set this to determine whether the keyword recognizer will start immediately or if it should wait for your code to tell it to start.
201204

205+
##### SpeechInputSource.cs
206+
Allows you to specify keywords and keyboard shortcuts in the Unity Inspector, instead of registering them explicitly in code. Keywords are handled by scripts that implement ISpeechHandler.cs.
207+
208+
Check out Assets/HoloToolkit/Input/Tests/Scripts/SphereKeywords.cs and Assets/HoloToolkit/Input/Tests/Scripts/SphereGlobalKeywords.cs for an example of implementing these features, which is used in the demo scene at Assets/HoloToolkit/Input/Tests/SpeechInputSource.unity.
209+
210+
**_KeywordsAndKeys_** Set the size as the number of keywords you'd like to listen for, then specify the keywords to complete the array.
211+
212+
**RecognizerStart** Set this to determine whether the keyword recognizer will start immediately or if it should wait for your code to tell it to start.
213+
214+
##### ISpeechHandler.cs
215+
Interface that a game object can implement to react to speech keywords.
216+
202217
### [Test Prefabs](TestPrefabs)
203218

204219
Prefabs used in the various test scenes, which you can use as inspiration to build your own.
@@ -276,6 +291,19 @@ Gazing on an object and saying "Select Object" will persistently select that obj
276291
after which the user can also adjust object size with "Make Smaller" and "Make Bigger" voice commands and finally clear
277292
currently selected object by saying "Clear Selection".
278293

294+
#### SpeechInputSource.unity
295+
296+
Shows how to use the SpeechInputSource.cs script to add keywords to your scene.
297+
298+
1. Select whether you want the recognizer to start automatically or when you manually start it.
299+
2. Specify the number of keywords you want.
300+
3. Type the word or phrase you'd like to register as the keyword and, if you want, set a key code to use in the Editor. You can also use an attached microphone with the Editor.
301+
4. Attach a script that implements ISpeechHandler.cs to the object in the scene that will require the gaze focus to execute the command. You should register this script with the InputManager.cs as a global listener to handle keywords that don't require a focused object.
302+
303+
When you start the scene, your keywords will automatically be registered on a KeywordRecognizer, and the recognizer will be started (or not) based on your Recognizer Start setting.
304+
305+
####
306+
279307
---
280308
##### [Go back up to the table of contents.](../../../README.md)
281309
---

Assets/HoloToolkit/Input/Scripts/Cursor/Cursor.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public enum CursorStateEnum
2323
/// <summary>
2424
/// Not IsHandVisible
2525
/// </summary>
26-
Observe,
26+
Observe,
2727
/// <summary>
2828
/// Not IsHandVisible AND not IsInputSourceDown AND TargetedObject exists
2929
/// </summary>
30-
ObserveHover,
30+
ObserveHover,
3131
/// <summary>
3232
/// IsHandVisible AND not IsInputSourceDown AND TargetedObject is NULL
3333
/// </summary>
@@ -73,10 +73,13 @@ public enum CursorStateEnum
7373
[Tooltip("The distance from the hit surface to place the cursor")]
7474
public float SurfaceCursorDistance = 0.02f;
7575

76+
[Header("Motion")]
77+
[Tooltip("When lerping, use unscaled time. This is useful for games that have a pause mechanism or otherwise adjust the game timescale.")]
78+
public bool UseUnscaledTime = true;
79+
7680
/// <summary>
7781
/// Blend value for surface normal to user facing lerp
7882
/// </summary>
79-
[Header("Motion")]
8083
public float PositionLerpTime = 0.01f;
8184

8285
/// <summary>
@@ -105,7 +108,7 @@ public Vector3 Position
105108
{
106109
get { return transform.position; }
107110
}
108-
111+
109112
public Quaternion Rotation
110113
{
111114
get { return transform.rotation; }
@@ -153,7 +156,7 @@ public bool IsVisible
153156
}
154157
}
155158

156-
#region MonoBehaviour Functions
159+
#region MonoBehaviour Functions
157160

158161
private void Awake()
159162
{
@@ -177,7 +180,7 @@ private void Update()
177180
/// <summary>
178181
/// Override for enable functions
179182
/// </summary>
180-
protected virtual void OnEnable(){}
183+
protected virtual void OnEnable() { }
181184

182185
/// <summary>
183186
/// Override for disable functions
@@ -194,7 +197,7 @@ private void OnDestroy()
194197
UnregisterManagers();
195198
}
196199

197-
#endregion
200+
#endregion
198201

199202
/// <summary>
200203
/// Register to events from the managers the cursor needs.
@@ -302,17 +305,21 @@ protected virtual void UpdateCursorTransform()
302305
}
303306
}
304307

308+
float deltaTime = UseUnscaledTime
309+
? Time.unscaledDeltaTime
310+
: Time.deltaTime;
311+
305312
// Use the lerp times to blend the position to the target position
306-
transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime / PositionLerpTime);
307-
transform.localScale = Vector3.Lerp(transform.localScale, targetScale, Time.deltaTime / ScaleLerpTime);
308-
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime / RotationLerpTime);
313+
transform.position = Vector3.Lerp(transform.position, targetPosition, deltaTime / PositionLerpTime);
314+
transform.localScale = Vector3.Lerp(transform.localScale, targetScale, deltaTime / ScaleLerpTime);
315+
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, deltaTime / RotationLerpTime);
309316
}
310317

311318
/// <summary>
312319
/// Updates the visual representation of the cursor.
313320
/// </summary>
314321
public void SetVisiblity(bool visible)
315-
{
322+
{
316323
if (PrimaryCursorVisual != null)
317324
{
318325
PrimaryCursorVisual.gameObject.SetActive(visible);
@@ -414,7 +421,7 @@ public virtual CursorStateEnum CheckCursorState()
414421
{
415422
return CursorStateEnum.Select;
416423
}
417-
else if(cursorState == CursorStateEnum.Select)
424+
else if (cursorState == CursorStateEnum.Select)
418425
{
419426
return CursorStateEnum.Release;
420427
}

Assets/HoloToolkit/Input/Scripts/Cursor/ObjectCursor.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ protected override void OnEnable()
3737
{
3838
ParentTransform = transform;
3939
}
40+
41+
for (int i = 0; i < ParentTransform.childCount; i++)
42+
{
43+
ParentTransform.GetChild(i).gameObject.SetActive(false);
44+
}
45+
4046
base.OnEnable();
4147
}
4248

@@ -48,23 +54,42 @@ protected override void OnEnable()
4854
public override void OnCursorStateChange(CursorStateEnum state)
4955
{
5056
base.OnCursorStateChange(state);
51-
5257
if (state != CursorStateEnum.Contextual)
5358
{
54-
// Hide all children first
55-
for(int i = 0; i < ParentTransform.childCount; i++)
59+
60+
// First, try to find a cursor for the current state
61+
var newActive = new ObjectCursorDatum();
62+
for(int cursorIndex = 0; cursorIndex < CursorStateData.Length; cursorIndex++)
5663
{
57-
ParentTransform.GetChild(i).gameObject.SetActive(false);
64+
ObjectCursorDatum cursor = CursorStateData[cursorIndex];
65+
if (cursor.CursorState == state)
66+
{
67+
newActive = cursor;
68+
break;
69+
}
70+
}
71+
72+
// If no cursor for current state is found, let the last active cursor be
73+
// (any cursor is better than an invisible cursor)
74+
if (newActive.Name == null)
75+
{
76+
return;
5877
}
5978

60-
// Set active any that match the current state
61-
for (int i = 0; i < CursorStateData.Length; i++)
79+
// If we come here, there is a cursor for the new state,
80+
// so de-activate a possible earlier active cursor
81+
for(int cursorIndex = 0; cursorIndex < CursorStateData.Length; cursorIndex++)
6282
{
63-
if (CursorStateData[i].CursorState == state)
83+
ObjectCursorDatum cursor = CursorStateData[cursorIndex];
84+
if (cursor.CursorObject.activeSelf)
6485
{
65-
CursorStateData[i].CursorObject.SetActive(true);
86+
cursor.CursorObject.SetActive(false);
87+
break;
6688
}
6789
}
90+
91+
// ... and set the cursor for the new state active.
92+
newActive.CursorObject.SetActive(true);
6893
}
6994
}
7095
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using UnityEngine.EventSystems;
5+
6+
namespace HoloToolkit.Unity.InputModule
7+
{
8+
/// <summary>
9+
/// Interface to implement to react to speech recognition.
10+
/// </summary>
11+
public interface ISpeechHandler : IEventSystemHandler
12+
{
13+
void OnSpeechKeywordRecognized(SpeechKeywordRecognizedEventData eventData);
14+
}
15+
}

Assets/HoloToolkit/Input/Scripts/InputEvents/ISpeechHandler.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System;
5+
using UnityEngine;
6+
using UnityEngine.EventSystems;
7+
using UnityEngine.Windows.Speech;
8+
9+
namespace HoloToolkit.Unity.InputModule
10+
{
11+
/// <summary>
12+
/// Describes an input event that involves keyword recognition.
13+
/// </summary>
14+
public class SpeechKeywordRecognizedEventData : InputEventData
15+
{
16+
/// <summary>
17+
/// A measure of correct recognition certainty.
18+
/// </summary>
19+
public ConfidenceLevel Confidence { get; private set; }
20+
21+
/// <summary>
22+
/// The time it took for the phrase to be uttered.
23+
/// </summary>
24+
public TimeSpan PhraseDuration { get; private set; }
25+
26+
/// <summary>
27+
/// The moment in time when uttering of the phrase began.
28+
/// </summary>
29+
public DateTime PhraseStartTime { get; private set; }
30+
31+
/// <summary>
32+
/// A semantic meaning of recognized phrase.
33+
/// </summary>
34+
public SemanticMeaning[] SemanticMeanings { get; private set; }
35+
36+
/// <summary>
37+
/// The text that was recognized.
38+
/// </summary>
39+
public string RecognizedText { get; private set; }
40+
41+
public SpeechKeywordRecognizedEventData(EventSystem eventSystem) : base(eventSystem)
42+
{
43+
}
44+
45+
public void Initialize(IInputSource inputSource, uint sourceId, ConfidenceLevel confidence, TimeSpan phraseDuration, DateTime phraseStartTime, SemanticMeaning[] semanticMeanings, string recognizedText)
46+
{
47+
BaseInitialize(inputSource, sourceId);
48+
Confidence = confidence;
49+
PhraseDuration = phraseDuration;
50+
PhraseStartTime = phraseStartTime;
51+
SemanticMeanings = semanticMeanings;
52+
RecognizedText = recognizedText;
53+
}
54+
}
55+
}

Assets/HoloToolkit/Input/Scripts/InputEvents/SpeechKeywordRecognizedEventData.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)