Skip to content

Commit 500522b

Browse files
authored
Merge pull request #827 from StephenHodgson/HTK-Refactor
Minor Refactoring and Cleanup
2 parents c71cab7 + 0278cf9 commit 500522b

Some content is hidden

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

50 files changed

+744
-694
lines changed

Assets/HoloToolkit-Examples/InteractiveElements/Scripts/GestureInteractive.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
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 UnityEngine;
54
using System.Collections;
65
using HoloToolkit.Unity.InputModule;
6+
using UnityEngine;
7+
using Cursor = HoloToolkit.Unity.InputModule.Cursor;
78

8-
#if UNITY_EDITOR || UNITY_WSA
9+
#if UNITY_WSA || UNITY_STANDALONE_WIN
910
using UnityEngine.Windows.Speech;
1011
#endif
1112

@@ -22,14 +23,14 @@ public class GestureInteractive : Interactive, ISourceStateHandler
2223
/// <summary>
2324
/// Gesture Manipulation states
2425
/// </summary>
25-
public enum GestureManipulationState { None, Start, Update, Lost };
26+
public enum GestureManipulationState { None, Start, Update, Lost }
2627
public GestureManipulationState GestureState { get; protected set; }
2728

2829
private IInputSource mCurrentInputSource;
2930
private uint mCurrentInputSourceId;
3031

3132
[Tooltip("Sets the time before the gesture starts after a press has occured, handy when a select event is also being used")]
32-
public float StartDelay = 0;
33+
public float StartDelay;
3334

3435
[Tooltip ("The GestureInteractiveControl to send gesture updates to")]
3536
public GestureInteractiveControl Control;
@@ -38,7 +39,7 @@ public enum GestureManipulationState { None, Start, Update, Lost };
3839
/// Provide additional UI for gesture feedback.
3940
/// </summary>
4041
[Tooltip("Should this control hide the cursor during this manipulation?")]
41-
public bool HideCursorOnManipulation = false;
42+
public bool HideCursorOnManipulation;
4243

4344
/// <summary>
4445
/// cached gesture values for computations
@@ -47,7 +48,7 @@ public enum GestureManipulationState { None, Start, Update, Lost };
4748
private Vector3 mStartHeadRay;
4849
private Vector3 mStartHandPosition;
4950
private Vector3 mCurrentHandPosition;
50-
private HoloToolkit.Unity.InputModule.Cursor mCursor;
51+
private Cursor mCursor;
5152

5253
private Coroutine mTicker;
5354
private IInputSource mTempInputSource;
@@ -276,10 +277,10 @@ private Vector3 GetCurrentHandPosition()
276277
private void HandleCursor(bool state)
277278
{
278279
// Hack for now.
279-
// TODO: Update Cursor Modifyer to handle HideOnGesture, then calculate visibility so cursors can handle this correctly
280+
// TODO: Update Cursor Modifier to handle HideOnGesture, then calculate visibility so cursors can handle this correctly
280281
if (state)
281282
{
282-
mCursor = GameObject.FindObjectOfType<HoloToolkit.Unity.InputModule.Cursor>();
283+
mCursor = FindObjectOfType<Cursor>();
283284
}
284285

285286
if (HideCursorOnManipulation && mCursor != null)
@@ -302,7 +303,7 @@ protected override void Update()
302303
}
303304
}
304305

