示例#1
0
        // Use this for initialization
        IEnumerator Start()
        {
            // get the singleton instance
            _mSpeechDetectionPlugin = SpeechDetectionUtils.GetInstance();

            // check the reference to the plugin
            if (null == _mSpeechDetectionPlugin)
            {
                Debug.LogError("Proxy Speech Detection Plugin is not set!");
                yield break;
            }

            // wait for plugin to become available
            while (!_mSpeechDetectionPlugin.IsAvailable())
            {
                yield return(null);
            }

            // no need to display a warning if the plugin is available
            SpeechDetectionUtils.SetActive(false, _mTextWaiting);

            // display the UI controls
            SpeechDetectionUtils.SetActive(true,
                                           _mDropDownDialects, _mDropDownLanguages,
                                           _mTextDictation, _mTextSummary);

            // subscribe to events
            _mSpeechDetectionPlugin.AddListenerOnDetectionResult(HandleDetectionResult);

            // Get languages from plugin,
            _mSpeechDetectionPlugin.GetLanguages((languageResult) =>
            {
                _mLanguageResult = languageResult;

                // prepare the language drop down items
                SpeechDetectionUtils.PopulateLanguagesDropdown(_mDropDownLanguages, _mLanguageResult);

                // subscribe to language change events
                if (_mDropDownLanguages)
                {
                    _mDropDownLanguages.onValueChanged.AddListener(delegate {
                        SpeechDetectionUtils.HandleLanguageChanged(_mDropDownLanguages,
                                                                   _mDropDownDialects,
                                                                   _mLanguageResult,
                                                                   _mSpeechDetectionPlugin);
                    });
                }

                // subscribe to dialect change events
                if (_mDropDownDialects)
                {
                    _mDropDownDialects.onValueChanged.AddListener(delegate {
                        SpeechDetectionUtils.HandleDialectChanged(_mDropDownDialects,
                                                                  _mLanguageResult,
                                                                  _mSpeechDetectionPlugin);
                    });
                }

                // Disabled until a language is selected
                SpeechDetectionUtils.DisableDialects(_mDropDownDialects);

                // set the default language
                SpeechDetectionUtils.RestoreLanguage(_mDropDownLanguages);

                // set the default dialect
                SpeechDetectionUtils.RestoreDialect(_mDropDownDialects);
            });
        }
示例#2
0
        /// <summary>
        /// Display GUI in the editor panel
        /// </summary>
        private void OnGUI()
        {
            EditorProxySpeechDetectionPlugin plugin = EditorProxySpeechDetectionPlugin.GetInstance();

            bool enabled = EditorProxySpeechDetectionPlugin.IsEnabled();

            if (!enabled)
            {
                if (null != plugin)
                {
                    // unsubscribe to events
                    plugin.RemoveListenerOnDetectionResult(HandleDetectionResult);
                }
            }

            bool isCompiling = EditorApplication.isCompiling;

            if (isCompiling)
            {
                GUI.enabled = false;
            }
            bool newEnabled = GUILayout.Toggle(enabled, "Enabled");

            if (newEnabled != enabled)
            {
                EditorProxySpeechDetectionPlugin.SetEnabled(newEnabled);
            }
            if (isCompiling)
            {
                GUI.enabled = true;
            }

            if (null != plugin && plugin.IsAvailable())
            {
                GUILayout.Label("IsAvailable: true");
            }
            else
            {
                GUILayout.Label("IsAvailable: false");
            }

            if (isCompiling ||
                !newEnabled)
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("Open Browser Tab"))
            {
                if (null != plugin)
                {
                    SetTextStatus("Open Browser Tab");
                    plugin.ManagementOpenBrowserTab();
                }
            }
            if (GUILayout.Button("Close Browser Tab"))
            {
                if (null != plugin)
                {
                    SetTextStatus("Close Browser Tab");
                    plugin.ManagementCloseBrowserTab();
                }
            }
            GUILayout.BeginHorizontal(GUILayout.Width(position.width));
            int port = 5000;

            if (null != plugin)
            {
                port = plugin._mPort;
            }
            string strPort = GUILayout.TextField(string.Format("{0}", port));

            if (int.TryParse(strPort, out port))
            {
                if (null != plugin)
                {
                    plugin._mPort = port;
                }
            }
            if (GUILayout.Button("Set Proxy Port"))
            {
                if (null != plugin)
                {
                    SetTextStatus(string.Format("Set Proxy Tab: port={0}", plugin._mPort));
                    plugin.ManagementSetProxyPort(plugin._mPort);
                }
            }
            GUILayout.EndHorizontal();
            if (GUILayout.Button("Launch Proxy"))
            {
                if (null != plugin)
                {
                    SetTextStatus("Launch Proxy");
                    plugin.ManagementLaunchProxy();
                }
            }
            if (GUILayout.Button("Close Proxy"))
            {
                if (null != plugin)
                {
                    SetTextStatus("Close Proxy");
                    plugin.ManagementCloseProxy();
                }
            }

            int newLanguage = EditorGUILayout.Popup(_mLanguage, _mLanguages);

            if (_mLanguage != newLanguage)
            {
                _mLanguage = newLanguage;
                if (null != plugin)
                {
                    SpeechDetectionUtils.HandleLanguageChanged(_mLanguages,
                                                               _mLanguage,
                                                               out _mDialects,
                                                               ref _mDialect,
                                                               _mLanguageResult,
                                                               plugin);
                }
            }

            if (!isCompiling &&
                newEnabled)
            {
                GUI.enabled = _mLanguage != 0;
            }
            int newDialect = EditorGUILayout.Popup(_mDialect, _mDialects);

            if (_mDialect != newDialect)
            {
                _mDialect = newDialect;
                if (null != plugin)
                {
                    SpeechDetectionUtils.HandleDialectChanged(_mDialects,
                                                              _mDialect,
                                                              _mLanguageResult,
                                                              plugin);
                }
            }
            if (!isCompiling &&
                newEnabled)
            {
                GUI.enabled = true;
            }

            for (int index = 0; index < _mWords.Count; ++index)
            {
                GUILayout.Label(_mWords[index]);
            }

            GUILayout.Label(_sTextStatus, GUILayout.Width(position.width), GUILayout.Height(40));

            if (isCompiling ||
                !newEnabled)
            {
                GUI.enabled = true;
            }
        }
