动态海拔图,全路线小地图,骑行记录上传增加截图
This commit is contained in:
1 parent
65fc5b5c50
commit
725b510748
11 files changed
+4294
-4675
No files matched your search
@@ -9,6 +9,8 @@ using DG.Tweening;
|
||||
using System;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.Collections.Generic;
|
||||
using Assets.Cyp.Common;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
@@ -57,7 +59,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
[SerializeField]
|
||||
Text mapName;//路书名称
|
||||
[SerializeField] LineChart elevationChart;//海拔图
|
||||
[SerializeField] Image img;//当前用户头像
|
||||
[SerializeField] RawImage img;//当前用户头像
|
||||
[SerializeField]
|
||||
Button StartOrPauseButton;//暂停按钮
|
||||
[SerializeField]
|
||||
@@ -66,6 +68,9 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
Button DeviceButton;//设备按钮
|
||||
[SerializeField]
|
||||
Button ExitButton;//退出按钮
|
||||
|
||||
[SerializeField]
|
||||
GameObject target;//开始按钮
|
||||
#endregion
|
||||
|
||||
#region 控制器
|
||||
@@ -86,8 +91,6 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
SettingButton.onClick.AddListener(ShowSettingPanel);
|
||||
DeviceButton.onClick.AddListener(ShowDevicePanel);
|
||||
ExitButton.onClick.AddListener(StopRide);
|
||||
|
||||
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
@@ -97,6 +100,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
mapName.text = route.RouteInstance.Name;
|
||||
totalDistance.text = "/" + Math.Round(mainController.GetMapData().TotalDistance, 2).ToString() + "KM";
|
||||
RenderChart();
|
||||
startIndex = playerController.CurrentIndex;
|
||||
}
|
||||
// Update is called once per frame
|
||||
float tt = 1f;
|
||||
@@ -139,15 +143,20 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
currentSlopeText.text = Math.Round(playerController.CurrentSlope, 1).ToString() + "%";
|
||||
currentSlopeDistanceText.text = Math.Round(playerController.CurrentSlopeDistance, 0).ToString() + "M";
|
||||
//移动海拔图头像 TODO:移动所有人的头像
|
||||
MoveChartMarkPoint();
|
||||
UpdateRealTimeChart();
|
||||
//MoveChartMarkPoint();
|
||||
}
|
||||
}
|
||||
|
||||
//根据不同的骑行模式渲染不同的UI界面
|
||||
void InitUI(CyclingModel cyclingModel)
|
||||
private void LateUpdate()
|
||||
{
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
target.transform.position = playerController.transform.position; //new Vector3((float)Math.Round(player.transform.position.x,1), 0, (float)Math.Round(player.transform.position.z,1));
|
||||
target.transform.rotation = new Quaternion(playerController.transform.rotation.x, playerController.transform.rotation.y + 180, playerController.transform.rotation.z, playerController.transform.rotation.w);
|
||||
}
|
||||
}
|
||||
|
||||
private void StartRide()
|
||||
{
|
||||
//加个5秒钟倒计时
|
||||
@@ -188,25 +197,79 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
isSimple *= -1;
|
||||
}
|
||||
|
||||
|
||||
private int maxCacheDataNumber = 100;//海拔图最大点数
|
||||
private int totalCount;//路线实际点数
|
||||
private int startIndex;//选中玩家起始索引
|
||||
private int interval = 50;//选中玩家移动索引个数
|
||||
private float[] elevationList;
|
||||
//初始化海拔图
|
||||
void RenderChart()
|
||||
{
|
||||
elevationChart.ClearData();
|
||||
var elevationArr = mainController.GetLineChartData();
|
||||
foreach (var elevation in elevationArr)
|
||||
elevationList = mainController.GetLineChartData();
|
||||
totalCount = elevationList.Length;
|
||||
maxCacheDataNumber = Math.Min(totalCount, maxCacheDataNumber);
|
||||
elevationChart.SetMaxCache(maxCacheDataNumber);
|
||||
//for (int i = 0; i < maxCacheDataNumber; i++)
|
||||
//{
|
||||
// elevationChart.AddData(0, elevationList[i]);
|
||||
//}
|
||||
//elevationChart.RefreshChart();
|
||||
|
||||
var endIndex = playerController.CurrentIndex;
|
||||
var s = endIndex / maxCacheDataNumber;
|
||||
var v = endIndex % maxCacheDataNumber;
|
||||
|
||||
maxCacheDataNumber = Math.Min(totalCount-s* maxCacheDataNumber, maxCacheDataNumber);
|
||||
|
||||
for (int i = 0; i < maxCacheDataNumber; i++)
|
||||
{
|
||||
elevationChart.AddData(0, elevation);
|
||||
initCount++;
|
||||
if (initCount > maxCacheDataNumber) break;
|
||||
AddOneData(s * maxCacheDataNumber + v + i);
|
||||
}
|
||||
|
||||
elevationChart.RefreshChart();
|
||||
Utils.DisplayImage(StartCoroutine, img, App.CurrentUser.WxHeadImg);
|
||||
}
|
||||
//长路线动态更新chart
|
||||
private int initCount;
|
||||
private float updateTime;
|
||||
private int lastIndex;
|
||||
private int chartAddNum;
|
||||
void UpdateRealTimeChart()
|
||||
{
|
||||
var endIndex = playerController.CurrentIndex;
|
||||
updateTime += Time.deltaTime;
|
||||
if (updateTime >= 1)
|
||||
{
|
||||
int delta = endIndex - lastIndex;
|
||||
if (delta >0 && initCount < totalCount)
|
||||
{
|
||||
lastIndex = endIndex;
|
||||
AddOneData(initCount);
|
||||
initCount++;
|
||||
updateTime = 0;
|
||||
chartAddNum++;
|
||||
}
|
||||
var v = (endIndex - chartAddNum) % maxCacheDataNumber;
|
||||
MoveChartMarkPoint(v);
|
||||
}
|
||||
}
|
||||
void AddOneData(int index)
|
||||
{
|
||||
elevationChart.AddData(0, elevationList[index]);
|
||||
//elevationChart.AddXAxisData(index.ToString(), index);
|
||||
|
||||
}
|
||||
|
||||
void MoveChartMarkPoint()
|
||||
void MoveChartMarkPoint(int index)
|
||||
{
|
||||
var dataPoints = elevationChart.series.list[0].dataPoints.OrderBy(c=>c.x).ToList();
|
||||
if (dataPoints.Count > 0)
|
||||
{
|
||||
var pinLoction = dataPoints[playerController.CurrentIndex];
|
||||
pinLoction.y += 10;
|
||||
var pinLoction = dataPoints[index];
|
||||
pinLoction.y = img.transform.localPosition.y;
|
||||
img.transform.localPosition = pinLoction;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user