add standalone mode ,bug fix

This commit is contained in:
CroakFang
2023-02-13 10:38:40 +08:00
parent 7ba9b84a11
commit f11edb5924
46 changed files with 3599 additions and 34 deletions
+27
View File
@@ -1,5 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
@@ -26,6 +28,31 @@ public class UmaViewerDownload : MonoBehaviour
}
}
public static IEnumerator DownloadAsset(UmaDatabaseEntry entry,string path, Action<string> callback = null)
{
string baseurl = GetAssetRequestUrl(entry.Url);
if (!string.IsNullOrEmpty(Path.GetExtension(entry.Name)))
{
baseurl = GetGenericRequestUrl(entry.Url);
}
using UnityWebRequest www = UnityWebRequest.Get(baseurl);
callback?.Invoke($"Downloading missing asset : {Path.GetFileName(entry.Name)}\n");
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.LogError(www.error);
callback?.Invoke($"Failed to download resources : {www.error}");
}
else
{
Debug.Log("saving " + entry.Url);
Directory.CreateDirectory(Path.GetDirectoryName(path));
File.WriteAllBytes(path, www.downloadHandler.data);
callback?.Invoke($"Downloading missing asset : {Path.GetFileName(entry.Name)}\ncompleted, please load again");
}
}
public static string GetManifestRequestUrl(string hash)
{
return $"{MANIFEST_ROOT_URL}/{hash.Substring(0, 2)}/{hash}";