【配置】异步获取配置文件

dev_chengFeng
gaoxin 2021-04-15 17:29:21 +08:00 committed by JLIOSM1
parent bb79e2839a
commit 5105747314
8 changed files with 102 additions and 94 deletions

View File

@ -87,18 +87,23 @@ namespace GameLogic
/// </summary> /// </summary>
#if UNITY_EDITOR #if UNITY_EDITOR
public static string Platform = "EDITOR"; public static string Platform = "EDITOR";
public static string FilePathEx = "file://";
public static string PersistentDataPath = Application.dataPath + "/../AssetBundles/"; public static string PersistentDataPath = Application.dataPath + "/../AssetBundles/";
#elif UNITY_ANDROID #elif UNITY_ANDROID
public static string Platform = "ANDROID"; public static string Platform = "ANDROID";
public static string FilePathEx = "";
public static string PersistentDataPath = Application.persistentDataPath + "/Android/"; public static string PersistentDataPath = Application.persistentDataPath + "/Android/";
#elif UNITY_IOS #elif UNITY_IOS
public static string Platform = "IOS"; public static string Platform = "IOS";
public static string FilePathEx = "file://";
public static string PersistentDataPath = Application.persistentDataPath + "/IOS/"; public static string PersistentDataPath = Application.persistentDataPath + "/IOS/";
#elif UNITY_STANDALONE_WIN #elif UNITY_STANDALONE_WIN
public static string Platform = "WINDOWS"; public static string Platform = "WINDOWS";
public static string FilePathEx = "file://";
public static string PersistentDataPath = Application.persistentDataPath + "/Windows/"; public static string PersistentDataPath = Application.persistentDataPath + "/Windows/";
#else #else
public static string Platform = "OTHER"; public static string Platform = "OTHER";
public static string FilePathEx = "";
public static string PersistentDataPath = Application.persistentDataPath + "/Other/"; public static string PersistentDataPath = Application.persistentDataPath + "/Other/";
#endif #endif

View File

@ -194,11 +194,11 @@ public class App : UnitySingleton<App>
/// <summary> /// <summary>
/// 初始化 /// 初始化
/// </summary> /// </summary>
public void Initialize() public IEnumerator Initialize()
{ {
ConfigMgr.Init(); yield return ConfigMgr.Init();
yield return VersionMgr.Initialize();
SLanguageMoreLanguageMgr.Instance.InitData(); SLanguageMoreLanguageMgr.Instance.InitData();
VersionMgr.Initialize();
} }
/// <summary> /// <summary>

View File

@ -109,22 +109,42 @@ namespace GameLogic
return AppConst.PersistentDataPath + configFile + ".txt"; return AppConst.PersistentDataPath + configFile + ".txt";
} }
} }
/// <summary>
/// Stream版本文件路径
/// </summary>
string configStreamFilePath
{
get
{
return AppConst.StreamPath + configFile + ".txt";
}
}
MConfig NetInfo; MConfig NetInfo;
// 初始化 获取本地的数据 // 初始化 获取本地的数据
public void Init() public IEnumerator Init()
{ {
try if (File.Exists(configFilePath))
{ {
if (File.Exists(configFilePath)) NetInfo = new MConfig(File.ReadAllText(configFilePath, System.Text.Encoding.UTF8));
}
else
{
string url = AppConst.FilePathEx + configStreamFilePath;
Debug.Log("[ConfigLoader Start ]@" + url);
WWW _www = new WWW(url);
yield return _www;
if (string.IsNullOrEmpty(_www.error))
{ {
NetInfo = new MConfig(File.ReadAllText(configFilePath, System.Text.Encoding.UTF8)); Debug.Log("[ConfigLoader OK ]=" + _www.text);
NetInfo = new MConfig(_www.text);
}
else
{
Debug.LogError("[ConfigLoader ERR ]=" + _www.error);
} }
} }
catch (Exception e) yield return null;
{
Debug.LogError(e);
}
} }
public void SetNetInfo(string info) public void SetNetInfo(string info)

