135 lines
4.5 KiB
C#
135 lines
4.5 KiB
C#
using Assets.Scenes.Ride.Scripts;
|
|
using Assets.Scenes.Ride.Scripts.Model;
|
|
using DG.Tweening;
|
|
using System;
|
|
using UnityEngine;
|
|
|
|
namespace Assets.Scripts.Scenes.VideoRide
|
|
{
|
|
public class VideoPlayer : AbstractVideoPlayer
|
|
{
|
|
public double EndDistance => totalDistance;
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
animator.Play("idle");
|
|
power = 200;;
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
}
|
|
public void SetPower(double power)
|
|
{
|
|
this.power = power;
|
|
}
|
|
public void SetEndDistance(double distance)
|
|
{
|
|
this.totalDistance = distance;
|
|
}
|
|
public void Complete()
|
|
{
|
|
start = false;
|
|
manager.Save(totalDistance);
|
|
}
|
|
protected override void ComputeAnimator()
|
|
{
|
|
base.ComputeAnimator();
|
|
var currentFrame = manager.GetCurrentFrame();
|
|
if (manager.mockDirection.ContainsKey(currentFrame))
|
|
{
|
|
bearing = manager.mockDirection[currentFrame];
|
|
}
|
|
animator.SetFloat("bearing", bearing);
|
|
}
|
|
protected override void ComputePlayer()
|
|
{
|
|
heartRate = manager.UpDateHeart();
|
|
power = manager.UpdatePower();
|
|
cadance = manager.UpdateCadence();
|
|
#region TEST
|
|
power = 200;
|
|
cadance = 150;
|
|
heartRate = 160;
|
|
#endregion
|
|
weight = App.CurrentUser.Weight;
|
|
bicycleWeight = App.CurrentUser.BicycleWeight;
|
|
//发送阻力
|
|
manager.TrackResistance(currentSlope);
|
|
base.ComputePlayer();
|
|
//一旦有功率就开始骑行、否则暂停
|
|
if (!manager.IsQuit())
|
|
{
|
|
if (power > 0)
|
|
{
|
|
manager.StartGame();
|
|
}
|
|
}
|
|
}
|
|
//控制视频播放速度
|
|
protected override void ComputeVideo()
|
|
{
|
|
|
|
mapData = manager.GetMapData();
|
|
float ratio = 1;
|
|
if (currentIndex + 1 < mapData.List.Count)
|
|
{
|
|
ratio = (float)(speed / mapData.List[currentIndex + 1].Speed);
|
|
}
|
|
else
|
|
{
|
|
ratio = (float)(speed / mapData.List[currentIndex].Speed);
|
|
}
|
|
if (manager.CurrentPlayer != null && manager.CurrentPlayer.UserId != UserId)
|
|
return;
|
|
|
|
manager.Play(ratio);
|
|
|
|
//if (totalDistance >= mapData.TotalDistance)
|
|
//{
|
|
// start = false;
|
|
// manager.Pause();//暂停视频
|
|
//}
|
|
}
|
|
|
|
protected override void ComputeRecord()
|
|
{
|
|
var mapData = manager.GetMapData();
|
|
//Debug.Log($"ticks:{ticks}-{manager.GetCurrentFrame()}-endistance:{totalDistance}-totalDistance:{mapData.TotalDistance}-index:{currentIndex}-speed:{speed}-currentSlope:{currentSlope}-GetCurrentFrame:{manager.GetCurrentFrame()}-currentlatLon:{bearing}");
|
|
//记录骑行数据
|
|
var recorderData = manager.cyclingController.recorderData;
|
|
var targetData = new TargetData
|
|
{
|
|
Ticks = ticks,
|
|
_Power = power,
|
|
_Speed = speed,
|
|
_Distance = totalDistance > mapData.TotalDistance ? mapData.TotalDistance : totalDistance,
|
|
_Cadence = cadance,
|
|
_HeartRate = heartRate,
|
|
_Lat = currentlatLon.x,
|
|
_Lon = currentlatLon.y,
|
|
_TotalClimb = totalClimb,
|
|
};
|
|
var preDistance = totalDistance >= mapData.TotalDistance ? targetData._Distance : targetData._Distance - distance;
|
|
recorderData.PreDistance = Math.Round(preDistance, 6, MidpointRounding.AwayFromZero);
|
|
recorderData.EndDistance = Math.Round(targetData._Distance, 6, MidpointRounding.AwayFromZero);
|
|
recorderData.RiderDatas.Add(targetData);
|
|
|
|
//if (totalDistance >= mapData.TotalDistance)
|
|
//{
|
|
// start = false;
|
|
// manager.Save(totalDistance);
|
|
//}
|
|
}
|
|
//保存骑行记录
|
|
public void Upload()
|
|
{
|
|
if (manager.cyclingController.recorderData != null && !manager.cyclingController.recorderData.Saved)//处理重复上传的问题
|
|
{
|
|
manager.Save(totalDistance);
|
|
}
|
|
}
|
|
}
|
|
}
|