예제 #1
0
        private void ResponseDelegate(HTTPRequest originalRequest, HTTPResponse response)
        {
            switch (originalRequest.State)
            {
            case HTTPRequestStates.Finished:
                Log.Debug($"url = {originalRequest.Uri} 结果=  " + response.DataAsText);
                if (response.IsSuccess)
                {
                    ResponseData responseData = JsonHelper.FromJson <ResponseData>(response.DataAsText);
                    if (responseData.status == 0)
                    {
                        if (null != Game.Hotfix.OnGetNetLineSwith)
                        {
                            //热更层网络控件已初始化,由热更层处理
                            Game.Hotfix.OnGetNetLineSwith.Invoke(responseData.data);
                        }
                        else
                        {
                            //热更层未初始化,直接保存新域名
                            int serverType = PlayerPrefsMgr.mInstance.GetInt(PlayerPrefsKeys.SERVER_TYPE, 2);
                            PlayerPrefsMgr.mInstance.SetString($"{PlayerPrefsKeys.NET_LINE_SWITCH_INFO}{serverType}", responseData.data);
                            PlayerPrefs.Save();
                            NetLineSwitchData lineSwitchData = JsonHelper.FromJson <NetLineSwitchData>(responseData.data);
                            UpdateNetLineWithInfo(lineSwitchData);
                        }
                    }
                }
                break;

            default:
                break;
            }
        }
예제 #2
0
        private void UpdateNetLineWithInfo(NetLineSwitchData lineSwitchData)
        {
            int    serverType = PlayerPrefsMgr.mInstance.GetInt(PlayerPrefsKeys.SERVER_TYPE, 2);
            int    selectID   = lineSwitchData.selector;
            string userChoice = PlayerPrefsMgr.mInstance.GetString($"{PlayerPrefsKeys.CURRENT_SERVER_USER_CHOICEID}{serverType}", string.Empty);

            if (!string.IsNullOrEmpty(userChoice))
            {
                selectID = Convert.ToInt32(userChoice);
            }
            PlayerPrefsMgr.mInstance.SetInt($"{PlayerPrefsKeys.CURRENT_USING_SERVERID}{serverType}", selectID);

            foreach (LineInfo lineInfo in lineSwitchData.list)
            {
                if (lineInfo.id == selectID)
                {
                    if (!string.IsNullOrEmpty(lineInfo.http))
                    {
                        PlayerPrefsMgr.mInstance.SetString($"{PlayerPrefsKeys.CURRENT_SERVER_HTTP_DOMAIN}{serverType}", lineInfo.http);
                    }
                    if (!string.IsNullOrEmpty(lineInfo.sck))
                    {
                        PlayerPrefsMgr.mInstance.SetString($"{PlayerPrefsKeys.CURRENT_SERVER_SCK_DOMAIN}{serverType}", lineInfo.sck);
                    }
                    if (!string.IsNullOrEmpty(lineInfo.res))
                    {
                        PlayerPrefsMgr.mInstance.SetString($"{PlayerPrefsKeys.CURRENT_SERVER_RES_DOMAIN}{serverType}", lineInfo.res);
                    }
                }
            }
            PlayerPrefs.Save();
        }