fix:AR相关修改
This commit is contained in:
1 parent
74ba5790f9
commit
c95f6b7c70
12 files changed
+382
-368
No files matched your search
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user