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

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>
#if UNITY_EDITOR
public static string Platform = "EDITOR";
public static string FilePathEx = "file://";
public static string PersistentDataPath = Application.dataPath + "/../AssetBundles/";
#elif UNITY_ANDROID
public static string Platform = "ANDROID";
public static string FilePathEx = "";
public static string PersistentDataPath = Application.persistentDataPath + "/Android/";
#elif UNITY_IOS
public static string Platform = "IOS";
public static string FilePathEx = "file://";
public static string PersistentDataPath = Application.persistentDataPath + "/IOS/";
#elif UNITY_STANDALONE_WIN
public static string Platform = "WINDOWS";
public static string FilePathEx = "file://";
public static string PersistentDataPath = Application.persistentDataPath + "/Windows/";
#else
public static string Platform = "OTHER";
public static string FilePathEx = "";
public static string PersistentDataPath = Application.persistentDataPath + "/Other/";
#endif

View File

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

View File

@ -109,22 +109,42 @@ namespace GameLogic
return AppConst.PersistentDataPath + configFile + ".txt";
}
}
/// <summary>
/// Stream版本文件路径
/// </summary>
string configStreamFilePath
{
get
{
return AppConst.StreamPath + configFile + ".txt";
}
}
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)
{
Debug.LogError(e);
}
yield return null;
}
public void SetNetInfo(string info)

View File

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

View File

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

View File

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

View File

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

View File

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