示例#3
0
        // Use this for initialization
        IEnumerator Start()
        {
            // get the singleton instance
            _mSpeechDetectionPlugin = SpeechDetectionUtils.GetInstance();

            // check the reference to the plugin
            if (null == _mSpeechDetectionPlugin)
            {
                Debug.LogError("WebGL Speech Detection Plugin is not set!");
                yield break;
            }

            // wait for plugin to become available
            while (!_mSpeechDetectionPlugin.IsAvailable())
            {
                yield return(null);
            }

            // no need to display a warning if the plugin is available
            SpeechDetectionUtils.SetActive(false, _mTextWarning);

            // make the dropdowns non-interactive
            SpeechDetectionUtils.SetInteractable(false,
                                                 _mDropDownLanguages, _mDropDownDialects);

            // show UI controls
            SpeechDetectionUtils.SetActive(true,
                                           _mDropDownDialects, _mDropDownLanguages,
                                           _mImageWords, _mTextSummary);

            // subscribe to events
            _mSpeechDetectionPlugin.AddListenerOnDetectionResult(HandleDetectionResult);

            // Get languages from plugin,
            _mSpeechDetectionPlugin.GetLanguages((languageResult) =>
            {
                _mLanguageResult = languageResult;

                // prepare the language drop down items
                SpeechDetectionUtils.PopulateLanguagesDropdown(_mDropDownLanguages, _mLanguageResult);

                // make the dropdowns interactive
                SpeechDetectionUtils.SetInteractable(true,
                                                     _mDropDownLanguages, _mDropDownDialects);

                // subscribe to language change events
                if (_mDropDownLanguages)
                {
                    _mDropDownLanguages.onValueChanged.AddListener(delegate {
                        SpeechDetectionUtils.HandleLanguageChanged(_mDropDownLanguages,
                                                                   _mDropDownDialects,
                                                                   _mLanguageResult,
                                                                   _mSpeechDetectionPlugin);
                    });
                }

                // subscribe to dialect change events
                if (_mDropDownDialects)
                {
                    _mDropDownDialects.onValueChanged.AddListener(delegate {
                        SpeechDetectionUtils.HandleDialectChanged(_mDropDownDialects,
                                                                  _mLanguageResult,
                                                                  _mSpeechDetectionPlugin);
                    });
                }

                // Disabled until a language is selected
                SpeechDetectionUtils.DisableDialects(_mDropDownDialects);

                // set the default language
                SpeechDetectionUtils.RestoreLanguage(_mDropDownLanguages);

                // set the default dialect
                SpeechDetectionUtils.RestoreDialect(_mDropDownDialects);
            });

            // get all the words in the UI
            foreach (Example02Word word in GameObject.FindObjectsOfType <Example02Word>())
            {
                Text text = word.GetComponentInChildren <Text>();
                if (text)
                {
                    _mWords[text.text.ToLower()] = word;
                }
            }
        }
        /// <summary>
        /// Display GUI in the editor panel
        /// </summary>
        private void OnGUI()
        {
            EditorProxySpeechDetectionPlugin plugin = EditorProxySpeechDetectionPlugin.GetInstance();

            bool enabled = EditorProxySpeechDetectionPlugin.IsEnabled();

            if (!enabled)
            {
                if (null != plugin)
                {
                    // unsubscribe to events
                    plugin.RemoveListenerOnDetectionResult(HandleDetectionResult);
                }
            }

            bool isCompiling = EditorApplication.isCompiling;

            if (isCompiling)
            {
                GUI.enabled = false;
            }
            bool newEnabled = GUILayout.Toggle(enabled, "Enabled");

            if (newEnabled != enabled)
            {
                EditorProxySpeechDetectionPlugin.SetEnabled(newEnabled);
            }
            if (isCompiling)
            {
                GUI.enabled = true;
            }

            if (null != plugin && plugin.IsAvailable())
            {
                GUILayout.Label("IsAvailable: true");
            }
            else
            {
                GUILayout.Label("IsAvailable: false");
            }

            if (isCompiling ||
                !newEnabled)
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("Open Browser Tab"))
            {
                if (null != plugin)
                {
                    SetTextStatus("Open Browser Tab");
                    plugin.ManagementOpenBrowserTab();
                }
            }
            if (GUILayout.Button("Close Browser Tab"))
            {
                if (null != plugin)
                {
                    SetTextStatus("Close Browser Tab");
                    plugin.ManagementCloseBrowserTab();
                }
            }
            GUILayout.BeginHorizontal(GUILayout.Width(position.width));
            int port = 5000;

            if (null != plugin)
            {
                port = plugin._mPort;
            }
            string strPort = GUILayout.TextField(string.Format("{0}", port));

            if (int.TryParse(strPort, out port))
            {
                if (null != plugin)
                {
                    plugin._mPort = port;
                }
            }
            if (GUILayout.Button("Set Proxy Port"))
            {
                if (null != plugin)
                {
                    SetTextStatus(string.Format("Set Proxy Tab: port={0}", plugin._mPort));
                    plugin.ManagementSetProxyPort(plugin._mPort);
                }
            }
            GUILayout.EndHorizontal();
            if (GUILayout.Button("Launch Proxy"))
            {
                if (null != plugin)
                {
                    SetTextStatus("Launch Proxy");
                    plugin.ManagementLaunchProxy();
                }
            }
            if (GUILayout.Button("Close Proxy"))
            {
                if (null != plugin)
                {
                    SetTextStatus("Close Proxy");
                    plugin.ManagementCloseProxy();
                }
            }

            int newLanguage = EditorGUILayout.Popup(_mLanguage, _mLanguages);

            if (_mLanguage != newLanguage)
            {
                _mLanguage = newLanguage;
                if (null != plugin)
                {
                    SpeechDetectionUtils.HandleLanguageChanged(_mLanguages,
                                                               _mLanguage,
                                                               out _mDialects,
                                                               ref _mDialect,
                                                               _mLanguageResult,
                                                               plugin);
                }
            }

            if (!isCompiling &&
                newEnabled)
            {
                GUI.enabled = _mLanguage != 0;
            }
            int newDialect = EditorGUILayout.Popup(_mDialect, _mDialects);

            if (_mDialect != newDialect)
            {
                _mDialect = newDialect;
                if (null != plugin)
                {
                    SpeechDetectionUtils.HandleDialectChanged(_mDialects,
                                                              _mDialect,
                                                              _mLanguageResult,
                                                              plugin);
                }
            }
            if (!isCompiling &&
                newEnabled)
            {
                GUI.enabled = true;
            }

            GUI.skin.label.wordWrap = true;
            GUILayout.Label("Say any of the following words which will highlight when detected.", GUILayout.Width(position.width), GUILayout.Height(40));
            GUI.skin.label.wordWrap = false;

            Color oldColor = GUI.backgroundColor;

            foreach (KeyValuePair <string, MethodInfo> kvp in _mEditorCommands)
            {
                DateTime timer = _mTimers[kvp.Key];
                if (timer > DateTime.Now)
                {
                    GUI.backgroundColor = Color.red;
                }
                else
                {
                    GUI.backgroundColor = oldColor;
                }
                GUILayout.Button(kvp.Key);
            }
            GUI.backgroundColor = oldColor;

            GUILayout.Label(_sTextStatus, GUILayout.Width(position.width), GUILayout.Height(40));

            if (isCompiling ||
                !newEnabled)
            {
                GUI.enabled = true;
            }
        }