From 1dafda4b442ed5c0efe75eb3b52f1ddbd0e7ec97 Mon Sep 17 00:00:00 2001 From: gaoxin Date: Fri, 22 Jan 2021 14:17:08 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=83=AD=E6=9B=B4=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E3=80=91=E7=BB=93=E6=9E=84=E6=90=AD=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AssetBundles/config.txt | 4 + AssetBundles/version.txt | 2 +- .../Scripts/ConstDefine/AppConst.cs | 5 +- Assets/LuaFramework/Scripts/Framework/App.cs | 11 ++ .../Scripts/Manager/ConfigManager.cs | 153 ++++++++++++++++++ .../Scripts/Manager/ConfigManager.cs.meta | 11 ++ Assets/Resources/config.txt | 4 + Assets/Resources/config.txt.meta | 7 + .../Manager/ResourcesUpdateManager.cs | 21 ++- 9 files changed, 214 insertions(+), 4 deletions(-) create mode 100644 AssetBundles/config.txt create mode 100644 Assets/LuaFramework/Scripts/Manager/ConfigManager.cs create mode 100644 Assets/LuaFramework/Scripts/Manager/ConfigManager.cs.meta create mode 100644 Assets/Resources/config.txt create mode 100644 Assets/Resources/config.txt.meta diff --git a/AssetBundles/config.txt b/AssetBundles/config.txt new file mode 100644 index 0000000000..a9c5b7f715 --- /dev/null +++ b/AssetBundles/config.txt @@ -0,0 +1,4 @@ +{"subChannel":"1", +"buglyId":"261348dcd3", +"channel":"pc", +"serverUrl":"http://60.1.1.23:8080/"} \ No newline at end of file diff --git a/AssetBundles/version.txt b/AssetBundles/version.txt index d252578df2..e7e73835a5 100644 --- a/AssetBundles/version.txt +++ b/AssetBundles/version.txt @@ -1 +1 @@ -{"buglyId":"261348dcd3", "channel":"pc", "resUrl":"http://60.1.1.12/jieling_dl/dev/assetBundles/subChannal094-test/", "packageVersion":"0.2", "subChannel":"1", "version":"0.15.0", "serverUrl":"http://60.1.1.23:8080/"} \ No newline at end of file +{"subChannel":"1", "buglyId":"261348dcd3", "channel":"pc", "resUrl":"http://60.1.1.12/jieling_dl/dev/assetBundles/subChannal094-test/", "packageVersion":"0.2", "version":"0.15.0", "serverUrl":"http://60.1.1.23:8080/"} \ No newline at end of file diff --git a/Assets/LuaFramework/Scripts/ConstDefine/AppConst.cs b/Assets/LuaFramework/Scripts/ConstDefine/AppConst.cs index cc239a6a3c..d05cf15bff 100644 --- a/Assets/LuaFramework/Scripts/ConstDefine/AppConst.cs +++ b/Assets/LuaFramework/Scripts/ConstDefine/AppConst.cs @@ -164,8 +164,9 @@ namespace GameLogic public static string LaQi_JoinRoom_Url = string.Empty; //拉起应用链接 - public const string LoadingMD5Flie = "files.txt"; //加载界面更新MD5文件 - public const string GameVersionFile = "version.txt"; //游戏版本号文件 + public const string LoadingMD5Flie = "files.txt"; //加载界面更新MD5文件 + public const string GameVersionFile = "version.txt"; //游戏版本号文件 + public const string GameConfigFile = "config.txt"; //游戏版本号文件 public static int UserId; //用户ID public static int Token; //用户Token diff --git a/Assets/LuaFramework/Scripts/Framework/App.cs b/Assets/LuaFramework/Scripts/Framework/App.cs index 343bc0ecfc..f5b47afc24 100644 --- a/Assets/LuaFramework/Scripts/Framework/App.cs +++ b/Assets/LuaFramework/Scripts/Framework/App.cs @@ -180,12 +180,23 @@ public class App : UnitySingleton return VersionManager.Instance; } } + /// + /// 配置数据管理器管理器 + /// + public static ConfigManager ConfigMgr + { + get + { + return ConfigManager.Instance; + } + } /// /// 初始化 /// public void Initialize() { + ConfigMgr.Init(); VersionMgr.Initialize(); } diff --git a/Assets/LuaFramework/Scripts/Manager/ConfigManager.cs b/Assets/LuaFramework/Scripts/Manager/ConfigManager.cs new file mode 100644 index 0000000000..e2c83228e2 --- /dev/null +++ b/Assets/LuaFramework/Scripts/Manager/ConfigManager.cs @@ -0,0 +1,153 @@ +using UnityEngine; +using UnityEditor; +using GameCore; +using System.Collections; +using System.IO; +using System; + +namespace GameLogic +{ + public class MConfig + { + Hashtable info; + + public MConfig(string json) + { + info = MiniJSON.jsonDecode(json) as Hashtable; + } + + public string ToJson() + { + return MiniJSON.jsonEncode(info); + } + + public string GetInfo(string key) + { + if (info.ContainsKey(key)) + { + return info[key] as string; + } + return null; + } + + public void RemoveInfo(string key) + { + if (info.ContainsKey(key)) + { + info.Remove(key); + } + } + + public void SetInfo(string key, string value) + { + info[key] = value; + } + } + public class ConfigManager : Singleton + { + + /// + /// 版本号文件 + /// + const string configFile = "config"; + /// + /// 版本文件路径 + /// + string configFilePath + { + get + { + return AppConst.PersistentDataPath + configFile + ".txt"; + } + } + + MConfig StreamingInfo; + MConfig PersistentInfo; + MConfig NetInfo; + // 初始化 获取本地的数据 + public void Init() + { + try + { + if (File.Exists(configFilePath)) + { + PersistentInfo = new MConfig(File.ReadAllText(configFilePath, System.Text.Encoding.UTF8)); + } + } + catch (Exception e) + { + Debug.LogError(e); + } + + try + { + StreamingInfo = new MConfig(Resources.Load(configFile).text); + } + catch (Exception e) + { + Debug.LogError(e); + } + } + + public void SetNetInfo(string info) + { + + try + { + NetInfo = new MConfig(info); + SaveToFiles(); + } + catch (Exception e) + { + Debug.LogError(e); + } + } + + /// + /// 保存到文件 + /// + void SaveToFiles() + { + PersistentInfo = NetInfo; + string directoryPath = Path.GetDirectoryName(configFilePath); + if (!Directory.Exists(directoryPath)) Directory.CreateDirectory(directoryPath); + File.WriteAllText(configFilePath, PersistentInfo.ToJson(), System.Text.Encoding.UTF8); + } + + /// + /// + /// + /// + /// + public string GetConfigInfo(string key) + { + string v = GetConfigNetInfo(key); + if (v != null) return v; + v = GetConfigPersistentInfo(key); + if (v != null) return v; + v = GetConfigStreamingInfo(key); + if (v != null) return v; + return null; + } + public string GetConfigNetInfo(string key) + { + if (NetInfo == null) return null; + string v = NetInfo.GetInfo(key); + return v; + } + public string GetConfigPersistentInfo(string key) + { + if (PersistentInfo == null) return null; + string v = PersistentInfo.GetInfo(key); + return v; + } + public string GetConfigStreamingInfo(string key) + { + if (StreamingInfo == null) return null; + string v = StreamingInfo.GetInfo(key); + return v; + } + + + } +} diff --git a/Assets/LuaFramework/Scripts/Manager/ConfigManager.cs.meta b/Assets/LuaFramework/Scripts/Manager/ConfigManager.cs.meta new file mode 100644 index 0000000000..690450a906 --- /dev/null +++ b/Assets/LuaFramework/Scripts/Manager/ConfigManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 252b072fc95a44740976d9126b5b4626 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/config.txt b/Assets/Resources/config.txt new file mode 100644 index 0000000000..a9c5b7f715 --- /dev/null +++ b/Assets/Resources/config.txt @@ -0,0 +1,4 @@ +{"subChannel":"1", +"buglyId":"261348dcd3", +"channel":"pc", +"serverUrl":"http://60.1.1.23:8080/"} \ No newline at end of file diff --git a/Assets/Resources/config.txt.meta b/Assets/Resources/config.txt.meta new file mode 100644 index 0000000000..64e1d3c3a3 --- /dev/null +++ b/Assets/Resources/config.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 343cc3bd6dddfa64381bbe4c53e06a87 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Core/ResUpdate/Manager/ResourcesUpdateManager.cs b/Assets/Scripts/Core/ResUpdate/Manager/ResourcesUpdateManager.cs index a766fd97f5..ac15104c01 100644 --- a/Assets/Scripts/Core/ResUpdate/Manager/ResourcesUpdateManager.cs +++ b/Assets/Scripts/Core/ResUpdate/Manager/ResourcesUpdateManager.cs @@ -314,6 +314,25 @@ namespace ResUpdate } downLoadURL = VersionManager.Instance.GetVersionInfo("resUrl") + AppConst.PlatformPath + "/"; + + // 获取config + string conUrl = downLoadURL + AppConst.GameConfigFile; + Debug.Log("Download_Resouces_Url:" + conUrl); + UnityWebRequest request0 = UnityWebRequest.Get(conUrl); + request0.certificateHandler = new AcceptAllCertificatesSignedWithASpecificPublicKey(); + yield return request0.SendWebRequest(); + if (request0.isNetworkError) + { + SetResourcesUpdateState(true, ResourcesUpdateState.GetGameConfigsFailed); + yield break; + } + else + { + Debug.Log("www.text.config:" + request0.downloadHandler.text); + ConfigManager.Instance.SetNetInfo(request0.downloadHandler.text); + } + + // 获取version string resUrl = downLoadURL + AppConst.GameVersionFile; Debug.Log("Download_Resouces_Url:" + resUrl); @@ -327,7 +346,7 @@ namespace ResUpdate } else { - Debug.Log("www.text:" + request.downloadHandler.text); + Debug.Log("www.text.version:" + request.downloadHandler.text); Hashtable table = MiniJSON.jsonDecode(request.downloadHandler.text) as Hashtable; if (table == null)