View File

@ -1,7 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 4aa48f27e17d9ff4198e9e0de44d7ea2 guid: 2da61b816f9280346b8ee1f5ab41c5d9
timeCreated: 1557993678
licenseType: Pro
TextScriptImporter: TextScriptImporter:
externalObjects: {} externalObjects: {}
userData: userData:

View File

@ -53,44 +53,60 @@ namespace GameLogic
/// 版本号文件 /// 版本号文件
/// </summary> /// </summary>
const string VersionsFile = "version"; const string VersionsFile = "version";
/// <summary> /// <summary>
/// 外部版本号 /// 版本文件路径
/// </summary> /// </summary>
Version externalVersion; string VersionsFilePath
/// <summary>
/// 流媒体目录中的游戏及其版本号
/// </summary>
Version internalVersion;
public void Initialize()
{ {
InitVersions(); get
{
return AppConst.PersistentDataPath + VersionsFile + ".txt";
}
}
/// <summary>
/// Stream版本文件路径
/// </summary>
string VersionsStreamFilePath
{
get
{
return AppConst.StreamPath + VersionsFile + ".txt";
}
} }
/// <summary> /// <summary>
/// 初始化资源版本号 /// 版本号
/// </summary> /// </summary>
public void InitVersions() Version VersionInfo;
public IEnumerator Initialize()
{ {
try if (File.Exists(VersionsFilePath))
{ {
if (File.Exists(VersionsFilePath)) VersionInfo = new Version(File.ReadAllText(VersionsFilePath, System.Text.Encoding.UTF8));
}
else
{
string url = AppConst.FilePathEx + VersionsStreamFilePath;
Debug.Log("[VersionLoader Start ]@" + url);
WWW _www = new WWW(url);
yield return _www;
if (string.IsNullOrEmpty(_www.error))
{ {
externalVersion = new Version(File.ReadAllText(VersionsFilePath, System.Text.Encoding.UTF8)); Debug.Log("[VersionLoader OK ]=" + _www.text);
VersionInfo = new Version(_www.text);
}
else
{
Debug.LogError("[VersionLoader ERR ]=" + _www.error);
} }
} }
catch (Exception e) { yield return null;
Debug.LogError(e); }
}
try public void InitVersions()
{ {
internalVersion = new Version(Resources.Load<TextAsset>(VersionsFile).text);
}
catch(Exception e)
{
Debug.LogError(e);
}
} }
@ -100,14 +116,9 @@ namespace GameLogic
/// <param name="version"></param> /// <param name="version"></param>
public void SetInfo(string key, string value) public void SetInfo(string key, string value)
{ {
if (externalVersion != null) if (VersionInfo != null)
{ {
externalVersion.SetInfo(key, value); VersionInfo.SetInfo(key, value);
return;
}
if (internalVersion != null)
{
internalVersion.SetInfo(key, value);
return; return;
} }
} }
@ -118,16 +129,10 @@ namespace GameLogic
/// <param name="version"></param> /// <param name="version"></param>
public void SaveVersion(string version) public void SaveVersion(string version)
{ {
if (externalVersion != null) if (VersionInfo != null)
{ {
externalVersion.SetInfo("version", version); VersionInfo.SetInfo("version", version);
SaveToFiles(externalVersion); SaveToFiles(VersionInfo);
return;
}
if (internalVersion != null)
{
internalVersion.SetInfo("version", version);
SaveToFiles(internalVersion);
return; return;
} }
} }
@ -140,14 +145,9 @@ namespace GameLogic
/// <returns></returns> /// <returns></returns>
public string GetLocalVersion() public string GetLocalVersion()
{ {
if (externalVersion != null) if (VersionInfo != null)
{ {
return externalVersion.GetInfo("version"); return VersionInfo.GetInfo("version");
}
if (internalVersion != null)
{
return internalVersion.GetInfo("version");
} }
return null; return null;
} }
@ -194,14 +194,9 @@ namespace GameLogic
/// <returns></returns> /// <returns></returns>
public string GetVersionInfo(string key) public string GetVersionInfo(string key)
{ {
if (externalVersion != null) if (VersionInfo != null)
{ {
return externalVersion.GetInfo(key); return VersionInfo.GetInfo(key);
}
if (internalVersion != null)
{
return internalVersion.GetInfo(key);
} }
return null; return null;
} }
@ -216,16 +211,6 @@ namespace GameLogic
File.WriteAllText(VersionsFilePath, version.ToJson(), System.Text.Encoding.UTF8); File.WriteAllText(VersionsFilePath, version.ToJson(), System.Text.Encoding.UTF8);
} }
/// <summary>
/// 版本文件路径
/// </summary>
string VersionsFilePath
{
get
{
return AppConst.PersistentDataPath + VersionsFile + ".txt";
}
}
/// <summary> /// <summary>
/// 检测包版本,用于比较本地包与线上包的差异,有差异则需要更换新包 /// 检测包版本,用于比较本地包与线上包的差异,有差异则需要更换新包

