using System; using UnityEngine; public class NetworkConfig { public static bool IsNeedCheckRes; private static string _IPListUrl; public static string AssetBundleUrl; public static string AssetBundleUrlBackup; public static string WebBlogUrl; public static string ApiUrl; public static string ApkKey; public static string _appid; public static string _cchid; public static string _appkey; public static string _channel; public static string _GDT_set_id; public static string _GDT_secret_key; public static string _GDT_channel; public static string _Table_Version; public static Action _Callback; public static string IPListUrl { get { if (string.IsNullOrEmpty(_IPListUrl)) return ControllUrlManager.ResUpdate; return _IPListUrl; } } public static string Table_Version { get { if (!string.IsNullOrEmpty(ControllUrlManager.Table_Version)) return ControllUrlManager.Table_Version; return _Table_Version; } } // public static void ReadNetworkConfig(Action callback) // { // // var strServerListPath = ""; // // #if UNITY_ANDROID && !UNITY_EDITOR // // strServerListPath = Application.streamingAssetsPath + "/NetworkConfig.txt"; // // #else // IOS PC Editor // // strServerListPath = "file://" + Application.streamingAssetsPath + "/NetworkConfig.txt"; // // #endif // _Callback = callback; // AssetUpdateDownloaderTick.instance.LoadStreamingAsset("NetworkConfig.txt", DelConfig); // // LoadAssetBundle.Instance.LoadTableAsset(strServerListPath, DelConfig); // } public static void DelConfig(WWW assetWWW) { try { var text = assetWWW.text; #if Code_Encryption byte[] assetbytes = assetWWW.bytes; ResConvert.Dencypt(ref assetbytes); text = System.Text.Encoding.UTF8.GetString(assetbytes); #endif var lines = text.Split('\n'); foreach (var line in lines) { var lineSplit = GetConfigKeyValue(line); if (string.Compare(lineSplit[0], "IsNeedCheckRes") == 0) IsNeedCheckRes = bool.Parse(lineSplit[1]); else if (string.Compare(lineSplit[0], "IPListUrl") == 0) _IPListUrl = lineSplit[1]; else if (string.Compare(lineSplit[0], "AssetBundleUrl") == 0) AssetBundleUrl = lineSplit[1]; else if (string.Compare(lineSplit[0], "AssetBundleUrlBackup") == 0) AssetBundleUrlBackup = lineSplit[1]; else if (lineSplit[0] == "WebBlogUrl") WebBlogUrl = lineSplit[1]; else if (lineSplit[0] == "appid") _appid = lineSplit[1]; else if (lineSplit[0] == "cchid") _cchid = lineSplit[1]; else if (lineSplit[0] == "appkey") _appkey = lineSplit[1]; else if (lineSplit[0] == "channel") _channel = lineSplit[1]; else if (lineSplit[0] == "ApiUrl") ApiUrl = lineSplit[1]; else if (lineSplit[0] == "ApkKey") ApkKey = lineSplit[1]; else if (lineSplit[0] == "GDTSetId") _GDT_set_id = lineSplit[1]; else if (lineSplit[0] == "GDTSecretKey") _GDT_secret_key = lineSplit[1]; else if (lineSplit[0] == "GDTChannel") _GDT_channel = lineSplit[1]; else if (lineSplit[0] == "TableVersion") _Table_Version = lineSplit[1]; } } catch (Exception e) { GuiTextDebug.debug("load netfile fail:" + e); } if (_Callback != null) _Callback.Invoke(); } public static string[] GetConfigKeyValue(string line, char splitChar = '=') { var lineSplit = line.Split(splitChar); for (var i = 0; i < lineSplit.Length; ++i) lineSplit[i] = lineSplit[i].Trim('\r', ' ', '\n'); return lineSplit; } }