骑行数据逻辑调整
This commit is contained in:
1 parent
8226b8a7c2
commit
00b9c7e796
15 files changed
+4173
-21344
No files matched your search
+3342
-21273
File diff suppressed because it is too large.
Load diff
@@ -110,6 +110,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
timer = 1.0f;
|
||||
}
|
||||
}
|
||||
public bool stopRecord = false;
|
||||
//骑行中
|
||||
protected virtual void Run()
|
||||
{
|
||||
@@ -146,13 +147,14 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
distance = totalDistance - mapData.TotalDistance;
|
||||
totalDistance = mapData.TotalDistance;
|
||||
stopRecord = true;
|
||||
StartCoroutine("LateUpload");
|
||||
}
|
||||
|
||||
//数据处理
|
||||
currentlatlong = Along(totalDistance);//下一个坐标
|
||||
|
||||
nextPos = map.GeoToWorldPosition(currentlatlong);//下一个点
|
||||
nextPos.y += 0.6f;//提高y轴让人物站在地图上面
|
||||
nextPos.y += 1f;//提高y轴让人物站在地图上面
|
||||
prePos = transform.localPosition;//当前点
|
||||
thisRotation = transform.localRotation;
|
||||
//移动动画控制
|
||||
@@ -169,10 +171,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//计算功率 速度 当前骑行总里程(M)心率 踏频 等
|
||||
protected virtual void Compute()
|
||||
{
|
||||
//power = 900;//功率
|
||||
//speed = Helper.CalculateSpeed(elevation, 0, power, 65, 7);
|
||||
//distance = Math.Round(speed / 3600, 6);
|
||||
//totalDistance += distance;
|
||||
|
||||
}
|
||||
//当前用户调用来上传骑行记录
|
||||
public virtual void Upload()
|
||||
@@ -224,24 +223,12 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
nextSlope = pointList[nextIndex].Grade;
|
||||
nextSlopeDistance = sumDistance - totalDistance * 1000;
|
||||
NextSlopeTotalDistance = pointList[nextIndex].Distance;
|
||||
currentSlopeDistance = totalDistance * 1000 - (sumDistance - pointList[index].Distance);
|
||||
currentSlopeDistance = CurrentDistance-( totalDistance * 1000 - (sumDistance - pointList[index].Distance));
|
||||
|
||||
}
|
||||
public double PreElevation;
|
||||
public double PreSlope;
|
||||
//根据距离计算坐标
|
||||
Vector2d Along(double endDistance)
|
||||
{
|
||||
if (mapData != null)
|
||||
{
|
||||
var list = mapData.List.Select(p => new GeoJSON.Net.Geometry.GeographicPosition(p.Point[0], p.Point[1]));
|
||||
LineString lineString = new LineString(list);
|
||||
var pt1 = Turf.Along(lineString, endDistance);
|
||||
var ll = ((GeographicPosition)((GeoJSON.Net.Geometry.Point)pt1.Geometry).Coordinates);
|
||||
return new Vector2d(ll.Latitude, ll.Longitude);
|
||||
}
|
||||
return currentlatlong;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 人物移动与转向控制
|
||||
|
||||
@@ -82,6 +82,10 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
{
|
||||
UIManager.AddEvent(sender, eventType, unityAction);
|
||||
}
|
||||
public void ShowDevice(PFUIPanel pFUIPanel)
|
||||
{
|
||||
UIManager.Show(UIManager.Instance.DevicePanel, pFUIPanel);
|
||||
}
|
||||
|
||||
public Texture GetCountryImageByCode(string code)
|
||||
{
|
||||
@@ -287,10 +291,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
var rs = resultPanel.GetComponent<ResultPanelScript>();
|
||||
rs.InjectController(this);
|
||||
rs.SetDataSource(cyclingController.recorderData);
|
||||
#if !UNITY_EDITOR
|
||||
cyclingController.recorderData.SaveData(cyclingModel, selectParamModel, imageFileName);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
protected string CaptureCamera(Camera camera, Rect rect)
|
||||
|
||||
@@ -41,13 +41,15 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
Transform mapRanking;
|
||||
Slider slider;
|
||||
#endregion
|
||||
|
||||
GameObject loadingPanel;
|
||||
#region 属性
|
||||
float process = 0;//0-100 %
|
||||
#endregion
|
||||
CyclingController cyclingController;
|
||||
private void Start()
|
||||
{
|
||||
loadingPanel = transform.Find("Panel/LoadingPanel").gameObject;
|
||||
loadingPanel.showLoadingExtension();
|
||||
//InitGameObject();
|
||||
}
|
||||
public void InjectController(CyclingController controller)
|
||||
@@ -163,9 +165,21 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
void StartRide(BaseEventData baseEvent)
|
||||
{
|
||||
//启用ridenow
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
depressFlag = true;
|
||||
var checkAnt = cyclingController.CheckAnt();
|
||||
#if UNITY_EDITOR
|
||||
checkAnt = true;
|
||||
#endif
|
||||
if (!checkAnt)
|
||||
{
|
||||
var alert = (GameObject)Instantiate(Resources.Load("UI/Prefab/Ride/Alert"), panel.transform);
|
||||
alert.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
//启用ridenow
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
depressFlag = true;
|
||||
}
|
||||
}
|
||||
void Cancel(BaseEventData baseEvent)
|
||||
{
|
||||
@@ -194,6 +208,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
mapCountry.texture = cyclingController.GetCountryImageByName(userList[0].Country);//路书国家
|
||||
|
||||
Utils.DisplayImage(StartCoroutine, altitudeGraph, route.AltitudeGraph);//海拔图
|
||||
loadingPanel.SetActive(false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class NoDeviceScript: MonoBehaviour
|
||||
{
|
||||
Button cancelButton;
|
||||
Button confirmButton;
|
||||
CyclingController cyclingController;
|
||||
private void Start()
|
||||
{
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
cancelButton = transform.Find("CloseButton").GetComponent<Button>();
|
||||
confirmButton = transform.Find("SaveButton").GetComponent<Button>();
|
||||
UIManager.AddEvent(cancelButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, Cancel);
|
||||
UIManager.AddEvent(confirmButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, Confirm);
|
||||
}
|
||||
private void Cancel(BaseEventData baseEventData)
|
||||
{
|
||||
transform.gameObject.SetActive(false);
|
||||
}
|
||||
private void Confirm(BaseEventData baseEventData)
|
||||
{
|
||||
transform.gameObject.SetActive(false);
|
||||
var pFUIPanel = transform.parent.GetComponent<PFUIPanel>();
|
||||
cyclingController.ShowDevice(pFUIPanel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48e8de0b3f98fd343baced2ca18f9305
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -28,7 +28,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
var temp = Math.Round(value, digit);
|
||||
//向Text组件赋值
|
||||
text.text = string.Format(format, temp);
|
||||
}, mOldScore, newScore, 0.4f));
|
||||
}, mOldScore, newScore, 1f));
|
||||
//将更新后的值记录下来, 用于下一次滚动动画
|
||||
mOldScore = newScore;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
distance = data._Speed / 3600;
|
||||
totalDistance = data._Distance;
|
||||
}
|
||||
currentlatlong = mainController.Along(totalDistance);//下一个坐标
|
||||
var diff = Math.Round(totalDistance - _playerController.TotalDistance, 3) * 1000;
|
||||
_reviewItemScript.SetDistance(diff);
|
||||
}
|
||||
|
||||
@@ -33,30 +33,34 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
weight = App.CurrentUser.Weight;
|
||||
bicycleWeight = App.CurrentUser.BicycleWeight;
|
||||
//#if UNITY_EDITOR
|
||||
power = 1000;//测试功率
|
||||
power = 300;//测试功率
|
||||
//#endif
|
||||
mainController.TrackResistance(currentSlope);//TODO
|
||||
speed = Helper.CalculateSpeed(elevation, currentSlope, power, weight, bicycleWeight);
|
||||
distance = mainController.UpdateDistance(speed);
|
||||
totalDistance += distance;
|
||||
//记录骑行数据
|
||||
if (!stopRecord)
|
||||
{
|
||||
//记录骑行数据
|
||||
currentlatlong = mainController.Along(totalDistance);//下一个坐标
|
||||
var recorderData = mainController.cyclingController.recorderData;
|
||||
targetData = new TargetData
|
||||
{
|
||||
Ticks = ticks,
|
||||
_Power = power,
|
||||
_Speed = speed,
|
||||
_Distance = totalDistance > mapData.TotalDistance ? mapData.TotalDistance : totalDistance,
|
||||
_Cadence = cadance,
|
||||
_HeartRate = heartRate,
|
||||
_Lat = currentlatlong.x,
|
||||
_Lon = currentlatlong.y,
|
||||
_TotalClimb = totalClimb,
|
||||
};
|
||||
|
||||
var recorderData = mainController.cyclingController.recorderData;
|
||||
targetData = new TargetData
|
||||
{
|
||||
Ticks = ticks,
|
||||
_Power = power,
|
||||
_Speed = speed,
|
||||
_Distance = totalDistance > mapData.TotalDistance ? mapData.TotalDistance : totalDistance,
|
||||
_Cadence = cadance,
|
||||
_HeartRate = heartRate,
|
||||
_Lat = currentlatlong.x,
|
||||
_Lon = currentlatlong.y,
|
||||
_TotalClimb = totalClimb,
|
||||
};
|
||||
recorderData.RiderDatas.Add(targetData);
|
||||
recorderData.RiderDatas.Add(targetData);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
protected override void SendTcp()
|
||||
{
|
||||
if (mainController.cyclingController != null)
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
// dat.Add(item);
|
||||
//}
|
||||
//前后取50个点
|
||||
decimal diff = i - playerController.CurrentIndex+1;
|
||||
decimal diff = i - playerController.CurrentIndex;
|
||||
decimal diffAbs = Math.Abs(diff);
|
||||
if (diffAbs <= 200)
|
||||
{
|
||||
|
||||
@@ -87,6 +87,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
Button alertBtn;
|
||||
Button alertCloseBtn;
|
||||
Text preSlopeText;
|
||||
GameObject startPanel;
|
||||
void Awake()
|
||||
{
|
||||
#region 控件获取与事件绑定
|
||||
@@ -95,7 +96,8 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
map = transform.parent.Find("Map").GetComponent<AbstractMap>();
|
||||
leftPanel = transform.Find("Panel/ReviewPanel").gameObject;
|
||||
nearByPanel = transform.Find("Panel/NearPanel").gameObject;
|
||||
startBtn = transform.Find("Panel/StartButton").GetComponent<Button>();
|
||||
startPanel = transform.Find("Panel/StartPanel").gameObject;
|
||||
startBtn = transform.Find("Panel/StartPanel/StartButton").GetComponent<Button>();
|
||||
simpleBtn = transform.Find("Panel/SimpleButton").GetComponent<Button>();
|
||||
ditance = transform.Find("Panel/ComputerPanel/DistanceView/Distance").GetComponent<Text>();
|
||||
titlePanel = transform.Find("Panel/TitlePanel").gameObject;
|
||||
@@ -115,19 +117,13 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
countDownTxt = transform.Find("Panel/CountDown").GetComponent<Text>();
|
||||
mapName = transform.Find("Panel/TitlePanel/MapName").GetComponent<Text>();
|
||||
totalClimb = transform.Find("Panel/ComputerPanel/TotalClimbView/TotalClimb").GetComponent<Text>();
|
||||
elevationChart = transform.Find("Panel/ElevationChart").GetComponent<LineChart>();
|
||||
//img = transform.Find("Panel/ElevationChart/HeadImage").GetComponent<RawImage>();
|
||||
img = transform.Find("Panel/GraphChart/Head").GetComponent<RawImage>();
|
||||
t = transform.Find("Panel/GraphChart/Button");
|
||||
miniMap = transform.Find("Panel/MiniMap").GetComponent<RawImage>();
|
||||
|
||||
alertPanel = transform.Find("Panel/Alert").gameObject;
|
||||
alertBtn = transform.Find("Panel/Alert/SaveButton").GetComponent<Button>();
|
||||
alertCloseBtn = transform.Find("Panel/Alert/CloseButton").GetComponent<Button>();
|
||||
UIManager.AddEvent(alertBtn.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, AlertOk);
|
||||
UIManager.AddEvent(alertCloseBtn.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, AlertClose);
|
||||
|
||||
|
||||
|
||||
selectPanel = transform.Find("Panel/SelectPanel").gameObject;
|
||||
selectPlayer = transform.Find("Panel/SelectPlayer").gameObject;
|
||||
reviewPanel = transform.Find("Panel/ReviewPanel").gameObject;
|
||||
@@ -349,35 +345,32 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
selectPlayer.SetActive(true);
|
||||
}
|
||||
public void AlertOk(BaseEventData baseEventData)
|
||||
{
|
||||
alertPanel.SetActive(false);
|
||||
UIManager.Show(UIManager.Instance.DevicePanel, transform.Find("Panel").GetComponent<PFUIPanel>());
|
||||
}
|
||||
public void AlertClose(BaseEventData baseEventData)
|
||||
{
|
||||
alertPanel.SetActive(false);
|
||||
}
|
||||
|
||||
public void StartRide(BaseEventData baseEventData)
|
||||
{
|
||||
var antConnected = mainController.CheckAnt();//初始化ant+设备
|
||||
#if !UNITY_EDITOR
|
||||
#if UNITY_EDITOR
|
||||
antConnected = true;
|
||||
#endif
|
||||
if (!antConnected)
|
||||
{
|
||||
alertPanel.SetActive(true);
|
||||
}
|
||||
#endif
|
||||
//加个5秒钟倒计时
|
||||
count = 5;
|
||||
startBtn.gameObject.SetActive(false);
|
||||
countDownTxt.gameObject.SetActive(true);
|
||||
countDownTxt.text = count.ToString();
|
||||
else {
|
||||
//加个5秒钟倒计时
|
||||
count = 5;
|
||||
startPanel.SetActive(false);
|
||||
startBtn.gameObject.SetActive(false);
|
||||
countDownTxt.gameObject.SetActive(true);
|
||||
countDownTxt.text = count.ToString();
|
||||
}
|
||||
}
|
||||
//暂停游戏
|
||||
private void PauseRide(BaseEventData baseEventData)
|
||||
{
|
||||
mainController.SetPause();
|
||||
startBtn.gameObject.SetActive(true);
|
||||
startPanel.SetActive(true);
|
||||
}
|
||||
private void SaveRide(BaseEventData baseEventData)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user