change download method

This commit is contained in:
CroakFang
2023-02-14 04:11:31 +08:00
parent a306035dce
commit 92038d87ec
2 changed files with 7 additions and 8 deletions
+4 -4
View File
@@ -18,17 +18,17 @@ public class UmaDatabaseEntry
var path = $"{Config.Instance.MainPath}\\dat\\{Url.Substring(0, 2)}\\{Url}"; var path = $"{Config.Instance.MainPath}\\dat\\{Url.Substring(0, 2)}\\{Url}";
if (!File.Exists(path) && Config.Instance.WorkMode == WorkMode.Standalone) if (!File.Exists(path) && Config.Instance.WorkMode == WorkMode.Standalone)
{ {
UmaViewerMain.Instance.StartCoroutine(DownloadAsset(this)); DownloadAsset(this);
} }
return path; return path;
} }
} }
//TODO Make it async
public static IEnumerator DownloadAsset(UmaDatabaseEntry entry) public static void DownloadAsset(UmaDatabaseEntry entry)
{ {
var path = $"{Config.Instance.MainPath}\\dat\\{entry.Url.Substring(0, 2)}\\{entry.Url}"; var path = $"{Config.Instance.MainPath}\\dat\\{entry.Url.Substring(0, 2)}\\{entry.Url}";
yield return UmaViewerDownload.DownloadAsset(entry, path , delegate(string msg) UmaViewerDownload.DownloadAssetSync(entry, path , delegate(string msg)
{ {
UmaViewerUI.Instance.MessagePannel.SetActive(true); UmaViewerUI.Instance.MessagePannel.SetActive(true);
UmaViewerUI.Instance.MessageText.text = msg; UmaViewerUI.Instance.MessageText.text = msg;
+3 -4
View File
@@ -28,7 +28,7 @@ public class UmaViewerDownload : MonoBehaviour
} }
} }
public static IEnumerator DownloadAsset(UmaDatabaseEntry entry,string path, Action<string> callback = null) public static void DownloadAssetSync(UmaDatabaseEntry entry,string path, Action<string> callback = null)
{ {
string baseurl = GetAssetRequestUrl(entry.Url); string baseurl = GetAssetRequestUrl(entry.Url);
if (!string.IsNullOrEmpty(Path.GetExtension(entry.Name))) if (!string.IsNullOrEmpty(Path.GetExtension(entry.Name)))
@@ -37,8 +37,8 @@ public class UmaViewerDownload : MonoBehaviour
} }
using UnityWebRequest www = UnityWebRequest.Get(baseurl); using UnityWebRequest www = UnityWebRequest.Get(baseurl);
callback?.Invoke($"Downloading missing asset : {Path.GetFileName(entry.Name)}\n"); www.SendWebRequest();
yield return www.SendWebRequest(); while (!www.isDone) { }
if (www.result != UnityWebRequest.Result.Success) if (www.result != UnityWebRequest.Result.Success)
{ {
Debug.LogError(www.error); Debug.LogError(www.error);
@@ -49,7 +49,6 @@ public class UmaViewerDownload : MonoBehaviour
Debug.Log("saving " + entry.Url); Debug.Log("saving " + entry.Url);
Directory.CreateDirectory(Path.GetDirectoryName(path)); Directory.CreateDirectory(Path.GetDirectoryName(path));
File.WriteAllBytes(path, www.downloadHandler.data); File.WriteAllBytes(path, www.downloadHandler.data);
callback?.Invoke($"Downloading missing asset : {Path.GetFileName(entry.Name)}\ncompleted, please load again");
} }
} }