目标:使用听觉控制从一个场景切换到另一个场景。
问题:在 HoloLens 模拟器中启动应用程序时,第一个场景打开。当说“下一步”时,HoloLens 确实识别出该句子,但 sendMessage 没有打开该OnNextStep()
功能。
感谢您尝试提供帮助!:)
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Windows.Speech;
using System.Diagnostics;
using UnityEngine.SceneManagement;
public class KeywordManager : MonoBehaviour {
KeywordRecognizer keywordRecognizer = null;
Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>();
// Use this for initialization
void Start () {
keywords.Add("Next Step", () =>
{
SendMessage("OnNextStep", SendMessageOptions.DontRequireReceiver);
});
// Tell the KeywordRecognizer about our keywords.
keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray());
// Register a callback for the KeywordRecognizer and start recognizing!
keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
keywordRecognizer.Start();
}
private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
System.Action keywordAction;
if(keywords.TryGetValue(args.text, out keywordAction))
{
keywordAction.Invoke();
}
}
void OnNextstep()
{
UnityEngine.Debug.Log(this);
SceneManager.LoadScene("FirstStepScene");
}
// Update is called once per frame
void Update () {
}
}