173 lines
5.6 KiB
C#
173 lines
5.6 KiB
C#
using Assets.Scenes.Ride.Scripts.Model;
|
|
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
|
using System;
|
|
using UnityEngine;
|
|
|
|
namespace Assets.Scripts.Scenes.VideoRide
|
|
{
|
|
public class VideoPlayer : AbstractVideoPlayer
|
|
{
|
|
private bool isSingle = true;
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
animator.Play("idle");
|
|
userId = App.CurrentUser.Id;
|
|
userName = App.CurrentUser.Nickname;
|
|
}
|
|
|
|
protected bool GetStart()
|
|
{
|
|
return manager.IsStart();
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
}
|
|
|
|
public void SetPower(double power)
|
|
{
|
|
this.power = power;
|
|
}
|
|
|
|
public void SetEndDistance(double distance)
|
|
{
|
|
this.totalDistance = distance;
|
|
this.PreDistance = distance * 1000;
|
|
this.EndDistance = PreDistance;
|
|
}
|
|
|
|
public void Complete()
|
|
{
|
|
start = false;
|
|
var uimanager= FindObjectOfType<VideoUIManager>();
|
|
if (uimanager!= null)
|
|
{
|
|
uimanager.SaveAndShowResult();
|
|
}
|
|
}
|
|
|
|
protected override void ComputeAnimator()
|
|
{
|
|
base.ComputeAnimator();
|
|
}
|
|
|
|
protected override void ComputePlayer()
|
|
{
|
|
heartRate = manager.UpDateHeart();
|
|
power = manager.UpdatePower();
|
|
cadance = manager.UpdateCadence();
|
|
//#if UNITY_EDITOR
|
|
if (mockpower > 0)
|
|
{
|
|
power = mockpower;
|
|
cadance = 50;
|
|
heartRate = 120;
|
|
}
|
|
//#endif
|
|
weight = App.CurrentUser.Weight;
|
|
bicycleWeight = App.CurrentUser.BicycleWeight;
|
|
wkg = Math.Round(power / weight, 2);
|
|
|
|
//发送阻力
|
|
manager.TrackResistance(currentSlope * App.RideSetting.Sensitivity / 100);
|
|
base.ComputePlayer();
|
|
//比人先完成触发关门时间
|
|
HandleForGameRoom();
|
|
}
|
|
private bool gameRoomHandled { get; set; }
|
|
//房间倒计时保存
|
|
private void HandleForGameRoom()
|
|
{
|
|
var model = manager.cyclingController as GameModel;
|
|
if (model != null && model.FirstEndTime.HasValue && !gameRoomHandled && App.CurrentUser.Id != model.FirstUserId)
|
|
{
|
|
gameRoomHandled = true;
|
|
var gap = model.FirstEndTime.Value - UIManager.Now.GetDateTime();
|
|
var seconds = Math.Floor(gap.TotalSeconds);
|
|
UIManager.ShowGameRoomCountDownPanel((int)seconds, () => {
|
|
Upload();
|
|
var uiManager = FindObjectOfType<VideoUIManager>();
|
|
uiManager.ShowResultPanel();
|
|
},true);
|
|
}
|
|
}
|
|
//控制视频播放速度
|
|
protected override void ComputeVideo()
|
|
{
|
|
base.ComputeVideo();
|
|
//单人骑行到终点自动暂停
|
|
}
|
|
|
|
protected override void ComputeRecord()
|
|
{
|
|
var mapData = manager.GetMapData();
|
|
//记录骑行数据
|
|
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,
|
|
_FrameRate = manager.GetCurrentFrame()
|
|
};
|
|
|
|
var preDistance = totalDistance >= mapData.TotalDistance ? targetData._Distance : targetData._Distance - distance;
|
|
if (!isSingle)
|
|
{
|
|
preDistance = 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 (isSingle && totalDistance >= mapData.TotalDistance)
|
|
{
|
|
Complete();
|
|
}
|
|
}
|
|
|
|
protected override void Forward()
|
|
{
|
|
base.Forward();
|
|
distance = Math.Round(speed / 3600, 5, MidpointRounding.AwayFromZero);
|
|
totalDistance += distance;
|
|
}
|
|
//保存骑行记录
|
|
public void Upload()
|
|
{
|
|
if (manager.cyclingController.recorderData != null && !manager.cyclingController.recorderData.Saved)//处理重复上传的问题
|
|
{
|
|
manager.Save(totalDistance);
|
|
}
|
|
}
|
|
|
|
public override void SetPlayer(string name, double speed, double preDistance, double endDistance, double cadance, double heartRate, double wkg, int userId, double power, double currentPlayerDistance, int frame)
|
|
{
|
|
if (manager == null)
|
|
{
|
|
manager = FindObjectOfType<VideoGameManager>();
|
|
}
|
|
this.PreDistance = preDistance * 1000;
|
|
this.EndDistance = endDistance * 1000;
|
|
|
|
|
|
if (manager.IsQuit())
|
|
{
|
|
this.OnlineSpeed = 0;
|
|
}
|
|
else
|
|
{
|
|
this.OnlineSpeed = speed / 3.6;
|
|
}
|
|
}
|
|
}
|
|
}
|