5 using System.Collections.Generic;
16 [Tooltip(
"The keyword to handle.")]
19 [Tooltip(
"The handler to be invoked.")]
26 [Tooltip(
"The keywords to be recognized and optional keyboard shortcuts.")]
32 [Tooltip(
"Determines if this handler is a global listener, not connected to a specific GameObject.")]
38 [Tooltip(
"Keywords are persistent across all scenes. This Speech Input Handler instance will not be destroyed when loading a new scene.")]
42 private readonly Dictionary<string, UnityEvent> responses =
new Dictionary<string, UnityEvent>();
54 if (PersistentKeywords)
56 gameObject.DontDestroyOnLoad();
61 int keywordCount = Keywords.Length;
62 for (
int index = 0; index < keywordCount; index++)
65 string keyword = keywordAndResponse.
Keyword.ToLower().TrimEnd();
67 if (responses.ContainsKey(keyword))
69 Debug.LogError(
"Duplicate keyword '" + keyword +
"' specified in '" + gameObject.name +
"'.");
73 responses.Add(keyword, keywordAndResponse.
Response);
96 UnityEvent keywordResponse;
99 if (enabled && responses.TryGetValue(eventData.
RecognizedText.ToLower(), out keywordResponse))
101 keywordResponse.Invoke();