Skip to content

Commit

Permalink
Merge pull request microsoft#827 from StephenHodgson/HTK-Refactor
Browse files Browse the repository at this point in the history
Minor Refactoring and Cleanup
  • Loading branch information
NeerajW authored and keveleigh committed Aug 11, 2017
2 parents bd9e45f + 418702e commit 327b007
Show file tree
Hide file tree
Showing 50 changed files with 744 additions and 694 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;
using System.Collections;
using HoloToolkit.Unity.InputModule;
using UnityEngine;
using Cursor = HoloToolkit.Unity.InputModule.Cursor;

#if UNITY_EDITOR || UNITY_WSA
#if UNITY_WSA || UNITY_STANDALONE_WIN
using UnityEngine.Windows.Speech;
#endif

Expand All @@ -22,14 +23,14 @@ public class GestureInteractive : Interactive, ISourceStateHandler
/// <summary>
/// Gesture Manipulation states
/// </summary>
public enum GestureManipulationState { None, Start, Update, Lost };
public enum GestureManipulationState { None, Start, Update, Lost }
public GestureManipulationState GestureState { get; protected set; }

private IInputSource mCurrentInputSource;
private uint mCurrentInputSourceId;

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

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

/// <summary>
/// cached gesture values for computations
Expand All @@ -47,7 +48,7 @@ public enum GestureManipulationState { None, Start, Update, Lost };
private Vector3 mStartHeadRay;
private Vector3 mStartHandPosition;
private Vector3 mCurrentHandPosition;
private HoloToolkit.Unity.InputModule.Cursor mCursor;
private Cursor mCursor;

private Coroutine mTicker;
private IInputSource mTempInputSource;
Expand Down Expand Up @@ -276,10 +277,10 @@ private Vector3 GetCurrentHandPosition()
private void HandleCursor(bool state)
{
// Hack for now.
// TODO: Update Cursor Modifyer to handle HideOnGesture, then calculate visibility so cursors can handle this correctly
// TODO: Update Cursor Modifier to handle HideOnGesture, then calculate visibility so cursors can handle this correctly
if (state)
{
mCursor = GameObject.FindObjectOfType<HoloToolkit.Unity.InputModule.Cursor>();
mCursor = FindObjectOfType<Cursor>();
}

if (HideCursorOnManipulation && mCursor != null)
Expand All @@ -302,7 +303,7 @@ protected override void Update()
}
}

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

