예제 #1
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;
            }
        }
예제 #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;
            }

            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;
            }
        }