コード例 #1
0
    /// <summary>
    /// 下载大区服务器列表
    /// </summary>
    public void DownloadRegionServerList(string url, string country_code, Action <string, GameServerAreaDataGenerate> OnCompleted)
    {
        DataTableExtend.DownLoadTableConfig <GameServerAreaDataGenerate>(url, (dataList) =>
        {
            if (dataList == null)
            {
                if (OnCompleted != null)
                {
                    OnCompleted("download fail!", null);
                }
                return;
            }

            if (!string.IsNullOrEmpty(country_code))
            {
                foreach (var item in dataList)
                {
                    if (ArrayContains(item.m_CountryCode, country_code))
                    {
                        Debug.Log("选定大区key:" + item.m_key);
                        if (OnCompleted != null)
                        {
                            OnCompleted(null, item);
                        }
                        return;
                    }
                }
            }

            Debug.Log("使用ping选择大区:" + dataList.Count);
            List <string> specialServerHostList = new List <string>();
            foreach (var item in dataList)
            {
                specialServerHostList.Add(item.m_SpecialServerHost);
            }
            UnityPingManager.PingGetOptimalItem(specialServerHostList.ToArray(), (statistics) =>
            {
                Debug.Log("选出最优Ping:" + statistics);
                foreach (var item in dataList)
                {
                    if (item.m_SpecialServerHost == statistics.host)
                    {
                        if (OnCompleted != null)
                        {
                            OnCompleted(null, item);
                        }
                        break;
                    }
                }
            });
        });
    }
コード例 #2
0
    protected override void OnFlowStart(params object[] paras)
    {
        //GameServerAreaData gameServerArea = flowManager.GetVariable<GameServerAreaData>(P_GameServerAreaData);

        string hotupdateConfigUrl = null;

        try
        {
            string url = flowManager.GetVariable <string>(P_GameServerAreaDataConfigURL);
            Debug.Log("P_GameServerAreaDataConfigURL:" + url);
            int lastIndex = url.LastIndexOf("/");

            hotupdateConfigUrl = url;// Path.GetDirectoryName(url) + "/"+ P_HotUpdatePathData;
            hotupdateConfigUrl = hotupdateConfigUrl.Replace(hotupdateConfigUrl.Substring(lastIndex), "/" + P_HotUpdatePathData);
            Debug.Log("hotupdateConfigUrl:" + hotupdateConfigUrl);
        }
        catch (Exception e)
        {
            Finish("Parse URL failed :" + e);
            return;
        }

        DataTableExtend.DownLoadTableConfig <HotUpdatePathData>(hotupdateConfigUrl, GetHotUpdatePath);
    }
コード例 #3
0
    /// <summary>
    /// 下载大区服务器列表
    /// </summary>
    public void DownloadRegionServerList(string url, string country_code, Action <string, GameServerAreaData> OnCompleted)
    {
        DataTableExtend.DownLoadTableConfig <GameServerAreaData>(url, (dataList, urlError) =>
        {
            if (!string.IsNullOrEmpty(urlError))
            {
                Debug.LogError("DownloadRegionServerList download fail!");
                if (OnCompleted != null)
                {
                    OnCompleted("download fail! " + urlError, null);
                }
                return;
            }
            if (dataList.Count == 0)
            {
                Debug.LogError("DownloadRegionServerList GameServerAreaData is Empty!");
                if (OnCompleted != null)
                {
                    OnCompleted("GameServerAreaData is Empty!", null);
                }
                return;
            }

            if (!string.IsNullOrEmpty(country_code))
            {
                //根据国家选择大区
                foreach (var item in dataList)
                {
                    if (ArrayContains(item.m_CountryCode, country_code))
                    {
                        Debug.Log("国家选定大区key:" + item.m_key);
                        GameInfoCollecter.AddNetworkStateInfoValue("选定大区", item.m_key);
                        if (OnCompleted != null)
                        {
                            OnCompleted(null, item);
                        }
                        return;
                    }
                }
            }
            //根据大洲选择大区
            string continentName = GetContinentByCountryCode(country_code);
            if (!string.IsNullOrEmpty(continentName))
            {
                foreach (var item in dataList)
                {
                    if (ArrayContains(item.m_ContinentName, continentName))
                    {
                        Debug.Log("根据大洲选定大区key:" + item.m_key);
                        GameInfoCollecter.AddNetworkStateInfoValue("选定大区", item.m_key);
                        if (OnCompleted != null)
                        {
                            OnCompleted(null, item);
                        }
                        return;
                    }
                }
            }

            Debug.Log("使用ping选择大区:" + dataList.Count);
            List <string> specialServerHostList = new List <string>();
            foreach (var item in dataList)
            {
                specialServerHostList.Add(item.m_SpecialServerHost);
            }
            UnityPingManager.PingGetOptimalItem(specialServerHostList.ToArray(), (statistics) =>
            {
                Debug.Log("选出最优Ping:" + statistics);
                GameServerAreaData saData = null;
                foreach (var item in dataList)
                {
                    if (item.m_SpecialServerHost == statistics.host)
                    {
                        saData = item;
                        break;
                    }
                }

                string error = null;
                if (saData == null)
                {
                    error = "Select Ping Result Error!";
                }
                if (OnCompleted != null)
                {
                    OnCompleted(error, saData);
                }
            });
        });
    }