AR文件更新流程&AR网络延时问题
This commit is contained in:
1 parent
16cd2fd26b
commit
74ba5790f9
18 files changed
+867
-508
No files matched your search
@@ -7,6 +7,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
@@ -171,7 +172,7 @@ public class Loom : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, DownloadInfo> DownloadStack = new Dictionary<string, DownloadInfo>();
|
||||
public static Dictionary<string, DownloadInfo> DownloadStack { get; set; } = new Dictionary<string, DownloadInfo>();
|
||||
|
||||
public static async Task DownloadLoadARDataAndVideo(MapRoute route,IProgress<float> progress)
|
||||
{
|
||||
@@ -184,7 +185,6 @@ public class Loom : MonoBehaviour
|
||||
var cancelToken = new CancellationTokenSource();
|
||||
var dataPath = $"{localPath}/{route.Id}";
|
||||
|
||||
Helper.CreateDirectoryIfNotExsit(dataPath);
|
||||
Helper.CreateDirectoryIfNotExsit(dataPath);
|
||||
|
||||
await Loom.DownloadToFileAsync(arDataPath, $"{dataPath}/{route.Id}.json");
|
||||
@@ -206,9 +206,45 @@ public class Loom : MonoBehaviour
|
||||
};
|
||||
|
||||
var request = UnityWebRequest.Get(downloadUrl);
|
||||
request.method = UnityWebRequest.kHttpVerbGET;
|
||||
request.downloadHandler = dh;
|
||||
|
||||
request.method = UnityWebRequest.kHttpVerbGET;
|
||||
|
||||
return await request.SendWebRequest().ToUniTask(progress, PlayerLoopTiming.Update, (cancellation?.Token ?? default(CancellationToken)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// head request for file meta info such as etag.
|
||||
/// </summary>
|
||||
/// <param name="downloadUrl">download url</param>
|
||||
/// <param name="fullPath">local path for storage</param>
|
||||
/// <returns></returns>
|
||||
public static async UniTask<UnityWebRequest> HeadFileAsync(string downloadUrl, string fullPath, IProgress<float> progress = null,CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||
{
|
||||
try
|
||||
{ var etagFile = fullPath + ".etag";
|
||||
var etag = string.Empty;
|
||||
if (File.Exists(etagFile))
|
||||
{
|
||||
etag = File.ReadAllText(etagFile);
|
||||
}
|
||||
|
||||
var request = UnityWebRequest.Head(downloadUrl);
|
||||
if(!string.IsNullOrEmpty(etag))
|
||||
request.SetRequestHeader("If-None-Match", etag);
|
||||
|
||||
var result = await request.SendWebRequest();//.ToUniTask(progress, PlayerLoopTiming.Update, (cancellation?.Token ?? default(CancellationToken)));
|
||||
|
||||
if (result.responseCode != (long)HttpStatusCode.NotModified)
|
||||
{
|
||||
etag = result.GetResponseHeader("ETag");
|
||||
File.WriteAllText(fullPath+".etag",etag);
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user