AR文件更新流程&AR网络延时问题
This commit is contained in:
1 parent
16cd2fd26b
commit
74ba5790f9
18 files changed
+867
-508
No files matched your search
@@ -1,14 +1,6 @@
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using PolyAndCode.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Assets.AR;
|
||||
using Assets.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
@@ -36,24 +28,49 @@ 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, DownloadClick);
|
||||
UIManager.AddEvent(downloadBtn, EventTriggerType.PointerClick, Download_Click);
|
||||
UIManager.AddEvent(backBtn, EventTriggerType.PointerClick, CancelClick);
|
||||
|
||||
UIManager.AddEvent(runInbackBtn, EventTriggerType.PointerClick, (d) =>
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
downLoadList.SetActive(true);
|
||||
//var content = downLoadList.transform.Find("Viewport/Content");
|
||||
//var list = FindObjectsOfType<GameRoomDownloadTask>();
|
||||
////新增
|
||||
//var obj = list.Where(c => c.RoomId == RoomId).FirstOrDefault();
|
||||
//if (obj == null)
|
||||
//{
|
||||
// var newtask = Instantiate(downLoadTask, content);
|
||||
// newtask.GetComponent<GameRoomDownloadTask>().Init(RoomId, FileName,gameObject);
|
||||
//}
|
||||
});
|
||||
|
||||
UIManager.AddEvent(enterBtn, EventTriggerType.PointerClick, (ee) =>
|
||||
@@ -69,22 +86,17 @@ class GameRoomDownLoad : MonoBehaviour
|
||||
});
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
//if (!string.IsNullOrEmpty(FileName) && Loom.DownloadStack.ContainsKey(FileName))
|
||||
//{
|
||||
// processing(Loom.DownloadStack[FileName]);
|
||||
//}
|
||||
}
|
||||
|
||||
public void Init(int Id, string fileName, string url, GameRoomListController gameRoomListController, string routeName)
|
||||
private ARDownloader _downloader;
|
||||
public void Init(int Id, string fileName, string url, GameRoomListController gameRoomListController, string routeName,ARDownloader downloader)
|
||||
{
|
||||
RoomId = Id;
|
||||
FileName = fileName;
|
||||
RouteName = routeName;
|
||||
FileUrl = url;
|
||||
manager = gameRoomListController;
|
||||
_downloader = downloader;
|
||||
}
|
||||
|
||||
public void ComeIntoStep2(string fileName, string routeName)
|
||||
{
|
||||
FileName = fileName;
|
||||
@@ -101,42 +113,47 @@ class GameRoomDownLoad : MonoBehaviour
|
||||
step3.SetActive(false);
|
||||
downloadSlider.value = 0f;
|
||||
}
|
||||
|
||||
private void CancelClick(BaseEventData data)
|
||||
{
|
||||
Reset();
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
private void processing(float p)
|
||||
{
|
||||
downloadSlider.value = p;
|
||||
|
||||
if (!Loom.DownloadStack.ContainsKey(FileName) )
|
||||
{
|
||||
Loom.DownloadStack.Add(FileName, new Assets.Core.DownloadInfo(FileName, RouteName, p));
|
||||
}
|
||||
|
||||
Loom.DownloadStack[FileName].Process = p;
|
||||
|
||||
if (p >= 1)
|
||||
{
|
||||
Loom.DownloadStack.Remove(FileName);
|
||||
}
|
||||
}
|
||||
|
||||
private async void DownloadClick(BaseEventData baseEventData)
|
||||
|
||||
private async void Download_Click(BaseEventData baseEventData)
|
||||
{
|
||||
step2.SetActive(true);
|
||||
step2.transform.Find("RouteName").GetComponent<Text>().text = RouteName;
|
||||
|
||||
var filepath = PFConstants.VideoFolder + "/" + FileName;
|
||||
await Loom.DownloadToFileAsync(FileUrl, filepath, Progress.Create<float>(x => {
|
||||
processing(x);
|
||||
if (x >= 1)
|
||||
{
|
||||
downloadSlider.value = 100;
|
||||
step3.SetActive(true);
|
||||
step3.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));
|
||||
}
|
||||
|
||||
private void ComputeProgress()
|
||||
{
|
||||
//update progress
|
||||
var progress = (_videoProgress + _routeProgress + _dataProgress) / _downloader.Total;
|
||||
downloadSlider.value = progress * 100;
|
||||
|
||||
//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)
|
||||
{
|
||||
Loom.DownloadStack.Remove(FileName);
|
||||
downloadSlider.value = 100;
|
||||
step3.SetActive(true);
|
||||
step3.transform.Find("RouteName").GetComponent<Text>().text = RouteName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,25 @@
|
||||
using Assets.AR;
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using System;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Assets.AR;
|
||||
using Assets.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler, IPointerUpHandler
|
||||
{
|
||||
private GameObject downloadBtn;
|
||||
private GameObject downloading;
|
||||
private GameObject downloadTxt;
|
||||
|
||||
public class PropNames
|
||||
{
|
||||
public static List<string> icons = new List<string> { "icon1", "icon2", "icon3" };
|
||||
@@ -29,27 +29,66 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
{ true,"#ffffff"},{false,"#5c5c6e" }
|
||||
};
|
||||
}
|
||||
|
||||
public bool isModal = false;
|
||||
float width;
|
||||
float height;
|
||||
GameRoomListController listController;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
width = this.GetComponent<RectTransform>().rect.width;
|
||||
height = this.GetComponent<RectTransform>().rect.height;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
listController = FindObjectOfType<GameRoomListController>();
|
||||
}
|
||||
|
||||
float? localY = null;
|
||||
MapRoute map;
|
||||
Dictionary<string, Texture> caches;
|
||||
private MapRouteAreaItem area = null;
|
||||
Slider slider;
|
||||
GameRoomListController listController;
|
||||
NearRouteModel model { get; set; }
|
||||
|
||||
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 void Awake()
|
||||
{
|
||||
width = this.GetComponent<RectTransform>().rect.width;
|
||||
height = this.GetComponent<RectTransform>().rect.height;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
listController = FindObjectOfType<GameRoomListController>();
|
||||
}
|
||||
|
||||
public void Initial(MapRoute myMap, Dictionary<string, Texture> caches, MapRouteAreaItem area = null)
|
||||
{
|
||||
if (caches != null)
|
||||
@@ -63,30 +102,14 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
transform.GetComponent<Button>().onClick.RemoveAllListeners();
|
||||
transform.GetComponent<Button>().onClick.AddListener(Ride);
|
||||
}
|
||||
var downloadBtn = transform.Find("DownLoadModal/DownLoad").gameObject;
|
||||
var downloading = transform.Find("DownLoadModal/Downloading").gameObject;
|
||||
var downloadTxt = transform.Find("DownLoadModal/Text").gameObject;
|
||||
downloadBtn = transform.Find("DownLoadModal/DownLoad").gameObject;
|
||||
downloading = transform.Find("DownLoadModal/Downloading").gameObject;
|
||||
downloadTxt = transform.Find("DownLoadModal/Text").gameObject;
|
||||
slider = transform.Find("DownLoadModal/Slider").GetComponent<Slider>();
|
||||
|
||||
var fileName = map.FileName;
|
||||
var path = PFConstants.VideoFolder;
|
||||
var filepath = path + "/" + fileName;
|
||||
transform.Find("DownLoadModal").gameObject.SetActive(map.EnableAR && !File.Exists(filepath));
|
||||
UIManager.AddEvent(downloadBtn, EventTriggerType.PointerClick, async (e) =>
|
||||
{
|
||||
downloadBtn.SetActive(false);
|
||||
downloading.SetActive(true);
|
||||
downloadTxt.SetActive(false);
|
||||
slider.gameObject.SetActive(true);
|
||||
var progress = Progress.Create<float>(x =>
|
||||
{
|
||||
Loom.DownloadStack[map.FileName].Process = x;
|
||||
slider.value = x;
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)this.slider.transform);
|
||||
transform.Find("DownLoadModal").gameObject.SetActive(x!=1);
|
||||
});
|
||||
await Loom.DownloadLoadARDataAndVideo(map, progress);
|
||||
});
|
||||
ShowDownloadModal();
|
||||
|
||||
UIManager.AddEvent(downloadBtn, EventTriggerType.PointerClick,Download_Click);
|
||||
|
||||
transform.Find("Name").GetComponent<Text>().text = myMap.Name;
|
||||
transform.Find("IdContainer/Text").GetComponent<Text>().text = $"#{myMap.Id}";
|
||||
@@ -104,16 +127,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
tabContainer.Find("3d").gameObject.SetActive(myMap.Enable3D && !myMap.EnableAR);
|
||||
tabContainer.Find("AR").gameObject?.SetActive(myMap.EnableAR);
|
||||
tabContainer.Find("Country").GetComponent<RawImage>().texture = UIManager.Instance.loginRegOptions.GetCountryImage(myMap.CountryCode);
|
||||
//if (!isModal)
|
||||
//{
|
||||
// transform.Find("CollectImg").GetComponent<Button>().onClick.RemoveAllListeners();
|
||||
// transform.Find("CollectImg").GetComponent<Button>().onClick.AddListener(Collect);
|
||||
//}
|
||||
//transform.Find("CollectImg").Find("Image").GetComponent<Image>().sprite =
|
||||
// UIManager.Instance.collectDict[myMap.IsFavorite];
|
||||
#if !(UNITY_ANDROID || UNITY_IOS)
|
||||
//transform.Find("CollectImg").gameObject.SetActive(false);
|
||||
#endif
|
||||
|
||||
transform.Find("BtnInfo").GetComponent<Button>().onClick.AddListener(Info);
|
||||
transform.Find("BtnRide").GetComponent<Button>().onClick.AddListener(Ride);
|
||||
|
||||
@@ -126,7 +140,45 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
transform.Find("BtnContinue").gameObject.SetActive(isRecent);
|
||||
transform.Find("BtnReride").gameObject.SetActive(isRecent);
|
||||
transform.Find("MapHBImg").gameObject.SetActive(!isRecent);
|
||||
}
|
||||
|
||||
private async void Download_Click(BaseEventData data)
|
||||
{
|
||||
downloadBtn.SetActive(false);
|
||||
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));
|
||||
}
|
||||
|
||||
private void ComputeProgress()
|
||||
{
|
||||
//update progress
|
||||
var progress = (_videoProgress + _routeProgress + _dataProgress) / downloader.Total;
|
||||
slider.value = progress * 100;
|
||||
//update download info
|
||||
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);
|
||||
}
|
||||
|
||||
//显示下载面板
|
||||
private async void ShowDownloadModal()
|
||||
{
|
||||
if(!map.EnableAR) return;
|
||||
downloader = new ARDownloader(map);
|
||||
var showDownload = await downloader.CheckAllAsync();
|
||||
transform.Find("DownLoadModal").gameObject.SetActive(showDownload);
|
||||
}
|
||||
|
||||
private void Ride()
|
||||
@@ -206,7 +258,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
transform.Find("Shadow").GetComponent<Image>().DOFade(1, 0.3f);
|
||||
#endif
|
||||
}
|
||||
void SetActive4Button(bool b)
|
||||
private void SetActive4Button(bool b)
|
||||
{
|
||||
transform.Find("MapHBImg").gameObject.SetActive(!b);
|
||||
transform.Find("BtnInfo").gameObject.SetActive(b);
|
||||
@@ -228,7 +280,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
transform.Find("MapHBImg").GetComponent<RawImage>().color = Utils.HexToColorHtml(
|
||||
PropNames.colorDict[isFav]);
|
||||
}
|
||||
async void Collect()
|
||||
private async void Collect()
|
||||
{
|
||||
JsonResult<object> r;
|
||||
//transform.Find("CollectImg").GetComponent<Button>().enabled = false;
|
||||
@@ -256,7 +308,6 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
UIManager.ShowAlert("WARNING", r.errMsg);
|
||||
}
|
||||
}
|
||||
NearRouteModel model { get; set; }
|
||||
|
||||
public void Show(Vector3 position, NearRouteModel model)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user