【热更配置】结构搭建

dev_chengFeng
gaoxin 2021-01-22 14:17:08 +08:00
parent 09fcfff167
commit 1dafda4b44
9 changed files with 214 additions and 4 deletions

View File

@ -0,0 +1,4 @@
{"subChannel":"1",
"buglyId":"261348dcd3",
"channel":"pc",
"serverUrl":"http://60.1.1.23:8080/"}

View File

@ -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/"}
{"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/"}

View File

@ -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

View File

@ -180,12 +180,23 @@ public class App : UnitySingleton<App>
return VersionManager.Instance;
}
}
/// <summary>
/// 配置数据管理器管理器
/// </summary>
public static ConfigManager ConfigMgr
{
get
{
return ConfigManager.Instance;
}
}
/// <summary>
/// 初始化
/// </summary>
public void Initialize()
{
ConfigMgr.Init();
VersionMgr.Initialize();
}

View File

@ -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<ConfigManager>
{
/// <summary>
/// 版本号文件
/// </summary>
const string configFile = "config";
/// <summary>
/// 版本文件路径
/// </summary>
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<TextAsset>(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);
}
}
/// <summary>
/// 保存到文件
/// </summary>
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);
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
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;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 252b072fc95a44740976d9126b5b4626
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,4 @@
{"subChannel":"1",
"buglyId":"261348dcd3",
"channel":"pc",
"serverUrl":"http://60.1.1.23:8080/"}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 343cc3bd6dddfa64381bbe4c53e06a87
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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)