From 93aef95cdb63985dbe0430aeaab143c5082ff8ff Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 24 Nov 2018 16:18:38 +0100 Subject: [PATCH] simplified coroutine calls --- .../UI/FullscreenModelViewBehaviour.cs | 2 +- .../Scripts/Updater/UpdaterBehaviour.cs | 29 +++++++------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/Assets/RothenburgAR/Scripts/UI/FullscreenModelViewBehaviour.cs b/Assets/RothenburgAR/Scripts/UI/FullscreenModelViewBehaviour.cs index 676e82f..2480c1f 100644 --- a/Assets/RothenburgAR/Scripts/UI/FullscreenModelViewBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/UI/FullscreenModelViewBehaviour.cs @@ -54,7 +54,7 @@ namespace RothenburgAR.UI if (!data.HasModelDescription) return; this.currentPoiData = data; - StartCoroutine("SetModelCoroutine", data); + StartCoroutine(SetModelCoroutine(data)); } public IEnumerator SetModelCoroutine(PoiData data) diff --git a/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs b/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs index 5bf10a2..efe60a5 100644 --- a/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs @@ -116,6 +116,7 @@ namespace RothenburgAR.Updater }; result = result.Substring(0, result.Length - 1) + "}"; + return "{}"; return result; } @@ -179,12 +180,7 @@ namespace RothenburgAR.Updater private void UpdateMeta(ApiExhibitionVersion exhibition) { - var versionData = new UpdateVersionFileCoroutineData - { - path = PathHelper.CombinePaths(PathHelper.ExhibitionPath, exhibition.Id, "version.txt"), - httpHandlers = new List(), - version = exhibition.Meta.UpdateVersion.ToString() - }; + var currentHandlers = new List(); foreach (var lang in VersionAnswer.Languages) { @@ -192,7 +188,7 @@ namespace RothenburgAR.Updater var url = exhibition.Meta.UpdateUrl.Replace("{lang}", lang); var http = new HttpRequest(url, HttpVerb.GET).Send(); httpHandlers.Add(http); - versionData.httpHandlers.Add(http); + currentHandlers.Add(http); http.Operation.completed += ar => { @@ -217,23 +213,18 @@ namespace RothenburgAR.Updater }; } - StartCoroutine("UpdateVersionFileCoroutine", versionData); + var versionPath = PathHelper.CombinePaths(PathHelper.ExhibitionPath, exhibition.Id, "version.txt"); + var version = exhibition.Meta.UpdateVersion.ToString(); + StartCoroutine(UpdateVersionFileCoroutine(currentHandlers, versionPath, version)); } - private IEnumerator UpdateVersionFileCoroutine(UpdateVersionFileCoroutineData versionData) + private IEnumerator UpdateVersionFileCoroutine(List currentHandlers, string versionPath, string version) { // updates version file only if all sub files were downloaded successfully - yield return new WaitUntil(() => versionData.httpHandlers.All(h => h.IsDone)); - if (versionData.httpHandlers.Any(http => http.Request.isNetworkError || http.Request.isHttpError)) yield break; + yield return new WaitUntil(() => httpHandlers.All(h => h.IsDone)); + if (httpHandlers.Any(http => http.Request.isNetworkError || http.Request.isHttpError)) yield break; - File.WriteAllText(versionData.path, versionData.version); - } - - private class UpdateVersionFileCoroutineData - { - public List httpHandlers; - public string path; - public string version; + File.WriteAllText(versionPath, version); } private void UpdateMedia(ApiExhibit exhibit)