fix:AR相关修改
This commit is contained in:
parent
74ba5790f9
commit
c95f6b7c70
@ -5,6 +5,7 @@ using System.Threading.Tasks;
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace Assets.AR
|
||||
@ -20,10 +21,46 @@ namespace Assets.AR
|
||||
private readonly string _serverARRoutePath;
|
||||
private readonly string _serverVideoPath;
|
||||
|
||||
public bool IsVideoDownloaded { get; private set; }
|
||||
public bool IsARDataDownloaded { get; private set; }
|
||||
public bool IsARRouteDownloaded { get; private set; }
|
||||
public float Total { get; private set; } = 0;
|
||||
private bool IsVideoNeedDownload { get; set; }
|
||||
private bool IsARDataNeedDownload { get; set; }
|
||||
private bool IsARRouteNeedDownload { get; set; }
|
||||
public bool IsDone => !IsVideoNeedDownload && !IsARDataNeedDownload && !IsARRouteNeedDownload;
|
||||
|
||||
private float _total { get; set; }
|
||||
private float _videoProgress;
|
||||
public float VideoProgress
|
||||
{
|
||||
get => _videoProgress;
|
||||
set
|
||||
{
|
||||
_videoProgress = value;
|
||||
ComputeProgress();
|
||||
}
|
||||
}
|
||||
|
||||
private float _dataProgress;
|
||||
public float DataProgress
|
||||
{
|
||||
get => _dataProgress;
|
||||
set
|
||||
{
|
||||
_dataProgress = value;
|
||||
ComputeProgress();
|
||||
}
|
||||
}
|
||||
|
||||
private float _routeProgress;
|
||||
public float RouteProgress
|
||||
{
|
||||
get => _routeProgress;
|
||||
set
|
||||
{
|
||||
_routeProgress = value;
|
||||
ComputeProgress();
|
||||
}
|
||||
}
|
||||
|
||||
private Action<float> ReportProgress { get; set; }
|
||||
|
||||
public ARDownloader(MapRoute route)
|
||||
{
|
||||
@ -41,52 +78,73 @@ namespace Assets.AR
|
||||
_serverARRoutePath = _route.VideoRoute;
|
||||
_serverVideoPath = _route.Url;
|
||||
}
|
||||
|
||||
public async UniTask<UnityWebRequest> DownLoadVideoAsync(IProgress<float> progress = null,
|
||||
CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||
|
||||
private void ComputeProgress()
|
||||
{
|
||||
return await DownloadToFileAsync(_serverVideoPath, _localVideoPath, progress, cancellation);
|
||||
var progress = (_videoProgress + _routeProgress + _dataProgress) / _total;
|
||||
ReportProgress?.Invoke(progress);
|
||||
}
|
||||
|
||||
public async Task DownLoadDefault(Action<float> progress = null,CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||
{
|
||||
ReportProgress = progress;
|
||||
|
||||
if(IsVideoNeedDownload)
|
||||
await DownLoadVideoAsync(Progress.Create<float>(x => VideoProgress = x),cancellation);
|
||||
if(IsARRouteNeedDownload)
|
||||
await DownLoadARRouteAsync(Progress.Create<float>(x=> RouteProgress = x),cancellation);
|
||||
if(IsARDataNeedDownload)
|
||||
await DownLoadARDataAsync(Progress.Create<float>(x=> DataProgress = x),cancellation);
|
||||
}
|
||||
|
||||
public async UniTask<UnityWebRequest> DownLoadARRouteAsync(IProgress<float> progress = null,
|
||||
CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||
private async UniTask<UnityWebRequest> DownLoadVideoAsync(IProgress<float> progress = null,CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||
{
|
||||
return await DownloadToFileAsync(_serverARRoutePath, _localARRoutePath, progress, cancellation);
|
||||
var result = await DownloadToFileAsync(_serverVideoPath, _localVideoPath, progress, cancellation);
|
||||
IsVideoNeedDownload = !result.isDone;
|
||||
return result;
|
||||
}
|
||||
|
||||
public async UniTask<UnityWebRequest> DownLoadARDataAsync(IProgress<float> progress = null,
|
||||
private async UniTask<UnityWebRequest> DownLoadARRouteAsync(IProgress<float> progress = null,CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||
{
|
||||
var result = await DownloadToFileAsync(_serverARRoutePath, _localARRoutePath, progress, cancellation);
|
||||
IsARRouteNeedDownload = !result.isDone;
|
||||
return result;
|
||||
}
|
||||
|
||||
private async UniTask<UnityWebRequest> DownLoadARDataAsync(IProgress<float> progress = null,
|
||||
CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||
{
|
||||
return await DownloadToFileAsync(_serverARDataPath, _localARDataPath, progress, cancellation);
|
||||
var result = await DownloadToFileAsync(_serverARDataPath, _localARDataPath, progress, cancellation);
|
||||
IsARDataNeedDownload = !result.isDone;
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> CheckAllAsync()
|
||||
{
|
||||
IsARRouteDownloaded = await CheckARRouteAsync();
|
||||
IsARDataDownloaded = await CheckARDataAsync();
|
||||
IsVideoDownloaded = await CheckVideoAsync();
|
||||
IsARRouteNeedDownload = await CheckARRouteAsync();
|
||||
IsARDataNeedDownload = await CheckARDataAsync();
|
||||
IsVideoNeedDownload = await CheckVideoAsync();
|
||||
|
||||
if (IsVideoDownloaded)
|
||||
Total += 1f;
|
||||
if (IsARRouteDownloaded)
|
||||
Total += 1f;
|
||||
if (IsARDataDownloaded)
|
||||
Total += 1f;
|
||||
if (IsVideoNeedDownload)
|
||||
_total += 1f;
|
||||
if (IsARRouteNeedDownload)
|
||||
_total += 1f;
|
||||
if (IsARDataNeedDownload)
|
||||
_total += 1f;
|
||||
|
||||
return IsVideoDownloaded || IsARRouteDownloaded || IsARDataDownloaded;
|
||||
return IsVideoNeedDownload || IsARRouteNeedDownload || IsARDataNeedDownload;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// return true if the video is needed to download
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> CheckVideoAsync()
|
||||
private async Task<bool> CheckVideoAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(_localVideoPath)) return true;
|
||||
var result = await HeadFileAsync(_serverVideoPath, _localVideoPath);
|
||||
return result.responseCode != 304;
|
||||
return await HeadFileAsync(_serverVideoPath, _localVideoPath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -95,35 +153,33 @@ namespace Assets.AR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// return true if the video is needed to download
|
||||
/// return true if the video need to update or download
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> CheckARRouteAsync()
|
||||
private async Task<bool> CheckARRouteAsync()
|
||||
{
|
||||
if (!File.Exists(_localARRoutePath)) return true;
|
||||
var result = await HeadFileAsync(_serverARRoutePath, _localARRoutePath);
|
||||
return result.responseCode != 304;
|
||||
return await HeadFileAsync(_serverARRoutePath, _localARRoutePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// return true if the video is needed to download
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> CheckARDataAsync()
|
||||
private async Task<bool> CheckARDataAsync()
|
||||
{
|
||||
if (!File.Exists(_localARDataPath)) return true;
|
||||
var result = await HeadFileAsync(_serverARDataPath, _localARDataPath);
|
||||
return result.responseCode != 304;
|
||||
return await HeadFileAsync(_serverARDataPath, _localARDataPath);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件到本地(持续存入磁盘减少内存占用)
|
||||
/// </summary>
|
||||
/// <param name="downloadUrl">文件连接</param>
|
||||
/// <param name="fullPath">本地文件全路径</param>
|
||||
/// <param name="progress">下载进度</param>
|
||||
public static async UniTask<UnityWebRequest> DownloadToFileAsync(string downloadUrl, string fullPath,
|
||||
/// <param name="cancellation"></param>
|
||||
private static async UniTask<UnityWebRequest> DownloadToFileAsync(string downloadUrl, string fullPath,
|
||||
IProgress<float> progress = null, CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||
{
|
||||
var dh = new DownloadHandlerFile(fullPath)
|
||||
@ -138,12 +194,8 @@ namespace Assets.AR
|
||||
var result = await request.SendWebRequest().ToUniTask(progress, PlayerLoopTiming.Update,
|
||||
(cancellation?.Token ?? default(CancellationToken)));
|
||||
|
||||
var etag = result.GetResponseHeader("ETag");
|
||||
var etag = result.GetResponseHeader("x-oss-hash-crc64ecma");
|
||||
var path = fullPath + ".etag";
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
File.Create(path);
|
||||
}
|
||||
File.WriteAllText(path, etag);
|
||||
|
||||
return result;
|
||||
@ -155,7 +207,7 @@ namespace Assets.AR
|
||||
/// <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,
|
||||
private static async Task<bool> HeadFileAsync(string downloadUrl, string fullPath,
|
||||
IProgress<float> progress = null, CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||
{
|
||||
try
|
||||
@ -168,26 +220,13 @@ namespace Assets.AR
|
||||
}
|
||||
|
||||
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 != 304)
|
||||
{
|
||||
etag = result.GetResponseHeader("ETag");
|
||||
File.WriteAllText(fullPath + ".etag", etag);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
var result = await request.SendWebRequest().ToUniTask(progress, PlayerLoopTiming.Update, (cancellation?.Token ?? default(CancellationToken)));
|
||||
var responseTag = result.GetResponseHeader("x-oss-hash-crc64ecma");
|
||||
return !responseTag.Equals(etag);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,6 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Core;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using DG.Tweening;
|
||||
using Mapbox.Utils;
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using UnityEngine.Assertions;
|
||||
@ -116,18 +115,17 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
ticks++;
|
||||
}
|
||||
|
||||
public virtual void ComputeAnimator()
|
||||
protected virtual void ComputeAnimator()
|
||||
{
|
||||
if (animator != null)
|
||||
{
|
||||
animator.SetFloat(PreSpeed, (float)preSpeed);
|
||||
animator.SetFloat(AnimatorSpeed, (float)OnlineSpeed);
|
||||
animator.SetFloat(Grade, (float)currentSlope);
|
||||
animator.SetFloat(Power, (float)power);
|
||||
}
|
||||
if (animator == null) return;
|
||||
|
||||
animator.SetFloat(PreSpeed, (float)preSpeed);
|
||||
animator.SetFloat(AnimatorSpeed, (float)OnlineSpeed);
|
||||
animator.SetFloat(Grade, (float)currentSlope);
|
||||
animator.SetFloat(Power, (float)power);
|
||||
}
|
||||
//计算人物当前属性
|
||||
public virtual void ComputePlayer()
|
||||
protected virtual void ComputePlayer()
|
||||
{
|
||||
if (power > 0)
|
||||
{
|
||||
@ -141,7 +139,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
}
|
||||
//计算当前人物的经纬度
|
||||
public virtual void Forward()
|
||||
protected virtual void Forward()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -183,9 +181,11 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
public void ComputeNextSlope()
|
||||
{
|
||||
double sumDistance = 0;
|
||||
|
||||
mapData = manager.GetMapData();
|
||||
if (mapData == null)
|
||||
return;
|
||||
|
||||
var pointList = mapData.List;
|
||||
int preIndex = 0;
|
||||
for (int i = 0; i < pointList.Count; i++)
|
||||
@ -206,7 +206,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
currentIndex = pointList.Count - 1;
|
||||
}
|
||||
Debug.Log(currentIndex);
|
||||
|
||||
preIndex = currentIndex > 0 ? currentIndex - 1 : 0;//前一个索引
|
||||
int nextIndex = currentIndex == pointList.Count - 1 ? currentIndex : currentIndex + 1; //计算下一个点的坡度和距离
|
||||
|
||||
@ -218,6 +218,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
nextSlopeDistance = sumDistance - totalDistance * 1000;
|
||||
//NextSlopeTotalDistance = pointList[nextIndex].Distance;
|
||||
currentSlopeDistance = (totalDistance * 1000 - (sumDistance - pointList[currentIndex].Distance));
|
||||
|
||||
//计算累计爬升
|
||||
totalClimb = 0;
|
||||
for (int i = 1; i <= currentIndex; i++)
|
||||
@ -229,16 +230,19 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
head?.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
head?.SetActive(true);
|
||||
}
|
||||
|
||||
//显示人物头顶的名字
|
||||
public virtual void CreateHeadImage()
|
||||
protected virtual void CreateHeadImage()
|
||||
{
|
||||
if (head == null)
|
||||
{
|
||||
@ -270,17 +274,17 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
private void OnBecameInvisible()
|
||||
{
|
||||
head.SetActive(false);
|
||||
head?.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnBecameVisible()
|
||||
{
|
||||
head.SetActive(true);
|
||||
head?.SetActive(true);
|
||||
}
|
||||
|
||||
public void SetStartDistance(double distance)
|
||||
public void SetStartDistance(double _distance)
|
||||
{
|
||||
this.StartDistance = distance *1000;
|
||||
this.StartDistance = _distance *1000;
|
||||
}
|
||||
public void Destroy()
|
||||
{
|
||||
@ -288,7 +292,9 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
manager.Pause();
|
||||
}
|
||||
|
||||
head?.Destroy();
|
||||
|
||||
gameObject.Destroy();
|
||||
}
|
||||
//设置当前玩家属性
|
||||
|
||||
@ -4,7 +4,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
public class OnlineVideoPlayer : AbstractVideoPlayer
|
||||
{
|
||||
public override void CreateHeadImage()
|
||||
protected override void CreateHeadImage()
|
||||
{
|
||||
base.CreateHeadImage();
|
||||
if (Diff < 0)
|
||||
@ -39,7 +39,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
this.EndDistance = endDistance * 1000;
|
||||
}
|
||||
|
||||
public override void ComputePlayer()
|
||||
protected override void ComputePlayer()
|
||||
{
|
||||
distance = this.speed;
|
||||
}
|
||||
|
||||
@ -291,31 +291,17 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
private async Task StartDownloading()
|
||||
{
|
||||
slider.maxValue = downloader.Total * 100;
|
||||
if(downloader.IsVideoDownloaded)
|
||||
await downloader.DownLoadVideoAsync(Progress.Create<float>(HandleProgress));
|
||||
if(downloader.IsARRouteDownloaded)
|
||||
await downloader.DownLoadARRouteAsync(Progress.Create<float>(HandleProgress));
|
||||
if(downloader.IsARDataDownloaded)
|
||||
await downloader.DownLoadARDataAsync(Progress.Create<float>(HandleProgress));
|
||||
|
||||
//cancelToken = new CancellationTokenSource();
|
||||
//CompleteDownLoad();
|
||||
cancelToken = new CancellationTokenSource();
|
||||
await downloader.DownLoadDefault(ReportProgress, cancelToken);
|
||||
}
|
||||
|
||||
private void HandleProgress(float value)
|
||||
private void ReportProgress(float progress)
|
||||
{
|
||||
if (cancelToken != null && cancelToken.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
slider.value += (float)Math.Round(value * 100, 0);
|
||||
Debug.Log(value);
|
||||
|
||||
var progress = slider.value / slider.maxValue * 100;
|
||||
downloadText.text = progress.ToString(CultureInfo.InvariantCulture) + "%";
|
||||
|
||||
var isComplete = slider.value == slider.maxValue;
|
||||
if (isComplete)
|
||||
slider.value = progress * 100;
|
||||
downloadText.text = (progress * 100).ToString("f2") + "%";
|
||||
if (progress == 1f)
|
||||
CompleteDownLoad();
|
||||
}
|
||||
|
||||
@ -323,11 +309,16 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
var filepath = $"{PFConstants.VideoFolder}/{route.FileName}";
|
||||
manager.SetMedia(filepath);
|
||||
downloading = false;
|
||||
cancelToken = null;
|
||||
|
||||
watch.SetActive(App.routeResult == null);
|
||||
watch.GetComponent<Button>().enabled = true;
|
||||
|
||||
rideNow.enabled = true;
|
||||
rideNow.interactable = true;
|
||||
|
||||
downloadText.text = App.GetLocalString("Ride Now");
|
||||
downloading = false;
|
||||
}
|
||||
|
||||
//进入观察模式
|
||||
@ -370,18 +361,20 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
private void CancelDownload()
|
||||
{
|
||||
UIManager.SetModalPanel(transform.Find("ModalPanel").GetComponent<PFUIPanel>());
|
||||
|
||||
var videoUiManager = FindObjectOfType<VideoUIManager>();
|
||||
UIManager.ShowConfirm("Tips", "CancelDownloadConfirm",
|
||||
() =>
|
||||
{
|
||||
cancelToken?.Cancel();
|
||||
SceneManager.LoadSceneAsync("MainScene");
|
||||
UIManager.CloseConfirm();
|
||||
videoUiManager.SetModalPanel();
|
||||
},
|
||||
2,
|
||||
() =>
|
||||
{
|
||||
UIManager.CloseConfirm();
|
||||
videoUiManager.SetModalPanel();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
@ -61,32 +62,33 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
private void Start()
|
||||
{
|
||||
UIManager.SetModalPanel(transform.Find("ModalPanel").GetComponent<PFUIPanel>());
|
||||
|
||||
manager = FindObjectOfType<VideoGameManager>();
|
||||
Init();
|
||||
}
|
||||
|
||||
public void SetModalPanel()
|
||||
{
|
||||
UIManager.SetModalPanel(transform.Find("ModalPanel").GetComponent<PFUIPanel>());
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (manager != null && manager.GetMapRoute() != null)
|
||||
{
|
||||
mapName.text = manager.GetMapRoute().Name;
|
||||
if (manager.CurrentPlayer != null)
|
||||
{
|
||||
power.text = Math.Round(manager.CurrentPlayer.power).ToString();
|
||||
speed.text = manager.CurrentPlayer.speed.ToString("f1");
|
||||
heartRate.text = Math.Round((manager.CurrentPlayer.heartRate ?? 0d)).ToString();
|
||||
cadance.text = Math.Round(manager.CurrentPlayer.cadance).ToString();
|
||||
playerTimer.text = Helper.FormatTicks(manager.CurrentPlayer.ticks);
|
||||
distance.text = $"{Math.Round((manager.CurrentPlayer.totalDistance),2)}KM";
|
||||
left.fillAmount = (float)(Math.Round(manager.CurrentPlayer.power) / MAXPOWER_RATE);
|
||||
right.fillAmount = (float)(Math.Round((manager.CurrentPlayer.heartRate ?? 0f)) / MAXHEARRATE);
|
||||
SetSlopePanel();
|
||||
ftpImage.fillAmount = (float)(manager.CurrentPlayer.wkg / MAXWKG);
|
||||
wkg.text = $"{manager.CurrentPlayer.wkg}w/kg";
|
||||
SetHeartRateAlert();
|
||||
}
|
||||
}
|
||||
if (manager == null || manager.GetMapRoute() == null) return;
|
||||
mapName.text = manager.GetMapRoute().Name;
|
||||
if (manager.CurrentPlayer == null) return;
|
||||
power.text = Math.Round(manager.CurrentPlayer.power).ToString();
|
||||
speed.text = manager.CurrentPlayer.speed.ToString("f1");
|
||||
heartRate.text = Math.Round((manager.CurrentPlayer.heartRate ?? 0d)).ToString();
|
||||
cadance.text = Math.Round(manager.CurrentPlayer.cadance).ToString();
|
||||
playerTimer.text = Helper.FormatTicks(manager.CurrentPlayer.ticks);
|
||||
distance.text = $"{Math.Round((manager.CurrentPlayer.totalDistance),2)}KM";
|
||||
left.fillAmount = (float)(Math.Round(manager.CurrentPlayer.power) / MAXPOWER_RATE);
|
||||
right.fillAmount = (float)(Math.Round((manager.CurrentPlayer.heartRate ?? 0f)) / MAXHEARRATE);
|
||||
SetSlopePanel();
|
||||
ftpImage.fillAmount = (float)(manager.CurrentPlayer.wkg / MAXWKG);
|
||||
wkg.text = $"{manager.CurrentPlayer.wkg}w/kg";
|
||||
SetHeartRateAlert();
|
||||
}
|
||||
|
||||
//心率过高的时候显示
|
||||
@ -106,19 +108,18 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
public void ShowUpRemainTime(double remain)
|
||||
{
|
||||
if (remain > 110) return;
|
||||
|
||||
remain -= 20;
|
||||
|
||||
remain -= 15;
|
||||
|
||||
var canvas = remainTime.GetComponent<CanvasGroup>();
|
||||
if (remain <= 0)
|
||||
{
|
||||
if (canvas.alpha == 1)
|
||||
canvas.DOFade(0, 1).onComplete = () => { remainTime.SetActive(false); };
|
||||
canvas.DOFade(0, 1).onComplete = () => remainTime.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
remainTime.SetActive(true);
|
||||
remainTime.transform.Find("Bg/Distance").GetComponent<Text>().text = remain.ToString().PadLeft(2,'0');
|
||||
remainTime.transform.Find("Bg/Distance").GetComponent<Text>().text = remain.ToString(CultureInfo.InvariantCulture).PadLeft(2,'0');
|
||||
|
||||
if (canvas.alpha == 0)
|
||||
canvas.DOFade(1, 1f);
|
||||
@ -169,7 +170,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
quitBtn = transform.Find("Panel/ToolBarPanel/ExitButton").gameObject;
|
||||
changeViewBtn = transform.Find("Panel/ToolBarPanel/ChangeView").gameObject;
|
||||
deviceBtn = transform.Find("Panel/ToolBarPanel/DeviceButton").gameObject;
|
||||
//minmap
|
||||
|
||||
playerTimer = transform.Find("Panel/MiniMap/Panel/Timer").GetComponent<Text>();
|
||||
distance = transform.Find("Panel/MiniMap/Panel/Distance").GetComponent<Text>();
|
||||
mapName = transform.Find("Panel/MiniMap/Head/MapName").GetComponent<Text>();
|
||||
@ -184,7 +185,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
settingPanel = transform.Find("Panel/SettingPanel").gameObject;
|
||||
resultPanel = transform.Find("Panel/ResultPanel").gameObject;
|
||||
gameRoomResultPanel = transform.Find("Panel/GameRoomResult").gameObject;
|
||||
//
|
||||
explosive = transform.Find("Panel/Explosive").gameObject;
|
||||
//toolbar 事件注册
|
||||
UIManager.AddEvent(settingBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, ShowSetting);
|
||||
@ -197,7 +197,8 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
private void SetSlopePanel()
|
||||
{
|
||||
var normalizedSlope = (float)Math.Round(manager.CurrentPlayer.currentSlope, 1);
|
||||
slope.text = normalizedSlope > 0 ? "+"+normalizedSlope.ToString():normalizedSlope.ToString();
|
||||
slope.text = normalizedSlope > 0 ? "+"+normalizedSlope.ToString(CultureInfo.InvariantCulture):normalizedSlope.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
var strength = 3;//增强旋转角度系数
|
||||
if (normalizedSlope > 10) {
|
||||
normalizedSlope = 10f;
|
||||
@ -233,6 +234,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
UIManager.ShowRideSettingPanel();
|
||||
}
|
||||
|
||||
private void DeviceClick(BaseEventData e)
|
||||
{
|
||||
UIManager.Show(UIManager.Instance.DevicePanel, null, true);
|
||||
@ -272,12 +274,19 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
videoResultScript.InjectController(manager);
|
||||
videoResultScript.SetDataSource(manager.cyclingController.recorderData);
|
||||
}
|
||||
|
||||
public void SaveAndShowResult()
|
||||
{
|
||||
if (manager._aRMode == VideoGameManager.ARMode.INSPECT)
|
||||
if (manager._aRMode == ARMode.INSPECT)
|
||||
{
|
||||
SceneManager.LoadScene("MainScene");
|
||||
videoPlayer = FindObjectOfType<VideoPlayer>();
|
||||
videoPlayer?.Upload();
|
||||
return;
|
||||
}
|
||||
|
||||
videoPlayer = manager.CurrentPlayer as VideoPlayer;
|
||||
if(videoPlayer == null) return;
|
||||
|
||||
videoPlayer.Upload();
|
||||
//show result
|
||||
if (manager.cyclingController is GameModel)
|
||||
{
|
||||
@ -293,6 +302,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
videoResultScript.SetDataSource(manager.cyclingController.recorderData);
|
||||
}
|
||||
}
|
||||
|
||||
private void QuitClick(BaseEventData e)
|
||||
{
|
||||
var idMainRider = manager.CurrentPlayer != null && manager.CurrentPlayer.UserId == App.CurrentUser.Id;
|
||||
|
||||
@ -160,7 +160,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
cyclingController.Run(null);//发送数据到tcp
|
||||
var onlineRiders = cyclingController.riders;
|
||||
CreateOnlineUser(onlineRiders); //解析tcp返回数据
|
||||
tcpTimer += 0.2f;
|
||||
tcpTimer += 0.5f;
|
||||
}
|
||||
|
||||
//计算骑手的数据
|
||||
@ -466,27 +466,41 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
if (cyclingController.recorderData == null || cyclingController.recorderData.Saved)
|
||||
return;
|
||||
|
||||
|
||||
Quit();
|
||||
|
||||
cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime();
|
||||
var path = PFConstants.MapWorkoutRecordFolder + "/" + recordId;
|
||||
Helper.CreateDirectoryIfNotExsit(path);
|
||||
var imageFileName = path + "/" + Guid.NewGuid().ToString() + ".png";
|
||||
Helper.CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.5f, Screen.height * 0.5f), imageFileName);
|
||||
|
||||
cyclingController.recorderData.StartTime = startTime;
|
||||
cyclingController.recorderData.IsCompleted = totalDistance >= mapData.TotalDistance;
|
||||
cyclingController.recorderData.EndDistance = cyclingController.recorderData.IsCompleted ? mapData.TotalDistance : totalDistance;
|
||||
cyclingController.recorderData.AntModelId = AntModelId;
|
||||
cyclingController.recorderData.ManufacturerId = ManufacturerId;
|
||||
cyclingController.recorderData.ManufacturerName = ManufacturerName;
|
||||
cyclingController.recorderData.DeviceNumber = DeviceNumber;
|
||||
cyclingController.recorderData.LastFrame = GetCurrentFrame();
|
||||
|
||||
RankingId = cyclingController.recorderData.SaveWithLocalRecordAysnc(cyclingModel, selectParamModel, imageFileName, recordId, path);
|
||||
try
|
||||
{
|
||||
cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime();
|
||||
cyclingController.recorderData.StartTime = startTime;
|
||||
cyclingController.recorderData.IsCompleted = totalDistance >= mapData.TotalDistance;
|
||||
cyclingController.recorderData.EndDistance = cyclingController.recorderData.IsCompleted ? mapData.TotalDistance: totalDistance;
|
||||
cyclingController.recorderData.AntModelId = AntModelId;
|
||||
cyclingController.recorderData.ManufacturerId = ManufacturerId;
|
||||
cyclingController.recorderData.ManufacturerName = ManufacturerName;
|
||||
cyclingController.recorderData.DeviceNumber = DeviceNumber;
|
||||
cyclingController.recorderData.LastFrame = GetCurrentFrame();
|
||||
|
||||
var imagePath = CreateRecordCover(path);
|
||||
RankingId = cyclingController.recorderData.SaveWithLocalRecordAysnc(cyclingModel, selectParamModel,
|
||||
imagePath, recordId, path);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Helper.DelectDir(path);
|
||||
Debug.Log(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private string CreateRecordCover(string path)
|
||||
{
|
||||
Helper.CreateDirectoryIfNotExsit(path);
|
||||
var imagePath = path + "/" + Guid.NewGuid().ToString() + ".png";
|
||||
Helper.CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.5f, Screen.height * 0.5f), imagePath);
|
||||
return imagePath;
|
||||
}
|
||||
|
||||
public void AddEvent(GameObject sender, EventTriggerType eventType, UnityAction<BaseEventData> unityAction)
|
||||
{
|
||||
UIManager.AddEvent(sender, eventType, unityAction);
|
||||
|
||||
@ -41,7 +41,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
_uimanager?.SaveAndShowResult();
|
||||
}
|
||||
|
||||
public override void ComputePlayer()
|
||||
protected override void ComputePlayer()
|
||||
{
|
||||
heartRate = manager.UpDateHeart();
|
||||
power = manager.UpdatePower();
|
||||
@ -77,8 +77,13 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
UIManager.ShowGameRoomCountDownPanel((int)seconds, () =>
|
||||
{
|
||||
Upload();
|
||||
var uiManager = FindObjectOfType<VideoUIManager>();
|
||||
uiManager.ShowResultPanel();
|
||||
|
||||
if (_uimanager == null)
|
||||
{
|
||||
_uimanager = FindObjectOfType<VideoUIManager>();
|
||||
}
|
||||
_uimanager.ShowResultPanel();
|
||||
|
||||
},true);
|
||||
}
|
||||
}
|
||||
@ -120,7 +125,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
private double RemainingDistance => Math.Round((mapData.TotalDistance - totalDistance) * 1000);
|
||||
|
||||
public override void Forward()
|
||||
protected override void Forward()
|
||||
{
|
||||
base.Forward();
|
||||
distance = Math.Round(speed / 3600, 5, MidpointRounding.AwayFromZero);
|
||||
|
||||
@ -18,7 +18,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
|
||||
private MapCompetitionApi mapCompetitionApi;
|
||||
|
||||
public MapCompetition mapCompetition;
|
||||
public MapCompetition mapCompetition { get; set; }
|
||||
|
||||
private List<CompetitionRankingResultModel> mapWorkoutRecordRankings = new List<CompetitionRankingResultModel>();
|
||||
/// <summary>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,6 +69,8 @@ public class GameRoomListController : PFUIPanel
|
||||
private Transform cycingRoomModal;
|
||||
private Transform resultRoomModal;
|
||||
private GameObject RoomRankItem;
|
||||
|
||||
InputField hourInputField, minInputField;
|
||||
|
||||
private string RoomName;
|
||||
private string Roompwd;
|
||||
@ -103,6 +105,12 @@ public class GameRoomListController : PFUIPanel
|
||||
private bool ListChanged = false;
|
||||
private bool CreateRoomSuccessed = false;
|
||||
PFUIPageHelper pageHelper;
|
||||
private ARDownloader downloader;
|
||||
private GameRoomModel modelGameRoom { get; set; }
|
||||
private Text CyclingTimer { get; set; }
|
||||
List<GameRoomModel> list;
|
||||
private int Total { get; set; }
|
||||
private bool CreateClicked { get; set; }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
@ -126,73 +134,7 @@ public class GameRoomListController : PFUIPanel
|
||||
UIManager.AddEvent(_avatar, UnityEngine.EventSystems.EventTriggerType.PointerClick, AvatarBtn_Click);
|
||||
|
||||
}
|
||||
private void SearchBtn_Click(BaseEventData data)
|
||||
{
|
||||
pageHelper.PageIndex = 0;
|
||||
Query();
|
||||
}
|
||||
private void AvatarBtn_Click(BaseEventData data)
|
||||
{
|
||||
UIManager.ShowUserInfoPanel();
|
||||
}
|
||||
private void Query()
|
||||
{
|
||||
MapUDPService.SendQueryGameRoomList(App.CurrentUser.Id, pageHelper.PageIndex, pageHelper.PageSize, seachName);
|
||||
}
|
||||
private void Refreash()
|
||||
{
|
||||
Utils.DestroyChildren(_rectTransform);
|
||||
pageHelper.Total = Total;
|
||||
pageHelper.Build();
|
||||
if (list == null)
|
||||
{
|
||||
_noDataFound.SetActive(true);
|
||||
return;
|
||||
}
|
||||
_noDataFound.SetActive(false);
|
||||
int index = 0;
|
||||
foreach (var item in list)
|
||||
{
|
||||
index++;
|
||||
var g = Instantiate(RoomCell, _rectTransform);
|
||||
g.GetComponent<GameRoomCell>().ConfigureCell(item, index);
|
||||
}
|
||||
}
|
||||
List<GameRoomModel> list;
|
||||
private int Total { get; set; }
|
||||
private bool CreateClicked { get; set; }
|
||||
private void ListenerHandler(List<ReceiveMsgModel> message)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (message.Count > 1)
|
||||
return;
|
||||
//查询列表
|
||||
var roomList = message.Where(c => c.RoomList != null).FirstOrDefault();
|
||||
if (roomList != null)
|
||||
{
|
||||
list = roomList.RoomList;
|
||||
Total = roomList.GameRoomTotal;
|
||||
ListChanged = true;
|
||||
}
|
||||
//查询自己当前创建的房间信息并进入
|
||||
var info = message.Where(c => c.RoomList != null && c.RoomList.Where(o => o.UserId == App.CurrentUser.Id && o.Status == 0).Any()).FirstOrDefault();
|
||||
if (info != null)
|
||||
{
|
||||
GameRoom = info.RoomList[0];
|
||||
App.gameRoomDetail = GameRoom;
|
||||
CreateRoomSuccessed = true;
|
||||
//进入房间清空列表
|
||||
list = null;
|
||||
Total = 0;
|
||||
ListChanged = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
@ -208,14 +150,6 @@ public class GameRoomListController : PFUIPanel
|
||||
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
App.Model = "GameRoom";
|
||||
MapUDPService.MessageListener = ListenerHandler;
|
||||
MapUDPService.SendQueryGameRoomList(App.CurrentUser.Id, pageHelper.PageIndex, pageHelper.PageSize, seachName);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
//房间已经进行骑行时间
|
||||
@ -265,8 +199,84 @@ public class GameRoomListController : PFUIPanel
|
||||
|
||||
RenderDownloadTask();
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
App.Model = "GameRoom";
|
||||
MapUDPService.MessageListener = ListenerHandler;
|
||||
MapUDPService.SendQueryGameRoomList(App.CurrentUser.Id, pageHelper.PageIndex, pageHelper.PageSize, seachName);
|
||||
}
|
||||
|
||||
//LOOM中取数据渲染下载当前下载进度
|
||||
private void SearchBtn_Click(BaseEventData data)
|
||||
{
|
||||
pageHelper.PageIndex = 0;
|
||||
Query();
|
||||
}
|
||||
|
||||
private void AvatarBtn_Click(BaseEventData data)
|
||||
{
|
||||
UIManager.ShowUserInfoPanel();
|
||||
}
|
||||
|
||||
private void Query()
|
||||
{
|
||||
MapUDPService.SendQueryGameRoomList(App.CurrentUser.Id, pageHelper.PageIndex, pageHelper.PageSize, seachName);
|
||||
}
|
||||
|
||||
private void Refreash()
|
||||
{
|
||||
Utils.DestroyChildren(_rectTransform);
|
||||
pageHelper.Total = Total;
|
||||
pageHelper.Build();
|
||||
if (list == null)
|
||||
{
|
||||
_noDataFound.SetActive(true);
|
||||
return;
|
||||
}
|
||||
_noDataFound.SetActive(false);
|
||||
int index = 0;
|
||||
foreach (var item in list)
|
||||
{
|
||||
index++;
|
||||
var g = Instantiate(RoomCell, _rectTransform);
|
||||
g.GetComponent<GameRoomCell>().ConfigureCell(item, index);
|
||||
}
|
||||
}
|
||||
|
||||
private void ListenerHandler(List<ReceiveMsgModel> message)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (message.Count > 1)
|
||||
return;
|
||||
//查询列表
|
||||
var roomList = message.Where(c => c.RoomList != null).FirstOrDefault();
|
||||
if (roomList != null)
|
||||
{
|
||||
list = roomList.RoomList;
|
||||
Total = roomList.GameRoomTotal;
|
||||
ListChanged = true;
|
||||
}
|
||||
//查询自己当前创建的房间信息并进入
|
||||
var info = message.Where(c => c.RoomList != null && c.RoomList.Where(o => o.UserId == App.CurrentUser.Id && o.Status == 0).Any()).FirstOrDefault();
|
||||
if (info != null)
|
||||
{
|
||||
GameRoom = info.RoomList[0];
|
||||
App.gameRoomDetail = GameRoom;
|
||||
CreateRoomSuccessed = true;
|
||||
//进入房间清空列表
|
||||
list = null;
|
||||
Total = 0;
|
||||
ListChanged = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void RenderDownloadTask()
|
||||
{
|
||||
var downLoadList = transform.Find("DownLoadList").gameObject;
|
||||
@ -510,7 +520,7 @@ public class GameRoomListController : PFUIPanel
|
||||
Query();
|
||||
});
|
||||
}
|
||||
InputField hourInputField, minInputField;
|
||||
|
||||
private void InitStep2()
|
||||
{
|
||||
//关门时间
|
||||
@ -647,6 +657,7 @@ public class GameRoomListController : PFUIPanel
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void HandleStepBtn(string btnName)
|
||||
{
|
||||
next.SetActive(btnName == previous.name);
|
||||
@ -661,6 +672,7 @@ public class GameRoomListController : PFUIPanel
|
||||
step1Btn.transform.Find("Bg").gameObject.SetActive(btnName == previous.name);
|
||||
step2Btn.transform.Find("Bg").gameObject.SetActive(btnName != previous.name);
|
||||
}
|
||||
|
||||
private void HandleFormInput()
|
||||
{
|
||||
if (Members >= 2 && !string.IsNullOrEmpty(RoomName) && CloseTime > 0 && CloseTime < 120)
|
||||
@ -680,6 +692,7 @@ public class GameRoomListController : PFUIPanel
|
||||
create.GetComponent<Button>().enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleCloseTimeBtnClick(int closeTime, string btnName)
|
||||
{
|
||||
if (btnName != "MinInputField" && btnName != "HourInputField")
|
||||
@ -699,6 +712,7 @@ public class GameRoomListController : PFUIPanel
|
||||
btn60.GetComponent<Image>().color = btn60.name == btnName ? pink : grey;
|
||||
HandleFormInput();
|
||||
}
|
||||
|
||||
private void HandleMembersBtnClick(int members, string btnName)
|
||||
{
|
||||
ColorUtility.TryParseHtmlString("#3D3E4D", out Color grey);
|
||||
@ -711,6 +725,7 @@ public class GameRoomListController : PFUIPanel
|
||||
btn6.GetComponent<Image>().color = btn6.name == btnName ? pink : grey;
|
||||
HandleFormInput();
|
||||
}
|
||||
|
||||
private void ChangeDistance(int index)
|
||||
{
|
||||
var text = distanceOptions.GetComponent<Dropdown>().options[index].text;
|
||||
@ -718,6 +733,7 @@ public class GameRoomListController : PFUIPanel
|
||||
scroll.GetComponent<ScrollRect>().verticalNormalizedPosition = 1;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void OnEndDrag(BaseEventData arg0)
|
||||
{
|
||||
var scrollrect = scroll.GetComponent<ScrollRect>();
|
||||
@ -731,6 +747,7 @@ public class GameRoomListController : PFUIPanel
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowPwdConfirm()
|
||||
{
|
||||
enterRoomModal.gameObject.SetActive(true);
|
||||
@ -758,17 +775,13 @@ public class GameRoomListController : PFUIPanel
|
||||
}
|
||||
}
|
||||
|
||||
private ARDownloader downloader;
|
||||
|
||||
private GameRoomModel modelGameRoom { get; set; }
|
||||
//private GameRoomModel modelGameRoom { get; set; }
|
||||
private Text CyclingTimer { get; set; }
|
||||
public void ShowCycingPanel(GameRoomModel gameRoomModel)
|
||||
{
|
||||
ShowStatusModal(cycingRoomModal, gameRoomModel);
|
||||
modelGameRoom = gameRoomModel; //倒计时
|
||||
CyclingTimer = cycingRoomModal.Find("Modal/Timer").GetComponent<Text>();
|
||||
}
|
||||
|
||||
public void ShowDonePanel(int roomId)
|
||||
{
|
||||
var result = ConfigHelper.GameRoomApi.GetDetail(roomId);
|
||||
@ -794,6 +807,7 @@ public class GameRoomListController : PFUIPanel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowStatusModal(Transform tr,GameRoomModel data)
|
||||
{
|
||||
tr.Find("Modal/Id").GetComponent<Text>().text = data.RoomId.ToString().PadLeft(7, '0');
|
||||
@ -823,6 +837,7 @@ public class GameRoomListController : PFUIPanel
|
||||
UIManager.AddEvent(quit, EventTriggerType.PointerClick, (e) => { tr.gameObject.SetActive(false); });
|
||||
tr.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void GetInRoom()
|
||||
{
|
||||
//1.房间人数已经满了
|
||||
@ -844,19 +859,23 @@ public class GameRoomListController : PFUIPanel
|
||||
MapUDPService.SendJoinGameRoom(App.gameRoomDetail.RoomId,App.CurrentUser.Id,UIManager.Now.GetDateTime().ToUniversalTime());
|
||||
UIManager.ShowGameRoomDetailPanel();
|
||||
}
|
||||
|
||||
public void SelectRoom(GameRoomModel room)
|
||||
{
|
||||
GameRoom = room;
|
||||
RoomId = GameRoom.RoomId;
|
||||
}
|
||||
|
||||
public int GetRoomId()
|
||||
{
|
||||
return RoomId;
|
||||
}
|
||||
|
||||
public GameRoomModel GetCurrentRoom()
|
||||
{
|
||||
return GameRoom;
|
||||
}
|
||||
|
||||
public void Select(MapRoute map)
|
||||
{
|
||||
Map = map;
|
||||
@ -887,6 +906,7 @@ public class GameRoomListController : PFUIPanel
|
||||
tabContainer.Find("Country").GetComponent<RawImage>().texture = UIManager.Instance.loginRegOptions.GetCountryImage(map.CountryCode);
|
||||
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
content.transform.DestroyChildren();
|
||||
@ -894,54 +914,53 @@ public class GameRoomListController : PFUIPanel
|
||||
isEnd = false;
|
||||
GetList();
|
||||
}
|
||||
|
||||
private void onEndEdit()
|
||||
{
|
||||
var t = searchInput.GetComponent<InputField>().text;
|
||||
ftname = t;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void DisplayMaps(List<MapRoute> list)
|
||||
{
|
||||
if (map != null)
|
||||
if (map == null) return;
|
||||
foreach (var item in list)
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
var obj = Instantiate(map);
|
||||
obj.GetComponent<GameRoomMapItem>().Initial(item, caches);
|
||||
//obj.SendMessage("Initial", );
|
||||
obj.transform.SetParent(content.transform);
|
||||
obj.transform.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
var obj = Instantiate(map, content.transform, true);
|
||||
obj.GetComponent<GameRoomMapItem>().Initial(item, caches);
|
||||
obj.transform.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private async void GetList()
|
||||
{
|
||||
if (isEnd) return;
|
||||
var res = await ConfigHelper.mapApi.GetList(pageIndex, pageSize, ftname, distance, string.Join(",", hands), is3d, sort, sortDire, isEnableAR: isEnableAR, isEnableBattle: true);
|
||||
if (res.result)
|
||||
var res = await ConfigHelper.mapApi.GetList(pageIndex, pageSize, ftname, distance, string.Join(",", hands),
|
||||
is3d, sort, sortDire, isEnableAR: isEnableAR, isEnableBattle: true);
|
||||
if (!res.result) return;
|
||||
|
||||
if (res.data.Count == 0)
|
||||
{
|
||||
if (res.data.Count == 0)
|
||||
if (pageIndex != 0)
|
||||
{
|
||||
if (pageIndex != 0)
|
||||
{
|
||||
isEnd = true;
|
||||
scroll.transform.Find("Error").gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("当前没查到内容");
|
||||
scroll.transform.Find("Error").gameObject.SetActive(true);
|
||||
}
|
||||
isEnd = true;
|
||||
scroll.transform.Find("Error").gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
isEnd = false;
|
||||
DisplayMaps(res.data);
|
||||
scroll.transform.Find("Error").gameObject.SetActive(false);
|
||||
Debug.Log("当前没查到内容");
|
||||
scroll.transform.Find("Error").gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
isEnd = false;
|
||||
DisplayMaps(res.data);
|
||||
scroll.transform.Find("Error").gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
//创建房间
|
||||
private void CreateGameRoom(BaseEventData data)
|
||||
{
|
||||
@ -957,6 +976,7 @@ public class GameRoomListController : PFUIPanel
|
||||
|
||||
MapList.SetActive(true);
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
|
||||
@ -1297,6 +1297,7 @@ public class UIManager : MonoBehaviour
|
||||
if (UIManager.Instance.confirm != null)
|
||||
{
|
||||
UIManager.Instance.confirm.Close();
|
||||
UIManager.Instance.confirm = null;
|
||||
}
|
||||
}
|
||||
public static void ShowConfirm3(string title, string content, UnityAction action1, UnityAction action2,UnityAction action3)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user