/// <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; } } }); }); }
private void OnGUI() { GUIStyle style = "box"; style.fontSize = 35; GUI.skin.textField.fontSize = 32; GUI.skin.label.fontSize = 35; GUI.skin.button.fontSize = 30; GUILayout.Label("URL:"); customURL = GUILayout.TextField(customURL, GUILayout.Width(Screen.width), GUILayout.Height(60)); GUILayout.BeginHorizontal(); if (GUILayout.Button("Ping", GUILayout.Height(60))) { UnityPingManager.Ping(customURL, resultCallBack: ResultCallBack); } if (GUILayout.Button("Ping List All", GUILayout.Height(60))) { foreach (var item in hostLists) { UnityPingManager.Ping(item, pingTimes: pingTime, resultCallBack: ResultCallBack); } } if (GUILayout.Button("PingGetOptimalItem", GUILayout.Height(60))) { UnityPingManager.PingGetOptimalItem(hostLists.ToArray(), (res) => { resultString.Add(res.ToString()); }, pingTimes: pingTime); } if (GUILayout.Button("Clear", GUILayout.Height(60))) { resultString.Clear(); } GUILayout.EndHorizontal(); GUILayout.Label("Ping Times:"); pingTime = int.Parse(GUILayout.TextField(pingTime.ToString(), GUILayout.Width(Screen.width), GUILayout.Height(60))); pos = GUILayout.BeginScrollView(pos); foreach (var item in resultString) { GUILayout.Box(item, style); } GUILayout.EndScrollView(); }
/// <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); } }); }); }