View File

@ -210,7 +210,7 @@ namespace GameEditor.FrameTool
if (Directory.Exists(streamingPath)) Directory.Delete(streamingPath,true); if (Directory.Exists(streamingPath)) Directory.Delete(streamingPath,true);
Directory.CreateDirectory(streamingPath); Directory.CreateDirectory(streamingPath);
FileUtils.CopyDir(exportPath, streamingPath); FileUtils.CopyDir(exportPath, streamingPath);
CopyResourceFiles(); //CopyResourceFiles();
} }
/// <summary> /// <summary>

View File

@ -25,8 +25,7 @@ public class GameStart : MonoBehaviour
if (Application.isEditor) if (Application.isEditor)
{ {
App.Instance.Initialize(); StartCoroutine(StartGame());
UpdateManager.Instance.StartUp();
} }
else else
{ {
@ -71,7 +70,7 @@ public class GameStart : MonoBehaviour
DestroyImmediate(gameObj2); DestroyImmediate(gameObj2);
if (bundle != null) bundle.Unload(true); if (bundle != null) bundle.Unload(true);
bundle = null; bundle = null;
StartGame(); StartCoroutine(StartGame());
//StartCoroutine(playMovice()); //StartCoroutine(playMovice());
}); });
}); });
@ -80,14 +79,15 @@ public class GameStart : MonoBehaviour
} }
else else
{ {
StartGame(); StartCoroutine(StartGame());
} }
} }
void StartGame() IEnumerator StartGame()
{ {
App.Instance.Initialize(); yield return App.Instance.Initialize();
//App.Instance.Initialize();
UpdateManager.Instance.StartUp(); UpdateManager.Instance.StartUp();
} }
//IEnumerator playMovice() //IEnumerator playMovice()

View File

@ -153,8 +153,8 @@ namespace GameLogic
public void InitLanguageConfig() public void InitLanguageConfig()
{ {
//if (ConfigManager.Instance.GetConfigInfo("Setting.LanguagePackager.isActive") == "1") if (ConfigManager.Instance.GetConfigInfo("Setting.LanguagePackager.isActive") == "1")
//{ {
if (!PlayerPrefs.HasKey("language")) if (!PlayerPrefs.HasKey("language"))
{ {
@ -179,11 +179,11 @@ namespace GameLogic
{ {
PlayerPrefs.SetInt("language_flag", PlayerPrefs.GetInt("language")); PlayerPrefs.SetInt("language_flag", PlayerPrefs.GetInt("language"));
} }
//} }
//else else
//{ {
// PlayerPrefs.SetInt("language", 0); PlayerPrefs.SetInt("language", 0);
//} }
string languageStr = ""; string languageStr = "";
switch (GetLanguageType()) switch (GetLanguageType())