ar骑行bug fix

This commit is contained in:
lishuo committed 2023-02-07 18:35:16 +08:00
1 parent 2c9440f656
commit 08b92e7e9b
37 files changed
+3233 -3358

No files matched your search

+33 -20
View File
@@ -1,4 +1,5 @@
using Assets.Scenes.Ride.Scripts;
using Assets.Core;
using Assets.Scenes.Ride.Scripts;
using Assets.Scripts.Apis.Models;
using Cysharp.Threading.Tasks;
using System;
@@ -7,6 +8,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
@@ -18,8 +20,6 @@ public class Loom : MonoBehaviour
public static int maxThreads = 8;
static int numThreads;
public static Dictionary<string, float> DownLoadTaskList = new Dictionary<string, float>();
private static Loom _current;
public static Loom Current
{
@@ -132,14 +132,6 @@ public class Loom : MonoBehaviour
}
}
// Use this for initialization
void Start()
{
}
List<Action> _currentActions = new List<Action>();
// Update is called once per frame
@@ -179,23 +171,44 @@ public class Loom : MonoBehaviour
}
}
public static async void Download(MapRoute route,IProgress<float> progress)
public static Dictionary<string, DownloadInfo> DownloadStack = new Dictionary<string, DownloadInfo>();
public static async Task DownloadLoadARDataAndVideo(MapRoute route,IProgress<float> progress)
{
DownLoadTaskList.Add(route.FileName, 0);
DownloadStack.Add(route.FileName, new DownloadInfo(route.FileName,route.Name,0, route.Url));
var path = PFConstants.VideoFolder;
var localPath = PFConstants.ARFolder;
var arDataPath = route.ARConfig;
var videoRoute = route.VideoRoute;
var cancelToken = new CancellationTokenSource();
var res1 = await UnityWebRequest.Get(arDataPath).SendWebRequest().WithCancellation(cancelToken.Token);//下载AR数据
var res2 = await UnityWebRequest.Get(videoRoute).SendWebRequest().WithCancellation(cancelToken.Token);//下载video视频数据
var res3 = await UnityWebRequest.Get(route.Url).SendWebRequest().ToUniTask(progress);//下载视频
var dataPath = $"{localPath}/{route.Id}";
Helper.CreateDirectoryIfNotExsit(dataPath);
Helper.CreateDirectoryIfNotExsit(dataPath);
File.WriteAllBytes($"{dataPath}/{route.Id}.json", res1.downloadHandler.data);
File.WriteAllBytes($"{dataPath}/route-{route.Id}.json", res2.downloadHandler.data);
File.WriteAllBytes($"{path}/{route.FileName}", res3.downloadHandler.data);
await Loom.DownloadToFileAsync(arDataPath, $"{dataPath}/{route.Id}.json");
await Loom.DownloadToFileAsync(videoRoute, $"{dataPath}/route-{route.Id}.json");
await Loom.DownloadToFileAsync(route.Url, $"{path}/{route.FileName}", progress, cancelToken);
}
/// <summary>
/// 下载文件到本地(持续存入磁盘减少内存占用)
/// </summary>
/// <param name="downloadUrl">文件连接</param>
/// <param name="fullPath">本地文件全路径</param>
/// <param name="progress">下载进度</param>
public static async UniTask<UnityWebRequest> DownloadToFileAsync(string downloadUrl, string fullPath, IProgress<float> progress = null, CancellationTokenSource cancellation = default(CancellationTokenSource))
{
var dh = new DownloadHandlerFile(fullPath)
{
removeFileOnAbort = true
};
var request = UnityWebRequest.Get(downloadUrl);
request.method = UnityWebRequest.kHttpVerbGET;
request.downloadHandler = dh;
return await request.SendWebRequest().ToUniTask(progress, PlayerLoopTiming.Update, (cancellation?.Token ?? default(CancellationToken)));
}
}