305-
#if UNITY_EDITOR || UNITY_WSA
306+
#if UNITY_WSA || UNITY_STANDALONE_WIN
306307
/// <summary>
307308
/// From Interactive, but customized for triggering gestures from keywords
308309
/// Handle the manipulation in the GestureInteractiveControl
@@ -312,11 +313,10 @@ protected override void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEve
312313
{
313314
base.KeywordRecognizer_OnPhraseRecognized(args);
314315

315-
int index;
316-
//base.KeywordRecognizer_OnPhraseRecognized(args);
317316
// Check to make sure the recognized keyword matches, then invoke the corresponding method.
318317
if ((!KeywordRequiresGaze || HasGaze) && mKeywordDictionary != null)
319318
{
319+
int index;
320320
if (mKeywordDictionary.TryGetValue(args.text, out index))
321321
{
322322
Control.setGestureValue(index);

Assets/HoloToolkit-Examples/InteractiveElements/Scripts/Interactive.cs

+10-11
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
using System.Collections.Generic;
77
using HoloToolkit.Unity.InputModule;
88

9-
#if UNITY_EDITOR || UNITY_WSA
9+
#if UNITY_WSA || UNITY_STANDALONE_WIN
1010
using UnityEngine.Windows.Speech;
1111
#endif
1212

1313
namespace HoloToolkit.Examples.InteractiveElements
1414
{
1515
/// <summary>
16-
/// Interactive exposes basic button type events to the Unity Editor and recieves messages from the GestureManager and GazeManager.
16+
/// Interactive exposes basic button type events to the Unity Editor and receives messages from the GestureManager and GazeManager.
1717
///
1818
/// Beyond the basic button functionality, Interactive also maintains the notion of selection and enabled, which allow for more robust UI features.
1919
/// InteractiveEffects are behaviors that listen for updates from Interactive, which allows for visual feedback to be customized and placed on
@@ -30,7 +30,7 @@ public class Interactive : MonoBehaviour, IInputClickHandler, IFocusable, IInput
3030
public bool IsEnabled = true;
3131

3232
/// <summary>
33-
/// Does the gameObect currently have focus?
33+
/// Does the GameObject currently have focus?
3434
/// </summary>
3535
public bool HasGaze { get; protected set; }
3636

@@ -50,7 +50,7 @@ public class Interactive : MonoBehaviour, IInputClickHandler, IFocusable, IInput
5050
public float HoldTime = 0.5f;
5151

5252
/// <summary>
53-
/// Configure the amount of time a rolloff update should occure. When building more advanced UI,
53+
/// Configure the amount of time a roll off update should incur. When building more advanced UI,
5454
/// we may need to evaluate what the next gazed item is before updating.
5555
/// </summary>
5656
public float RollOffTime = 0.02f;
@@ -88,7 +88,7 @@ public enum ButtonStateEnum { Default, Focus, Press, Selected, FocusSelected, Pr
8888
protected bool mCheckRollOff = false;
8989
protected bool mCheckHold = false;
9090

91-
#if UNITY_EDITOR || UNITY_WSA
91+
#if UNITY_WSA || UNITY_STANDALONE_WIN
9292
protected KeywordRecognizer mKeywordRecognizer;
9393
#endif
9494
protected Dictionary<string, int> mKeywordDictionary;
@@ -134,7 +134,7 @@ protected virtual void Start()
134134
}
135135
}
136136

137-
#if UNITY_EDITOR || UNITY_WSA
137+
#if UNITY_WSA || UNITY_STANDALONE_WIN
138138
if (!KeywordRequiresGaze)
139139
{
140140
mKeywordRecognizer = new KeywordRecognizer(mKeywordArray);
@@ -206,7 +206,7 @@ public virtual void OnFocusExit()
206206

207207
private void SetKeywordListener(bool listen)
208208
{
209-
#if UNITY_EDITOR || UNITY_WSA
209+
#if UNITY_WSA || UNITY_STANDALONE_WIN
210210
if (listen)
211211
{
212212
if (KeywordRequiresGaze && mKeywordArray != null)
@@ -374,7 +374,7 @@ public void UnregisterWidget(InteractiveWidget widget)
374374
}
375375
}
376376

377-
#if UNITY_EDITOR || UNITY_WSA
377+
#if UNITY_WSA || UNITY_STANDALONE_WIN
378378
protected virtual void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
379379
{
380380

@@ -390,7 +390,7 @@ protected virtual void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEven
390390
#endif
391391

392392
/// <summary>
393-
/// Check if any state changes have occured, from alternate input sources
393+
/// Check if any state changes have occurred, from alternate input sources
394394
/// </summary>
395395
protected void CompareStates()
396396
{
@@ -510,7 +510,7 @@ protected virtual void OnDestroy()
510510

511511
protected virtual void OnEnable()
512512
{
513-
#if UNITY_EDITOR || UNITY_WSA
513+
#if UNITY_WSA || UNITY_STANDALONE_WIN
514514
if (mKeywordRecognizer != null && !KeywordRequiresGaze)
515515
{
516516
SetKeywordListener(true);
@@ -520,7 +520,6 @@ protected virtual void OnEnable()
520520

521521
protected virtual void OnDisable()
522522
{
523-
//SetKeywordListener(false);
524523
OnFocusExit();
525524
}
526525
}

Assets/HoloToolkit-Examples/InteractiveElements/Scripts/InteractiveToggle.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using UnityEngine.Events;
55
using HoloToolkit.Unity.InputModule;
66

7-
#if UNITY_EDITOR || UNITY_WSA
7+
#if UNITY_WSA || UNITY_STANDALONE_WIN
88
using UnityEngine.Windows.Speech;
99
#endif
1010

@@ -13,7 +13,7 @@ namespace HoloToolkit.Examples.InteractiveElements
1313
/// <summary>
1414
/// InteractiveToggle expands Interactive to expose selection or toggle states.
1515
///
16-
/// Beyong the basic button functionality, Interactive also maintains the notion of selection and enabled, which allow for more robust UI features.
16+
/// Beyond the basic button functionality, Interactive also maintains the notion of selection and enabled, which allow for more robust UI features.
1717
/// InteractiveEffects are behaviors that listen for updates from Interactive, which allows for visual feedback to be customized and placed on
1818
/// individual elements of the Interactive GameObject
1919
/// </summary>
@@ -54,7 +54,7 @@ public void SetSelection(bool selection)
5454

5555
/// <summary>
5656
/// A Read-only button or visual item. Passive mode ignores input, but updates the visuals as if it were enabled.
57-
/// Good for thinkgs like dashboard lights and data visualization
57+
/// Good for things like dashboard lights and data visualization
5858
/// </summary>
5959
public bool PassiveMode = false;
6060

@@ -190,12 +190,11 @@ protected override void Update()
190190

191191
}
192192

193-
#if UNITY_EDITOR || UNITY_WSA
193+
#if UNITY_WSA || UNITY_STANDALONE_WIN
194194
protected override void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
195195
{
196196
base.KeywordRecognizer_OnPhraseRecognized(args);
197197

198-
//base.KeywordRecognizer_OnPhraseRecognized(args);
199198
// Check to make sure the recognized keyword matches, then invoke the corresponding method.
200199
if ((!KeywordRequiresGaze || HasGaze) && mKeywordDictionary != null)
201200
{
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
using UnityEngine;
2-
using System.Collections;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
[RequireComponent(typeof(TextMesh))]
5-
public class DebugText : MonoBehaviour
6-
{
7-
private TextMesh mText;
4+
using UnityEngine;
85

9-
private void Awake()
6+
namespace HoloToolkit.Examples
7+
{
8+
[RequireComponent(typeof(TextMesh))]
9+
public class DebugText : MonoBehaviour
1010
{
11-
mText = GetComponent<TextMesh>();
12-
}
11+
private TextMesh mText;
1312

14-
public void SetText(string text)
15-
{
16-
mText.text = text;
13+
private void Awake()
14+
{
15+
mText = GetComponent<TextMesh>();
16+
}
17+
18+
public void SetText(string text)
19+
{
20+
mText.text = text;
21+
}
1722
}
1823
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
using UnityEngine;
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;
25
using UnityEngine.SceneManagement;
36

4-
public class LevelManager : MonoBehaviour
7+
namespace HoloToolkit.Examples
58
{
6-
public void LoadNextScene()
9+
public class LevelManager : MonoBehaviour
710
{
8-
int sceneIndex = SceneManager.GetActiveScene().buildIndex + 1;
9-
if (sceneIndex >= SceneManager.sceneCountInBuildSettings)
11+
public void LoadNextScene()
1012
{
11-
sceneIndex = 0;
12-
}
13+
int sceneIndex = SceneManager.GetActiveScene().buildIndex + 1;
14+
if (sceneIndex >= SceneManager.sceneCountInBuildSettings)
15+
{
16+
sceneIndex = 0;
17+
}
1318

14-
SceneManager.LoadScene(sceneIndex);
19+
SceneManager.LoadScene(sceneIndex);
20+
}
1521
}
1622
}

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using System.Linq;
1010
using UnityEngine;
1111

12-
#if UNITY_EDITOR || UNITY_WSA
12+
#if UNITY_WSA || UNITY_STANDALONE_WIN
1313
using UnityEngine.Windows.Speech;
1414
#endif
1515

@@ -195,7 +195,7 @@ public string DetailsText
195195
private string spaceQueryDescription;
196196
private string objectPlacementDescription;
197197
private uint trackedHandsCount = 0;
198-
#if UNITY_EDITOR || UNITY_WSA
198+
#if UNITY_WSA || UNITY_STANDALONE_WIN
199199
private KeywordRecognizer keywordRecognizer;
200200

201201
// Functions
@@ -268,7 +268,6 @@ private static void ToggleProcessedMesh()
268268

269269
private void Update()
270270
{
271-
// Updates
272271
Update_DebugDisplay(Time.deltaTime);
273272
Update_KeyboardInput(Time.deltaTime);
274273
}

Assets/HoloToolkit-Tests/Utilities/Scripts/ApplicationViewManagerEditButton.cs

+40-14
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,52 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using System.Collections;
5-
using System.Collections.Generic;
65
using UnityEngine;
76
using UnityEngine.UI;
87

9-
public class ApplicationViewManagerEditButton : MonoBehaviour
8+
namespace HoloToolkit.Unity.Tests
109
{
11-
public Text field;
12-
public void StartEdit()
10+
[RequireComponent(typeof(ApplicationViewManager))]
11+
public class ApplicationViewManagerEditButton : MonoBehaviour
1312
{
14-
StartCoroutine(OpenViewEdit());
15-
}
16-
public IEnumerator OpenViewEdit()
17-
{
18-
string result = null;
19-
var avm = this.GetComponent<HoloToolkit.Unity.ApplicationViewManager>();
20-
yield return avm.OnLaunchXamlView<string>("TestPage", s => result = s);
21-
yield return new WaitUntil(() => result != null);
22-
if (field!=null)
13+
public delegate void LaunchXmlView(string result);
14+
15+
/// <summary>
16+
/// Event to subscribe to when a text result is returned from the xml view.
17+
/// </summary>
18+
public event LaunchXmlView OnResult;
19+
20+
public Text Field;
21+
22+
private ApplicationViewManager viewManager;
23+
24+
private void Awake()
25+
{
26+
viewManager = gameObject.EnsureComponent<ApplicationViewManager>();
27+
}
28+
29+
public void StartEdit()
30+
{
31+
StartCoroutine(OpenViewEdit());
32+
}
33+
34+
private IEnumerator OpenViewEdit()
2335
{
24-
field.text = result;
36+
string result = string.Empty;
37+
38+
yield return viewManager.OnLaunchXamlView<string>("TestPage", s => result = s);
39+
40+
yield return new WaitUntil(() => !string.IsNullOrEmpty(result));
41+
42+
if (OnResult != null)
43+
{
44+
OnResult(result);
45+
}
46+
47+
if (Field != null)
48+
{
49+
Field.text = result;
50+
}
2551
}
2652
}
2753
}

0 commit comments

Comments
 (0)