int index;
//base.KeywordRecognizer_OnPhraseRecognized(args);
// Check to make sure the recognized keyword matches, then invoke the corresponding method.
if ((!KeywordRequiresGaze || HasGaze) && mKeywordDictionary != null)
{
int index;
if (mKeywordDictionary.TryGetValue(args.text, out index))
{
Control.setGestureValue(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
using System.Collections.Generic;
using HoloToolkit.Unity.InputModule;

#if UNITY_EDITOR || UNITY_WSA
#if UNITY_WSA || UNITY_STANDALONE_WIN
using UnityEngine.Windows.Speech;
#endif

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

/// <summary>
/// Does the gameObect currently have focus?
/// Does the GameObject currently have focus?
/// </summary>
public bool HasGaze { get; protected set; }

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

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

#if UNITY_EDITOR || UNITY_WSA
#if UNITY_WSA || UNITY_STANDALONE_WIN
protected KeywordRecognizer mKeywordRecognizer;
#endif
protected Dictionary<string, int> mKeywordDictionary;
Expand Down Expand Up @@ -134,7 +134,7 @@ protected virtual void Start()
}
}

#if UNITY_EDITOR || UNITY_WSA
#if UNITY_WSA || UNITY_STANDALONE_WIN
if (!KeywordRequiresGaze)
{
mKeywordRecognizer = new KeywordRecognizer(mKeywordArray);
Expand Down Expand Up @@ -206,7 +206,7 @@ public virtual void OnFocusExit()

private void SetKeywordListener(bool listen)
{
#if UNITY_EDITOR || UNITY_WSA
#if UNITY_WSA || UNITY_STANDALONE_WIN
if (listen)
{
if (KeywordRequiresGaze && mKeywordArray != null)
Expand Down Expand Up @@ -374,7 +374,7 @@ public void UnregisterWidget(InteractiveWidget widget)
}
}

#if UNITY_EDITOR || UNITY_WSA
#if UNITY_WSA || UNITY_STANDALONE_WIN
protected virtual void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{

Expand All @@ -390,7 +390,7 @@ protected virtual void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEven
#endif

/// <summary>
/// Check if any state changes have occured, from alternate input sources
/// Check if any state changes have occurred, from alternate input sources
/// </summary>
protected void CompareStates()
{
Expand Down Expand Up @@ -510,7 +510,7 @@ protected virtual void OnDestroy()

protected virtual void OnEnable()
{
#if UNITY_EDITOR || UNITY_WSA
#if UNITY_WSA || UNITY_STANDALONE_WIN
if (mKeywordRecognizer != null && !KeywordRequiresGaze)
{
SetKeywordListener(true);
Expand All @@ -520,7 +520,6 @@ protected virtual void OnEnable()

protected virtual void OnDisable()
{
//SetKeywordListener(false);
OnFocusExit();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using UnityEngine.Events;
using HoloToolkit.Unity.InputModule;

#if UNITY_EDITOR || UNITY_WSA
#if UNITY_WSA || UNITY_STANDALONE_WIN
using UnityEngine.Windows.Speech;
#endif

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

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

Expand Down Expand Up @@ -190,12 +190,11 @@ protected override void Update()

}

#if UNITY_EDITOR || UNITY_WSA
#if UNITY_WSA || UNITY_STANDALONE_WIN
protected override void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
base.KeywordRecognizer_OnPhraseRecognized(args);

//base.KeywordRecognizer_OnPhraseRecognized(args);
// Check to make sure the recognized keyword matches, then invoke the corresponding method.
if ((!KeywordRequiresGaze || HasGaze) && mKeywordDictionary != null)
{
Expand Down
29 changes: 17 additions & 12 deletions Assets/HoloToolkit-Examples/SavingSpatialMeshes/DebugText.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
using UnityEngine;
using System.Collections;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

[RequireComponent(typeof(TextMesh))]
public class DebugText : MonoBehaviour
{
private TextMesh mText;
using UnityEngine;

private void Awake()
namespace HoloToolkit.Examples
{
[RequireComponent(typeof(TextMesh))]
public class DebugText : MonoBehaviour
{
mText = GetComponent<TextMesh>();
}
private TextMesh mText;

public void SetText(string text)
{
mText.text = text;
private void Awake()
{
mText = GetComponent<TextMesh>();
}

public void SetText(string text)
{
mText.text = text;
}
}
}
22 changes: 14 additions & 8 deletions Assets/HoloToolkit-Examples/SavingSpatialMeshes/LevelManager.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
using UnityEngine;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;
using UnityEngine.SceneManagement;

public class LevelManager : MonoBehaviour
namespace HoloToolkit.Examples
{
public void LoadNextScene()
public class LevelManager : MonoBehaviour
{
int sceneIndex = SceneManager.GetActiveScene().buildIndex + 1;
if (sceneIndex >= SceneManager.sceneCountInBuildSettings)
public void LoadNextScene()
{
sceneIndex = 0;
}
int sceneIndex = SceneManager.GetActiveScene().buildIndex + 1;
if (sceneIndex >= SceneManager.sceneCountInBuildSettings)
{
sceneIndex = 0;
}

SceneManager.LoadScene(sceneIndex);
SceneManager.LoadScene(sceneIndex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Linq;
using UnityEngine;

#if UNITY_EDITOR || UNITY_WSA
#if UNITY_WSA || UNITY_STANDALONE_WIN
using UnityEngine.Windows.Speech;
#endif

Expand Down Expand Up @@ -195,7 +195,7 @@ public string DetailsText
private string spaceQueryDescription;
private string objectPlacementDescription;
private uint trackedHandsCount = 0;
#if UNITY_EDITOR || UNITY_WSA
#if UNITY_WSA || UNITY_STANDALONE_WIN
private KeywordRecognizer keywordRecognizer;

// Functions
Expand Down Expand Up @@ -268,7 +268,6 @@ private static void ToggleProcessedMesh()

private void Update()
{
// Updates
Update_DebugDisplay(Time.deltaTime);
Update_KeyboardInput(Time.deltaTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,52 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ApplicationViewManagerEditButton : MonoBehaviour
namespace HoloToolkit.Unity.Tests
{
public Text field;
public void StartEdit()
[RequireComponent(typeof(ApplicationViewManager))]
public class ApplicationViewManagerEditButton : MonoBehaviour
{
StartCoroutine(OpenViewEdit());
}
public IEnumerator OpenViewEdit()
{
string result = null;
var avm = this.GetComponent<HoloToolkit.Unity.ApplicationViewManager>();
yield return avm.OnLaunchXamlView<string>("TestPage", s => result = s);
yield return new WaitUntil(() => result != null);
if (field!=null)
public delegate void LaunchXmlView(string result);

/// <summary>
/// Event to subscribe to when a text result is returned from the xml view.
/// </summary>
public event LaunchXmlView OnResult;

public Text Field;

private ApplicationViewManager viewManager;

private void Awake()
{
viewManager = gameObject.EnsureComponent<ApplicationViewManager>();
}

public void StartEdit()
{
StartCoroutine(OpenViewEdit());
}

private IEnumerator OpenViewEdit()
{
field.text = result;
string result = string.Empty;

yield return viewManager.OnLaunchXamlView<string>("TestPage", s => result = s);

yield return new WaitUntil(() => !string.IsNullOrEmpty(result));

if (OnResult != null)
{
OnResult(result);
}

if (Field != null)
{
Field.text = result;
}
}
}
}
Loading

0 comments on commit 327b007

Please sign in to comment.