fix:AR相关修改

This commit is contained in:
lishuo committed 2023-06-28 15:59:34 +08:00
1 parent 74ba5790f9
commit c95f6b7c70
12 files changed
+382 -368

No files matched your search

@@ -28,40 +28,7 @@ class GameRoomDownLoad : MonoBehaviour
public string FileName { get; set; }
public string RouteName { get; set; }
private string FileUrl { get; set; }
private float _videoProgress;
public float VideoProgress
{
get => _videoProgress;
set
{
_videoProgress = value;
ComputeProgress();
}
}
private float _dataProgress = 0f;
public float DataProgress
{
get => _dataProgress;
set
{
_dataProgress = value;
ComputeProgress();
}
}
private float _routeProgress = 0f;
public float RouteProgress
{
get => _routeProgress;
set
{
_routeProgress = value;
ComputeProgress();
}
}
private void Start()
{
UIManager.AddEvent(downloadBtn, EventTriggerType.PointerClick, Download_Click);
@@ -124,34 +91,24 @@ class GameRoomDownLoad : MonoBehaviour
{
step2.SetActive(true);
step2.transform.Find("RouteName").GetComponent<Text>().text = RouteName;
downloadSlider.maxValue = _downloader.Total * 100;
if(_downloader.IsVideoDownloaded)
await _downloader.DownLoadVideoAsync(Progress.Create<float>(x => VideoProgress = x));
if(_downloader.IsARRouteDownloaded)
await _downloader.DownLoadARRouteAsync(Progress.Create<float>(x=> RouteProgress = x));
if(_downloader.IsARDataDownloaded)
await _downloader.DownLoadARDataAsync(Progress.Create<float>(x=> DataProgress = x));
await _downloader.DownLoadDefault(ReportProgress);
}
private void ComputeProgress()
private void ReportProgress(float progress)
{
//update progress
var progress = (_videoProgress + _routeProgress + _dataProgress) / _downloader.Total;
downloadSlider.value = progress * 100;
downloadSlider.value = progress;
//update download info
if (!Loom.DownloadStack.ContainsKey(FileName) )
{
Loom.DownloadStack.Add(FileName, new DownloadInfo(FileName, RouteName,progress));
}
Loom.DownloadStack[FileName].Process = progress;
if (progress >= 1)
LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)this.downloadSlider.transform);
if (progress == 1f)
{
Loom.DownloadStack.Remove(FileName);
downloadSlider.value = 100;
step3.SetActive(true);
step3.transform.Find("RouteName").GetComponent<Text>().text = RouteName;
}
@@ -2,11 +2,9 @@
using Assets.Scripts;
using Assets.Scripts.Apis;
using Assets.Scripts.Apis.Models;
using Cysharp.Threading.Tasks;
using DG.Tweening;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Threading;
using Assets.AR;
using Assets.Core;
using UnityEngine;
@@ -43,40 +41,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
private ARDownloader downloader { get; set; }
private float _videoProgress;
public float VideoProgress
{
get => _videoProgress;
set
{
_videoProgress = value;
ComputeProgress();
}
}
private float _dataProgress = 0f;
public float DataProgress
{
get => _dataProgress;
set
{
_dataProgress = value;
ComputeProgress();
}
}
private float _routeProgress = 0f;
public float RouteProgress
{
get => _routeProgress;
set
{
_routeProgress = value;
ComputeProgress();
}
}
private CancellationTokenSource _cancellation;
private void Awake()
{
@@ -87,6 +52,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
private void Start()
{
listController = FindObjectOfType<GameRoomListController>();
ShowDownloadModal();
}
public void Initial(MapRoute myMap, Dictionary<string, Texture> caches, MapRouteAreaItem area = null)
@@ -107,8 +73,6 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
downloadTxt = transform.Find("DownLoadModal/Text").gameObject;
slider = transform.Find("DownLoadModal/Slider").GetComponent<Slider>();
ShowDownloadModal();
UIManager.AddEvent(downloadBtn, EventTriggerType.PointerClick,Download_Click);
transform.Find("Name").GetComponent<Text>().text = myMap.Name;
@@ -148,28 +112,24 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
downloading.SetActive(true);
downloadTxt.SetActive(false);
slider.gameObject.SetActive(true);
slider.maxValue = downloader.Total * 100;
if(downloader.IsVideoDownloaded)
await downloader.DownLoadVideoAsync(Progress.Create<float>(x => VideoProgress = x));
if(downloader.IsARRouteDownloaded)
await downloader.DownLoadARRouteAsync(Progress.Create<float>(x=> RouteProgress = x));
if(downloader.IsARDataDownloaded)
await downloader.DownLoadARDataAsync(Progress.Create<float>(x=> DataProgress = x));
_cancellation = new CancellationTokenSource();
await downloader.DownLoadDefault(ReportProgress,_cancellation);
}
private void ComputeProgress()
private void ReportProgress(float progress)
{
//update progress
var progress = (_videoProgress + _routeProgress + _dataProgress) / downloader.Total;
slider.value = progress * 100;
//update download info
Debug.Log($"{progress},{downloader.IsDone}");
slider.value = progress;
if(!Loom.DownloadStack.ContainsKey(map.FileName))
Loom.DownloadStack.Add(map.FileName, new DownloadInfo(map.FileName,map.Name,0, map.Url));
Loom.DownloadStack[map.FileName].Process = progress;
//refresh slider
LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)this.slider.transform);
transform.Find("DownLoadModal").gameObject.SetActive(progress != 1);
transform.Find("DownLoadModal").gameObject.SetActive(progress < 1f);
if(progress == 1)
_cancellation = null;
}
//显示下载面板
@@ -183,10 +143,9 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
private void Ride()
{
var fileName = map.FileName;
var path = PFConstants.VideoFolder;
var filepath = path + "/" + fileName;
if ((map.EnableAR && File.Exists(filepath) )|| !map.EnableAR)
var canARRide = map.EnableAR && downloader != null && downloader.IsDone;
var canRide = !map.EnableAR;
if (canARRide || canRide)
{
var list = FindObjectsOfType<GameRoomMapItem>();
foreach (var item in list)
@@ -238,6 +197,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
transform.Find("Shadow").GetComponent<Image>().DOFade(0, 0.3f);
#endif
}
public void OnPointerEnter(PointerEventData eventData)
{
if (isModal)
@@ -258,6 +218,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
transform.Find("Shadow").GetComponent<Image>().DOFade(1, 0.3f);
#endif
}
private void SetActive4Button(bool b)
{
transform.Find("MapHBImg").gameObject.SetActive(!b);
@@ -280,6 +241,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
transform.Find("MapHBImg").GetComponent<RawImage>().color = Utils.HexToColorHtml(
PropNames.colorDict[isFav]);
}
private async void Collect()
{
JsonResult<object> r;
@@ -362,4 +324,11 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
{
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
}
private void OnDestroy()
{
// _cancellation?.Cancel();
// Loom.DownloadStack.Remove(map?.FileName);
}
}