Esempio n. 1
0
        /// <summary>
        /// HTTPサーバー更新
        /// </summary>
        private void HttpServerUpdate()
        {
            System.Action <AsyncOperation> readConfig = (x) => {
                var u = (UnityWebRequestAsyncOperation)x;
                HttpServerConfigState state;
                if (!u.webRequest.isNetworkError && !u.webRequest.isHttpError)
                {
                    var text = u.webRequest.downloadHandler.text;
                    m_HttpServerConfig = JsonUtility.FromJson <HttpServerConfig>(text);
                    state = HttpServerConfigState.Valid;
                }
                else
                {
                    state = HttpServerConfigState.Invalid;
                }
                if (m_HttpServerConfigState == HttpServerConfigState.ConnectingAndChange)
                {
                    m_HttpServerConfigState = HttpServerConfigState.Change;
                }
                else
                {
                    m_HttpServerConfigState = state;
                }
                m_DisplayDirty = true;
            };

            if (m_HttpServerConfigState == HttpServerConfigState.Invalid)
            {
                //コンフィグが無いなら
                m_HttpServerConfigState = HttpServerConfigState.Connecting;

                var port            = EditorPrefs.GetInt(HttpServer.kHttpServerPortEditorPrefsKey, HttpServer.kHttpServerPortDefault);
                var url             = GetUrl(port);
                var unityWebRequest = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET, new DownloadHandlerBuffer(), null);
                var request         = unityWebRequest.SendWebRequest();
                request.completed += readConfig;
            }
            else if (m_HttpServerConfigState == HttpServerConfigState.Change)
            {
                //コンフィグが変更されているなら
                m_HttpServerConfigState = HttpServerConfigState.Connecting;

                var urlSb = new StringBuilder();
                var port  = EditorPrefs.GetInt(HttpServer.kHttpServerPortEditorPrefsKey, HttpServer.kHttpServerPortDefault);
                urlSb.Append(GetUrl(port));
                urlSb.Append('?');
                urlSb.Append("MaxBandwidthBps=");
                urlSb.Append(m_HttpServerConfig.MaxBandwidthBps);
                var url             = urlSb.ToString();
                var unityWebRequest = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET, new DownloadHandlerBuffer(), null);
                var request         = unityWebRequest.SendWebRequest();
                request.completed += readConfig;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// HTTPサーバー終了時イベント
 /// </summary>
 private void OnWillFinishHttpServer()
 {
     m_Enable = false;
     m_HttpServerConfigState = HttpServerConfigState.Invalid;
 }
Esempio n. 3
0
        /// <summary>
        /// コンフィグ描画
        /// </summary>
        private void OnGUIForConfig()
        {
            var config   = ((m_HttpServerConfigState != HttpServerConfigState.Invalid)? m_HttpServerConfig: new HttpServerConfig());
            var isChange = false;

            var GuiEnabledOld = GUI.enabled;

            switch (m_HttpServerConfigState)
            {
            case HttpServerConfigState.Valid:
            case HttpServerConfigState.Connecting:
            case HttpServerConfigState.ConnectingAndChange:
                GUI.enabled = true;
                break;

            default:
                GUI.enabled = false;
                break;
            }

            var maxBandwidthKind = System.Array.IndexOf(kBandwidthBps, config.MaxBandwidthBps);

            if (maxBandwidthKind < 0)
            {
                maxBandwidthKind        = kBandwidthKindContent.Length - 1;
                m_IsCustomBandwidthKind = true;
            }
            EditorGUI.BeginChangeCheck();
            maxBandwidthKind = EditorGUILayout.Popup(kMaxBandwidthKindContent, maxBandwidthKind, kBandwidthKindContent);
            if (EditorGUI.EndChangeCheck())
            {
                if (maxBandwidthKind < kBandwidthBps.Length)
                {
                    config.MaxBandwidthBps  = kBandwidthBps[maxBandwidthKind];
                    m_IsCustomBandwidthKind = false;
                    isChange = true;
                }
                else
                {
                    m_IsCustomBandwidthKind = true;
                }
            }

            var GuiEnabledOld2 = GUI.enabled;

            if (GUI.enabled)
            {
                GUI.enabled = m_IsCustomBandwidthKind;
            }
            EditorGUI.BeginChangeCheck();
            var maxBandwidthBps = EditorGUILayout.IntField(kMaxBandwidthBpsContent, config.MaxBandwidthBps);

            if (EditorGUI.EndChangeCheck())
            {
                config.MaxBandwidthBps = maxBandwidthBps;
                isChange = true;
            }
            GUI.enabled = GuiEnabledOld2;

            if (isChange)
            {
                m_HttpServerConfig = config;
                if (m_HttpServerConfigState == HttpServerConfigState.Connecting)
                {
                    m_HttpServerConfigState = HttpServerConfigState.ConnectingAndChange;
                }
                else
                {
                    m_HttpServerConfigState = HttpServerConfigState.Change;
                }
            }
            GUI.enabled = GuiEnabledOld;
        }