void Awake() { if (instance == null) { instance = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } }
internal void ExportStreamingAssetWhenDownloadApk(Action finished) { ResourceIndexInfo.Instance.Init(Application.get_streamingAssetsPath() + "/ResourceIndexInfo.txt", delegate { LoggerHelper.Debug("资源索引信息:" + ResourceIndexInfo.Instance.GetLeftFilePathes().Length, true, 0); if (ResourceIndexInfo.Instance.GetLeftFilePathes().Length != 0) { StreamingAssetManager manager2 = new StreamingAssetManager { AllFinished = finished }; manager2.UpdateApkExport(); } else { LoggerHelper.Debug("没有streamingAssets,不需要导出", true, 0); finished(); } }, null); }
void Awake() { if (Instance == null) { Instance = this; streamingAssetsPath = Application.streamingAssetsPath; persistentDataPath = Application.persistentDataPath; LoadData(); // LoadSprites( ProjectsPaths.decorImagesPathExt, 8192 ); // LoadSprites( ProjectsPaths.backgroundImagesPathExt, 8192 ); DontDestroyOnLoad(gameObject); } else { if (this != Instance) { Destroy(this); } } }
//使用平台更新下载apk时导出资源,先导出资源再下载apk internal void ExportStreamingAssetWhenDownloadApk(Action finished) { ResourceIndexInfo.Instance.Init(Application.streamingAssetsPath + "/ResourceIndexInfo.txt", () => { LoggerHelper.Debug("资源索引信息:" + ResourceIndexInfo.Instance.GetLeftFilePathes().Length); if (ResourceIndexInfo.Instance.GetLeftFilePathes().Length != 0) { //下载apk时导出资源 var go = new StreamingAssetManager { AllFinished = finished }; go.UpdateApkExport(); } else { LoggerHelper.Debug("没有streamingAssets,不需要导出"); finished(); } }); }
private void AsynDownloadApk(Action <int, int, string> taskProgress, string fileName, string url, Action <int, long, long> progress, Action finished, Action <Exception> error) { var task = new DownloadTask { FileName = fileName, Url = url, Finished = finished, Error = error, TotalProgress = progress, MD5 = ServerVersion.ApkMd5 }; LoggerHelper.Info("down load apk & md5: " + url + " " + ServerVersion.ApkMd5); //LoggerHelper.Debug("APK保存的MD5值: " + ServerVersion.ApkMd5); var tasks = new List <DownloadTask> { task }; DownloadMgr.Instance.tasks = tasks; //添加taskProgress的回调 Action <int, int, string> TaskProgress = (total, current, filename) => { if (taskProgress != null) { taskProgress(total, current, filename); } }; DownloadMgr.Instance.TaskProgress = TaskProgress; StreamingAssetManager go = null; ResourceIndexInfo.Instance.Init(Application.streamingAssetsPath + "/ResourceIndexInfo.txt", () => { LoggerHelper.Info("资源索引信息:" + ResourceIndexInfo.Instance.GetLeftFilePathes().Length); if (ResourceIndexInfo.Instance.GetLeftFilePathes().Length == 0) { go = new StreamingAssetManager(); go.UpdateProgress = false; go.ApkFinished = true; } else { //下载apk时导出资源 go = new StreamingAssetManager { UpdateProgress = false }; go.AllFinished = () => { LoggerHelper.Debug("打开资源导出完成的标识11ApkFinished"); go.ApkFinished = true; }; } }); DownloadMgr.Instance.AllDownloadFinished = () => { LoggerHelper.Info("APK download finish, wait for export finish:" + fileName); if (go != null) { go.UpdateProgress = true; LoggerHelper.Debug("打开导出进度显示:" + go.ApkFinished); //先判断资源导出是否完成,再安装apk,没完成则等待完成 while (!go.ApkFinished) { System.Threading.Thread.Sleep(500); } LoggerHelper.Info("APK and export download finish."); go = null; } DriverLib.Invoke(() => { #if UNITY_IPHONE Action <bool> InstallIpa = (confirm) => { if (confirm) { //IOSUtils.UpdateLoader(fileName); } else { Application.Quit(); } }; ForwardLoadingMsgBoxLib.Instance.ShowMsgBox(DefaultUI.dataMap[11].content, DefaultUI.dataMap[7].content, DefaultUI.dataMap[12].content, InstallIpa); #else InstallApk(fileName); #endif }); if (finished != null) { finished(); } LoggerHelper.Debug("apk安装成功"); }; var stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); while (go == null) { System.Threading.Thread.Sleep(50); if (stopwatch.ElapsedMilliseconds > 3000) { break; } //LoggerHelper.Debug("阻塞直到StreamingAssetManager不为null或超时3秒"); } stopwatch.Stop(); //开始下载apk同时导出资源文件 if (go != null && !go.ApkFinished) { LoggerHelper.Debug("apk下载同时导出资源"); go.UpdateApkExport(); } DownloadMgr.Instance.CheckDownLoadList(); }
void DoInit() { DefaultUI.SetLoadingStatusTip(DefaultUI.dataMap.Get(4).content);//数据读取中… var loadCfgSuccess = SystemConfig.Init(); if (!loadCfgSuccess) { ForwardLoadingMsgBox.Instance.ShowRetryMsgBox(DefaultUI.dataMap[53].content, (isOk) => { if (isOk) DoInit(); else Application.Quit(); }); return; } if (SystemSwitch.ReleaseMode) { //第一次导出资源 ResourceIndexInfo.Instance.Init(Application.streamingAssetsPath + "/ResourceIndexInfo.txt", () => { //如果是完整包(判断ResourceIndexInfo.txt是否存在),再判断apk的资源版本是否比本地资源版本高,如果高删除MogoResource和version.xml if (ResourceIndexInfo.Instance.Exist()) { LoggerHelper.Debug("-------------------------Exist ResourceIndexInfo.txt--------------------------"); var localVer = Utils.LoadFile(SystemConfig.VersionPath); var localVersion = VersionManager.Instance.GetVersionInXML(localVer); var pkgVer = Resources.Load(SystemConfig.VERSION_URL_KEY) as TextAsset; var pkgVersion = VersionManager.Instance.GetVersionInXML(pkgVer.text); if (pkgVersion.ResouceVersionInfo.Compare(localVersion.ResouceVersionInfo) > 0) { //删除version.xml if (File.Exists(SystemConfig.VersionPath)) File.Delete(SystemConfig.VersionPath); //删除MogoResource文件夹 var mogoResroucesPath = SystemConfig.ResourceFolder.Substring(0, SystemConfig.ResourceFolder.Length - 1); if (Directory.Exists(mogoResroucesPath)) Directory.Delete(mogoResroucesPath, true); //删除后再导出version if (!File.Exists(SystemConfig.VersionPath)) { var ver = Resources.Load(SystemConfig.VERSION_URL_KEY) as TextAsset; if (ver != null) XMLParser.SaveText(SystemConfig.VersionPath, ver.text); } } } var go = new StreamingAssetManager(); go.AllFinished = () => { LoggerHelper.Debug("firstExport finish,start checkversion"); if (SystemSwitch.UseFileSystem) { try { MogoFileSystem.Instance.Init(); } catch (Exception ex) { LoggerHelper.Except(ex); } } VersionManager.Instance.Init(); VersionManager.Instance.LoadLocalVersion(); CheckVersion(CheckVersionFinish); }; go.FirstExport(); }); } else { SystemConfig.LoadServerList(); VersionManager.Instance.Init(); VersionManager.Instance.LoadLocalVersion(); gameObject.AddComponent("MogoInitialize"); IsRunOnAndroid = false; gameObject.AddComponent("PlatformSdkManager"); } }
void CheckVersion(Action callback) { #if UNITY_EDITOR ResourceIndexInfo.Instance.Init(Application.streamingAssetsPath + "/ResourceIndexInfo.txt", () => { if (ResourceIndexInfo.Instance.Exist()) { var localVer = Utils.LoadFile(SystemConfig.VersionPath); var localVersion = VersionManager.Instance.GetVersionInXML(localVer); var pkgVer = Resources.Load(SystemConfig.VERSION_URL_KEY) as TextAsset; var pkgVersion = VersionManager.Instance.GetVersionInXML(pkgVer.text); if (pkgVersion.ResouceVersionInfo.Compare(localVersion.ResouceVersionInfo) > 0) { if (File.Exists(SystemConfig.VersionPath)) { File.Delete(SystemConfig.VersionPath); } var mogoResroucesPath = SystemConfig.ResourceFolder.Substring(0, SystemConfig.ResourceFolder.Length - 1); if (Directory.Exists(mogoResroucesPath)) { Directory.Delete(mogoResroucesPath, true); } if (!File.Exists(SystemConfig.VersionPath)) { var ver = Resources.Load(SystemConfig.VERSION_URL_KEY) as TextAsset; if (ver != null) { XMLParser.SaveText(SystemConfig.VersionPath, ver.text); } } } } var go = new StreamingAssetManager(); go.AllFinished = () => { MogoFileSystem.Instance.Init(); Action <bool> fileDecompress = (finish) => { Driver.Invoke(() => { if (finish) { DefaultUI.SetLoadingStatusTip(DefaultUI.dataMap.Get(3).content);//正在更新本地文件 } else { DefaultUI.SetLoadingStatusTip(DefaultUI.dataMap.Get(4).content);//恢复成“数据读取中” } }); }; Action <int, int, string> taskProgress = (total, index, filename) => { Driver.Invoke(() => { DefaultUI.SetLoadingStatusTip(DefaultUI.dataMap.Get(2).content, index + 1, total, filename); }); }; Action <int, long, long> progress = (ProgressPercentage, TotalBytesToReceive, BytesReceived) => { Driver.Invoke(() => { DefaultUI.Loading(ProgressPercentage); }); }; Action <Exception> error = (ex) => { ForwardLoadingMsgBox.Instance.ShowRetryMsgBox(DefaultUI.dataMap[54].content, (isOk) => { if (isOk) { CheckVersion(callback); } else { Application.Quit(); } }); Debug.LogException(ex); }; DefaultUI.SetLoadingStatusTip(DefaultUI.dataMap.Get(1).content); VersionManager.Instance.CheckVersion(fileDecompress, taskProgress, progress, () => { Driver.Invoke(callback); }, error); }; go.FirstExport(); }); #else callback(); #endif }
void DoInit() { DefaultUI.SetLoadingStatusTip(DefaultUI.dataMap.Get(4).content);//数据读取中… var loadCfgSuccess = SystemConfig.Init(); if (!loadCfgSuccess) { ForwardLoadingMsgBox.Instance.ShowRetryMsgBox(DefaultUI.dataMap[53].content, (isOk) => { if (isOk) { DoInit(); } else { Application.Quit(); } }); return; } if (SystemSwitch.ReleaseMode) { //第一次导出资源 ResourceIndexInfo.Instance.Init(Application.streamingAssetsPath + "/ResourceIndexInfo.txt", () => { //如果是完整包(判断ResourceIndexInfo.txt是否存在),再判断apk的资源版本是否比本地资源版本高,如果高删除MogoResource和version.xml if (ResourceIndexInfo.Instance.Exist()) { Debug.Log("-------------------------Exist ResourceIndexInfo.txt--------------------------"); var localVer = Utils.LoadFile(SystemConfig.VersionPath); var localVersion = VersionManager.Instance.GetVersionInXML(localVer); var pkgVer = Resources.Load(SystemConfig.VERSION_URL_KEY) as TextAsset; var pkgVersion = VersionManager.Instance.GetVersionInXML(pkgVer.text); if (pkgVersion.ResouceVersionInfo.Compare(localVersion.ResouceVersionInfo) > 0) { //删除version.xml if (File.Exists(SystemConfig.VersionPath)) { File.Delete(SystemConfig.VersionPath); } //删除MogoResource文件夹 var mogoResroucesPath = SystemConfig.ResourceFolder.Substring(0, SystemConfig.ResourceFolder.Length - 1); if (Directory.Exists(mogoResroucesPath)) { Directory.Delete(mogoResroucesPath, true); } //删除后再导出version if (!File.Exists(SystemConfig.VersionPath)) { var ver = Resources.Load(SystemConfig.VERSION_URL_KEY) as TextAsset; if (ver != null) { XMLParser.SaveText(SystemConfig.VersionPath, ver.text); } } } } var go = new StreamingAssetManager(); go.AllFinished = () => { Debug.Log("firstExport finish,start checkversion"); if (SystemSwitch.UseFileSystem) { try { MogoFileSystem.Instance.Init(); } catch (Exception ex) { Debug.LogException(ex); } } VersionManager.Instance.Init(); VersionManager.Instance.LoadLocalVersion(); CheckVersion(CheckVersionFinish); }; go.FirstExport(); }); } else { SystemConfig.LoadServerList(); VersionManager.Instance.Init(); VersionManager.Instance.LoadLocalVersion(); //UnityEngineInternal.APIUpdaterRuntimeServices.AddComponent(gameObject, "Assets/Plugins/Init/Driver.cs (187,13)", "MogoInitialize"); //if (ass.GetType("MogoInitialize") != null) //gameObject.AddComponent(ass.GetType("MogoInitialize")); var t = System.Type.GetType("MogoInitialize,Assembly-CSharp"); var addedComponent = gameObject.AddComponent(t); IsRunOnAndroid = false; gameObject.AddComponent <PlatformSdkManager>(); } }
void Awake() { instance = this; _DestinationImage = new List <Image>(); _DestinationSprite = new List <SpriteRenderer>(); }
private void AsynDownloadApk(Action <int, int, string> taskProgress, string fileName, string url, Action <int, long, long> progress, Action finished, Action <Exception> error) { DownloadTask task = new DownloadTask { FileName = fileName, Url = url, Finished = finished, Error = error, TotalProgress = progress, MD5 = this.ServerVersion.ApkMd5 }; LoggerHelper.Info("down load apk & md5: " + url + " " + this.ServerVersion.ApkMd5, true); List <DownloadTask> list = new List <DownloadTask> { task }; DownloadMgr.Instance.tasks = list; Action <int, int, string> action = delegate(int total, int current, string filename) { if (taskProgress != null) { taskProgress(total, current, filename); } }; DownloadMgr.Instance.TaskProgress = action; StreamingAssetManager go = null; ResourceIndexInfo.Instance.Init(Application.get_streamingAssetsPath() + "/ResourceIndexInfo.txt", delegate { Action action = null; LoggerHelper.Info("资源索引信息:" + ResourceIndexInfo.Instance.GetLeftFilePathes().Length, true); if (ResourceIndexInfo.Instance.GetLeftFilePathes().Length == 0) { go = new StreamingAssetManager { UpdateProgress = false, ApkFinished = true }; } else { go = new StreamingAssetManager { UpdateProgress = false }; if (action == null) { action = delegate { LoggerHelper.Debug("打开资源导出完成的标识11ApkFinished", true, 0); go.ApkFinished = true; }; } go.AllFinished = action; } }, null); DownloadMgr.Instance.AllDownloadFinished = delegate { LoggerHelper.Info("APK download finish, wait for export finish:" + fileName, true); if (go != null) { go.UpdateProgress = true; LoggerHelper.Debug("打开导出进度显示:" + go.ApkFinished, true, 0); while (!go.ApkFinished) { Thread.Sleep(500); } LoggerHelper.Info("APK and export download finish.", true); go = null; } DriverLib.Invoke(() => this.InstallApk(fileName)); if (finished != null) { finished(); } LoggerHelper.Debug("apk安装成功", true, 0); }; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); while (go == null) { Thread.Sleep(50); if (stopwatch.ElapsedMilliseconds > 0xbb8L) { break; } } stopwatch.Stop(); if (!((go == null) || go.ApkFinished)) { LoggerHelper.Debug("apk下载同时导出资源", true, 0); go.UpdateApkExport(); } DownloadMgr.Instance.CheckDownLoadList(); }
private void AsynDownloadApk(Action<int, int, string> taskProgress, string fileName, string url, Action<int, long, long> progress, Action finished, Action<Exception> error) { var task = new DownloadTask { FileName = fileName, Url = url, Finished = finished, Error = error, TotalProgress = progress, MD5 = ServerVersion.ApkMd5 }; LoggerHelper.Info("down load apk & md5: " + url + " " + ServerVersion.ApkMd5); //LoggerHelper.Debug("APK保存的MD5值: " + ServerVersion.ApkMd5); var tasks = new List<DownloadTask> { task }; DownloadMgr.Instance.tasks = tasks; //添加taskProgress的回调 Action<int, int, string> TaskProgress = (total, current, filename) => { if (taskProgress != null) taskProgress(total, current, filename); }; DownloadMgr.Instance.TaskProgress = TaskProgress; StreamingAssetManager go = null; ResourceIndexInfo.Instance.Init(Application.streamingAssetsPath + "/ResourceIndexInfo.txt", () => { LoggerHelper.Info("资源索引信息:" + ResourceIndexInfo.Instance.GetLeftFilePathes().Length); if (ResourceIndexInfo.Instance.GetLeftFilePathes().Length == 0) { go = new StreamingAssetManager(); go.UpdateProgress = false; go.ApkFinished = true; } else { //下载apk时导出资源 go = new StreamingAssetManager { UpdateProgress = false }; go.AllFinished = () => { LoggerHelper.Debug("打开资源导出完成的标识11ApkFinished"); go.ApkFinished = true; }; } }); DownloadMgr.Instance.AllDownloadFinished = () => { LoggerHelper.Info("APK download finish, wait for export finish:" + fileName); if (go != null) { go.UpdateProgress = true; LoggerHelper.Debug("打开导出进度显示:" + go.ApkFinished); //先判断资源导出是否完成,再安装apk,没完成则等待完成 while (!go.ApkFinished) { System.Threading.Thread.Sleep(500); } LoggerHelper.Info("APK and export download finish."); go = null; } DriverLib.Invoke(() => { #if UNITY_IPHONE Action<bool> InstallIpa = (confirm) => { if (confirm) { //IOSUtils.UpdateLoader(fileName); } else Application.Quit(); }; ForwardLoadingMsgBoxLib.Instance.ShowMsgBox(DefaultUI.dataMap[11].content, DefaultUI.dataMap[7].content, DefaultUI.dataMap[12].content, InstallIpa); #else InstallApk(fileName); #endif }); if (finished != null) finished(); LoggerHelper.Debug("apk安装成功"); }; var stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); while (go == null) { System.Threading.Thread.Sleep(50); if (stopwatch.ElapsedMilliseconds > 3000) break; //LoggerHelper.Debug("阻塞直到StreamingAssetManager不为null或超时3秒"); } stopwatch.Stop(); //开始下载apk同时导出资源文件 if (go != null && !go.ApkFinished) { LoggerHelper.Debug("apk下载同时导出资源"); go.UpdateApkExport(); } DownloadMgr.Instance.CheckDownLoadList(); }
void CheckVersion(Action callback) { #if !UNITY_EDITOR ResourceIndexInfo.Instance.Init(Application.streamingAssetsPath + "/ResourceIndexInfo.txt", () => { if (ResourceIndexInfo.Instance.Exist()) { var localVer = Utils.LoadFile(SystemConfig.VersionPath); var localVersion = VersionManager.Instance.GetVersionInXML(localVer); var pkgVer = Resources.Load(SystemConfig.VERSION_URL_KEY) as TextAsset; var pkgVersion = VersionManager.Instance.GetVersionInXML(pkgVer.text); if (pkgVersion.ResouceVersionInfo.Compare(localVersion.ResouceVersionInfo) > 0) { if (File.Exists(SystemConfig.VersionPath)) File.Delete(SystemConfig.VersionPath); var mogoResroucesPath = SystemConfig.ResourceFolder.Substring(0, SystemConfig.ResourceFolder.Length - 1); if (Directory.Exists(mogoResroucesPath)) Directory.Delete(mogoResroucesPath, true); if (!File.Exists(SystemConfig.VersionPath)) { var ver = Resources.Load(SystemConfig.VERSION_URL_KEY) as TextAsset; if (ver != null) XMLParser.SaveText(SystemConfig.VersionPath, ver.text); } } } var go = new StreamingAssetManager(); go.AllFinished = () => { MogoFileSystem.Instance.Init(); Action<bool> fileDecompress = (finish) => { Driver.Invoke(() => { if (finish) DefaultUI.SetLoadingStatusTip(DefaultUI.dataMap.Get(3).content);//正在更新本地文件 else DefaultUI.SetLoadingStatusTip(DefaultUI.dataMap.Get(4).content);//恢复成“数据读取中” }); }; Action<int, int, string> taskProgress = (total, index, filename) => { Driver.Invoke(() => { DefaultUI.SetLoadingStatusTip(DefaultUI.dataMap.Get(2).content, index + 1, total, filename); }); }; Action<int, long, long> progress = (ProgressPercentage, TotalBytesToReceive, BytesReceived) => { Driver.Invoke(() => { DefaultUI.Loading(ProgressPercentage); }); }; Action<Exception> error = (ex) => { ForwardLoadingMsgBox.Instance.ShowRetryMsgBox(DefaultUI.dataMap[54].content, (isOk) => { if (isOk) CheckVersion(callback); else Application.Quit(); }); LoggerHelper.Except(ex); }; DefaultUI.SetLoadingStatusTip(DefaultUI.dataMap.Get(1).content); VersionManager.Instance.CheckVersion(fileDecompress, taskProgress, progress, () => { Driver.Invoke(callback); }, error); }; go.FirstExport(); }); #else callback(); #endif }