海拔图和小地图
This commit is contained in:
1 parent
42fa59d103
commit
8ad36c965d
521 files changed
+1985033
-439
No files matched your search
@@ -11,6 +11,8 @@ using GeoJSON.Net.Geometry;
|
||||
using TurfCS;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
@@ -21,7 +23,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
GameObject character;
|
||||
[SerializeField]
|
||||
Animator characterAnimator;
|
||||
[SerializeField]
|
||||
//[SerializeField]
|
||||
AbstractMap map;
|
||||
|
||||
#region 动画控制参数
|
||||
@@ -36,6 +38,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
bool isStart;
|
||||
MapDataModel mapData;
|
||||
int userId;
|
||||
DateTime startTime;//开始骑行时间
|
||||
|
||||
double speed;
|
||||
double power;
|
||||
@@ -69,6 +72,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
characterAnimator = GetComponentInChildren<Animator>();
|
||||
var mainController = transform.parent.GetComponent<MainController>();
|
||||
map = FindObjectOfType<AbstractMap>();
|
||||
mapData = mainController.GetMapData();//获取路书信息
|
||||
InitializePlayer(mainController.GetCenterCoordinate());//初始人物
|
||||
}
|
||||
@@ -84,10 +88,21 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
|
||||
#region 骑行逻辑
|
||||
//当前人物骑行状态 true 开始 false 暂停
|
||||
public void SetStart(bool start)
|
||||
//开始骑行
|
||||
public void SetStart()
|
||||
{
|
||||
isStart = start;
|
||||
isStart = true;
|
||||
startTime = DateTime.Now;
|
||||
}
|
||||
//继续骑行
|
||||
public void SetContinue()
|
||||
{
|
||||
isStart = true;
|
||||
}
|
||||
//暂停骑行
|
||||
public void SetPause()
|
||||
{
|
||||
isStart = false;
|
||||
}
|
||||
|
||||
//初始化玩家距离/朝向
|
||||
@@ -95,7 +110,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
ticks = 0;//当前骑行时间
|
||||
//初始化人物位置
|
||||
totalDistance = 10;//TODO:根据骑行模式动态取值
|
||||
totalDistance = 0;//TODO:根据骑行模式动态取值 KM
|
||||
currentlatlong = Along(totalDistance);//new Vector2d(coordinates[0], coordinates[1]);//当前坐标
|
||||
nextlatlong = currentlatlong;//下一秒坐标
|
||||
////初始化人物转向
|
||||
@@ -104,6 +119,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//Quaternion firstRotation = Quaternion.LookRotation(transform.localPosition - secondVect3d);
|
||||
//character.transform.rotation = Quaternion.Euler(0, firstRotation.eulerAngles.y, 0);
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
//骑行中
|
||||
void Run()
|
||||
{
|
||||
@@ -111,21 +127,28 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
//CamControl();
|
||||
ComputeMapData();//计算海拔&坡度&下一个点信息
|
||||
power = 300;//功率
|
||||
speed = Helper.CalculateSpeed(elevation, gradev, power, 65, 7);
|
||||
distance = Math.Round(speed / 3600, 5);
|
||||
power = 2000;//功率
|
||||
speed = Helper.CalculateSpeed(elevation, 0, power, 65, 7);
|
||||
distance = Math.Round(speed / 3600, 6);
|
||||
totalDistance += distance;
|
||||
characterAnimator.SetBool("IsRide", false);//初始化动画状态
|
||||
//characterAnimator.SetBool("IsRide", false);//初始化动画状态
|
||||
if (totalDistance <= mapData.TotalDistance)
|
||||
{
|
||||
//数据处理
|
||||
ticks++;
|
||||
nextlatlong = Along(totalDistance);//下一个坐标
|
||||
nextPos = map.GeoToWorldPosition(nextlatlong);//下一个点
|
||||
nextPos.y += 0.3f;
|
||||
prePos = transform.localPosition;//当前点
|
||||
//记录骑行数据
|
||||
var recordText = string.Format($"{ ticks },{ power.ToString(CultureInfo.InvariantCulture) },{ speed.ToString(CultureInfo.InvariantCulture) },{ Math.Round(totalDistance, 6).ToString(CultureInfo.InvariantCulture) },{ cadance.ToString(CultureInfo.InvariantCulture) },{ heartRate.ToString(CultureInfo.InvariantCulture) },{ Math.Round(nextlatlong.x, 6).ToString(CultureInfo.InvariantCulture) },{ Math.Round(nextlatlong.y, 6).ToString(CultureInfo.InvariantCulture) }");
|
||||
Debug.Log(recordText);
|
||||
sb.AppendLine(recordText);
|
||||
|
||||
//动画控制
|
||||
if (distance > 0)
|
||||
{
|
||||
characterAnimator.SetBool("IsRide", true);//开始移动动画
|
||||
nextlatlong = Along(totalDistance);//下一个坐标
|
||||
nextPos = map.GeoToWorldPosition(nextlatlong);//下一个点
|
||||
prePos = transform.localPosition;//当前点
|
||||
|
||||
StartCoroutine(LookAtNextPos());//转向
|
||||
StartCoroutine(MoveTo());//移动
|
||||
}
|
||||
@@ -137,20 +160,72 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
else
|
||||
{
|
||||
characterAnimator.SetBool("IsRide", false);
|
||||
//characterAnimator.SetBool("IsRide", false);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO:骑行结束
|
||||
void Finish()
|
||||
{
|
||||
//MapInterruptRecordApi api = new MapInterruptRecordApi();
|
||||
//上传文件
|
||||
//var path = FileHelper.GetDataDire("MapWorkoutRecords");
|
||||
//var fname = path + "/" + newFileName + ".txt";
|
||||
//var files = new List<string>();
|
||||
|
||||
//api.Add(null, null);
|
||||
MapInterruptRecordApi api = new MapInterruptRecordApi();
|
||||
|
||||
int FTP = 200;
|
||||
double NP = 0;
|
||||
string id = Guid.NewGuid().ToString();
|
||||
double IF = NP / FTP;
|
||||
|
||||
|
||||
var mapRecord = new MapInterruptRecord
|
||||
{
|
||||
Id = id,
|
||||
RouteId = 5946,
|
||||
EndDistance = totalDistance,
|
||||
RouteImage = "",
|
||||
RecordFileName = "",
|
||||
CreateTime = DateTime.Now,//骑行结束时间
|
||||
IsCompleted = true,
|
||||
TotalDistance = totalDistance,
|
||||
UserId = userId,
|
||||
Ftp = 200,
|
||||
IF = IF,
|
||||
Kj = 0,
|
||||
Tss = 0,
|
||||
NormalizedPower = Math.Round(NP, 0),
|
||||
AveragePower = 0,
|
||||
MaxPower = 0,
|
||||
Ticks = ticks,
|
||||
AverageCadence = 0,
|
||||
MaxCadence = 0,
|
||||
AverageHeartRate = 0,
|
||||
MaxHeartRate =0,
|
||||
Progress = 1,
|
||||
ContinueMark = "",
|
||||
ContinueIndex = 0,
|
||||
IsDelete = false,
|
||||
MapCompetitionId = 0,
|
||||
CurrentRouteStartDistance = 0,
|
||||
StartTime = DateTime.Now,
|
||||
WeightKg = 0,
|
||||
Weight = 0,
|
||||
BicycleWeight = 0,
|
||||
Mode = "Single",
|
||||
Param = "",
|
||||
DeviceNumber = "",
|
||||
ManufacturerId = 0,
|
||||
ManufacturerName ="",
|
||||
};
|
||||
|
||||
api.Add(mapRecord, null);
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region 工具类
|
||||
#region 工具类
|
||||
public int CurrentIndex;
|
||||
//当前距离所在的海拔/坡度/距离 下一个点的坡度以及剩余距离
|
||||
void ComputeMapData()
|
||||
{
|
||||
@@ -160,7 +235,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
for (int i = 0; i < pointList.Count; i++)
|
||||
{
|
||||
sumDistance += pointList[i].Distance;
|
||||
if (totalDistance >= sumDistance)
|
||||
if (totalDistance <= sumDistance)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
@@ -171,6 +246,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
gradev = pointList[index].Grade;
|
||||
//计算下一个点的坡度和距离
|
||||
int nextIndex = index == pointList.Count - 1 ? index : index + 1;
|
||||
CurrentIndex = nextIndex;
|
||||
nextSlope = pointList[nextIndex].Grade;
|
||||
nextSlopeDistance = sumDistance + pointList[nextIndex].Distance - totalDistance;
|
||||
}
|
||||
@@ -215,34 +291,36 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
t += Time.deltaTime;
|
||||
Vector3 v = Vector3.Lerp(prePos, nextPos, t);
|
||||
transform.localPosition = v;
|
||||
//控制海拔图的位置
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 相机控制
|
||||
[Header("CameraSettings")]
|
||||
[SerializeField]
|
||||
Camera cam;
|
||||
Vector3 previousPos = Vector3.zero;
|
||||
Vector3 deltaPos = Vector3.zero;
|
||||
//[Header("CameraSettings")]
|
||||
//[SerializeField]
|
||||
//Camera cam;
|
||||
//Vector3 previousPos = Vector3.zero;
|
||||
//Vector3 deltaPos = Vector3.zero;
|
||||
|
||||
IEnumerator CamControl()//TODO 替换成cinemachine
|
||||
{
|
||||
if (cam != null)
|
||||
{
|
||||
float t = 0;
|
||||
while (t < 1.0f)
|
||||
{
|
||||
t += Time.deltaTime / 0.5f;
|
||||
deltaPos = transform.position - previousPos;
|
||||
//deltaPos.y = 0;
|
||||
cam.transform.position = Vector3.Lerp(cam.transform.position, cam.transform.position + deltaPos, t);
|
||||
previousPos = transform.position;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
// IEnumerator CamControl()//替换成cinemachine
|
||||
//{
|
||||
// if (cam != null)
|
||||
// {
|
||||
// float t = 0;
|
||||
// while (t < 1.0f)
|
||||
// {
|
||||
// t += Time.deltaTime / 0.5f;
|
||||
// deltaPos = transform.position - previousPos;
|
||||
// //deltaPos.y = 0;
|
||||
// cam.transform.position = Vector3.Lerp(cam.transform.position, cam.transform.position + deltaPos, t);
|
||||
// previousPos = transform.position;
|
||||
// yield return null;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user