路线产生逻辑微调

This commit is contained in:
lishuo committed 2021-04-15 17:09:35 +08:00
1 parent 62938ec6ae
commit 92e43c2cd8
21 files changed
+3375 -1829

No files matched your search

+19 -14
View File
@@ -33,8 +33,8 @@ namespace Assets.Scenes.Ride.Scripts
#region 选手骑行数据
protected Vector2d nextlatlong; //下一个点的坐标
protected bool isStart;//开始或者暂停
protected bool isQuit;//true 中途退出 或者到达终点
//protected bool isStart;//开始或者暂停
public bool isQuit;//true 中途退出 或者到达终点
protected bool isMajor;//是否是主人公
protected MapDataModel mapData;
protected int userId;
@@ -59,7 +59,6 @@ namespace Assets.Scenes.Ride.Scripts
public double TotalClimb { get => totalClimb; }
public int UserId { get => userId; }
public bool IsStart { get => isStart; }
public double Speed { get => speed; }
public double Power { get => power; }
public double Cadance { get => cadance; }
@@ -79,20 +78,17 @@ namespace Assets.Scenes.Ride.Scripts
//开始骑行
public void SetStart()
{
isStart = true;
mainController.isStart = true;
startTime = DateTime.Now;
}
//继续骑行
public void SetContinue()
{
isStart = true;
mainController.isStart = true;
}
//暂停骑行
public void SetPause()
{
isStart = false;
mainController.isStart = false;
//characterAnimator.SetBool("IsRide", false);
}
@@ -126,7 +122,6 @@ namespace Assets.Scenes.Ride.Scripts
mapData = mainController.GetMapData();//获取路书信息
nextlatlong = new Vector2d(mapData.List[0].Point[0], mapData.List[0].Point[1]);//初始化人物位置 TODO加上之前骑行距离
cyclingExcutor = mainController.cyclingController;
isStart = mainController.isStart;
}
protected virtual void Excute()
@@ -135,6 +130,7 @@ namespace Assets.Scenes.Ride.Scripts
timer -= Time.deltaTime;
if (timer <= 0)//定时器 一秒执行一次
{
SendTcp();
Run();
timer = 1.0f;
}
@@ -143,16 +139,23 @@ namespace Assets.Scenes.Ride.Scripts
protected virtual void Run()
{
ComputeNextSlope();//计算下一个坡度相关数据
SendTcp();
if (mainController.isStart)
{
ticks++;
//计算累计爬升
var diff = mapData.List[CurrentIndex].Elevation - elevation;
if (diff > 0)
if (index > 0)
{
totalClimb += diff;
totalClimb = 0;
//计算累计爬升
for (int i = 1; i <= index; i++)
{
var diff = mapData.List[i].Elevation - mapData.List[i - 1].Elevation;
if (diff > 0)
{
totalClimb += diff;
}
}
}
ticks++;
Compute();//接受蓝牙设备数据计算
//characterAnimator.SetBool("IsRide", false);//初始化动画状态
if (totalDistance <= mapData.TotalDistance)
@@ -178,7 +181,7 @@ namespace Assets.Scenes.Ride.Scripts
//characterAnimator.SetBool("ReachEnd", true);//到达终点
//Task.Run(() => { });//异步上传数据
Upload();
isStart = false;
//mainController.isStart = false;
isQuit = true;
}
}
@@ -241,6 +244,7 @@ namespace Assets.Scenes.Ride.Scripts
{
double sumDistance = 0;
var pointList = mapData.List;
int preIndex = 0;
for (int i = 0; i < pointList.Count; i++)
{
sumDistance += pointList[i].Distance;
@@ -250,6 +254,7 @@ namespace Assets.Scenes.Ride.Scripts
break;
}
}
preIndex = index > 0 ? index - 1:0;
//计算当前海拔和坡度
elevation = pointList[index].Elevation;
currentSlope = pointList[index].Grade;