169 lines
6.0 KiB
C#
169 lines
6.0 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;
|
|
;
|
|
headPanel = manager.GetCanvasTransform().Find("GraphChart/HeadPanel").gameObject;
|
|
MoveGraphHead(true);
|
|
|
|
}
|
|
|
|
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);
|
|
//}
|
|
}
|
|
protected override void MoveGraphHead(bool init = false)
|
|
{
|
|
Vector3 oldPos = headPanel.transform.position;
|
|
int nextIndex = currentIndex;
|
|
var viewIndex = chartDataSourceScript.GetViewIndex(nextIndex);
|
|
|
|
var n = graph.DataSource.GetPoint("Player 2", viewIndex);
|
|
graph.PointToWorldSpace(out Vector3 nextPosition, n.x, n.y, "Player 2");
|
|
//nextPosition.x -= 14f;
|
|
//nextPosition.y += 5f;
|
|
//人物移动 停止条件 到中间且线未加载完
|
|
if (manager.IsStart() && chartDataSourceScript.ReachMid(viewIndex) && !chartDataSourceScript.ReachEnd())
|
|
{
|
|
var currentDistance = totalDistance;
|
|
var offset = currentDistance > 0 ? distance * 1000 / currentDistance : 1;
|
|
if (UserId == manager.CurrentPlayer.UserId)
|
|
{
|
|
graph.HorizontalScrolling += offset;
|
|
}
|
|
var duration = init ? 0 : 1;
|
|
headPanel.transform.DOMove(new Vector3(oldPos.x, nextPosition.y, 0), duration);
|
|
}
|
|
else
|
|
{
|
|
headPanel.transform.position = new Vector3(nextPosition.x, nextPosition.y, 0);
|
|
//headPanel.transform.DOMove(new Vector3(nextPosition.x, nextPosition.y, 0), 1);
|
|
}
|
|
headPanel.transform.SetAsLastSibling();
|
|
}
|
|
//保存骑行记录
|
|
public void Upload()
|
|
{
|
|
if (manager.cyclingController.recorderData != null && !manager.cyclingController.recorderData.Saved)//处理重复上传的问题
|
|
{
|
|
manager.Save(totalDistance);
|
|
}
|
|
}
|
|
}
|
|
}
|