海拔图和小地图
This commit is contained in:
1 parent
45801dff22
commit
c5bd9daba2
521 files changed
+1985033
-439
No files matched your search
@@ -1,11 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class Helper
|
||||
{
|
||||
public static string GetDataDire(string dirName = "")
|
||||
{
|
||||
|
||||
//var parentPath = System.IO.Directory.GetParent(Environment.CurrentDirectory).FullName;
|
||||
var parentPath = " ";//TODO
|
||||
var path = Path.Combine(parentPath, "PowerFunData", dirName);
|
||||
if (!System.IO.Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public static string FormatTicks(int seconds)
|
||||
{
|
||||
int h, m, s;
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using Assets.Scripts.Apis;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using XCharts;
|
||||
|
||||
public class MainController : MonoBehaviour
|
||||
{
|
||||
@@ -11,6 +14,7 @@ public class MainController : MonoBehaviour
|
||||
private int currentUserId;//当前选中的用户id
|
||||
private bool isStart;//当前游戏是否开始
|
||||
private string gameType;//当前骑行模式
|
||||
private DateTime startTime;//开始时间
|
||||
|
||||
public MapDataModel GetMapData()
|
||||
{
|
||||
@@ -52,5 +56,12 @@ public class MainController : MonoBehaviour
|
||||
string json = "{'Type':'LineString','TotalDistance':19.17906,'List':[{'Point':[26.092100000000002,119.33686000000002],'Elevation':7.6198},{'Point':[26.09211,119.33749000000002],'Elevation':7.5859},{'Point':[26.092170000000003,119.33840000000001],'Elevation':7.421},{'Point':[26.092260000000003,119.33921000000001],'Elevation':7.3133},{'Point':[26.092270002098761,119.33999000005943],'Elevation':7.2394},{'Point':[26.092280000000002,119.34077],'Elevation':7.2701},{'Point':[26.092240000956789,119.34129500009136],'Elevation':7.3416},{'Point':[26.092200000000002,119.34182000000001],'Elevation':7.4177},{'Point':[26.092083338752424,119.34270666844074],'Elevation':7.5033},{'Point':[26.09196667208499,119.34359333511317],'Elevation':7.2596},{'Point':[26.09185,119.34448],'Elevation':6.8727},{'Point':[26.091680000000004,119.34505000000001],'Elevation':6.4546},{'Point':[26.091536672044878,119.34593333550309],'Elevation':6.0312},{'Point':[26.091393338710645,119.34681666884185],'Elevation':5.751},{'Point':[26.091250000000002,119.3477],'Elevation':5.6373},{'Point':[26.091230000000003,119.34794000000001],'Elevation':5.6052},{'Point':[26.091225001411136,119.3485800001182],'Elevation':5.5997},{'Point':[26.091220000000003,119.34922000000002],'Elevation':5.6907},{'Point':[26.091330000000003,119.34997000000001],'Elevation':6.0231},{'Point':[26.091440000000002,119.35021],'Elevation':6.4916},{'Point':[26.09157,119.35095000000001],'Elevation':7.0092},{'Point':[26.091600000000003,119.3516],'Elevation':7.3641},{'Point':[26.091767507390937,119.35244499640774],'Elevation':7.4909},{'Point':[26.091935009859512,119.353289995235],'Elevation':6.9736},{'Point':[26.092102507405667,119.35413499648182],'Elevation':6.7797},{'Point':[26.092270000000003,119.35498000000001],'Elevation':6.5711},{'Point':[26.092405001867032,119.35571999903352],'Elevation':6.4206},{'Point':[26.092540000000003,119.35646000000001],'Elevation':6.3653},{'Point':[26.09269,119.35732000000002],'Elevation':7.251},{'Point':[26.092710000000004,119.35761000000001],'Elevation':8.2263},{'Point':[26.092703339253426,119.35853666675888],'Elevation':9.8464},{'Point':[26.092696672586847,119.35946333341218],'Elevation':11.8545},{'Point':[26.09269,119.36039000000001],'Elevation':13.6159},{'Point':[26.092665001414368,119.36103000007358],'Elevation':15.1102},{'Point':[26.092640000000003,119.36167],'Elevation':16.3984},{'Point':[26.0925,119.36225],'Elevation':17.1179},{'Point':[26.092270000000003,119.36289000000001],'Elevation':17.3805},{'Point':[26.092200000000002,119.36334000000001],'Elevation':17.3022},{'Point':[26.092180000000003,119.36363000000001],'Elevation':17.2282},{'Point':[26.092190000000002,119.36396],'Elevation':17.2224},{'Point':[26.092290000000002,119.36435000000002],'Elevation':17.1729},{'Point':[26.092100000000002,119.36453000000002],'Elevation':17.1065},{'Point':[26.092000000000002,119.36473000000001],'Elevation':17.0503},{'Point':[26.091910000000002,119.36502000000002],'Elevation':17.1392},{'Point':[26.09193,119.36525],'Elevation':17.2636},{'Point':[26.092150000000004,119.36569000000001],'Elevation':17.4486},{'Point':[26.09233,119.36581000000001],'Elevation':17.7034},{'Point':[26.092540000000003,119.36588],'Elevation':18.1077},{'Point':[26.092750000000002,119.36589000000001],'Elevation':18.5083},{'Point':[26.092950000000002,119.36582000000001],'Elevation':18.892},{'Point':[26.093110000000003,119.36572000000001],'Elevation':19.2643},{'Point':[26.09335,119.36544],'Elevation':19.6256},{'Point':[26.094033333311039,119.36542333352864],'Elevation':20.1707},{'Point':[26.094716666620165,119.36540666686258],'Elevation':21.2487},{'Point':[26.0954,119.36539],'Elevation':22.396},{'Point':[26.09605,119.36548],'Elevation':23.9715},{'Point':[26.09615,119.36567000000001],'Elevation':25.3392},{'Point':[26.096753333417059,119.36562333380944],'Elevation':26.626},{'Point':[26.097356666819095,119.36557666713746],'Elevation':28.1709},{'Point':[26.09796,119.36553],'Elevation':30.077},{'Point':[26.098260000000003,119.36556000000002],'Elevation':32.1094},{'Point':[26.09888000013564,119.36572999910875],'Elevation':34.3101},{'Point':[26.099500000000003,119.36590000000001],'Elevation':36.7362},{'Point':[26.099970000000003,119.36599000000001],'Elevation':39.7763},{'Point':[26.100720000000003,119.36591000000001],'Elevation':43.1691},{'Point':[26.101160000000004,119.36591000000001],'Elevation':46.6581},{'Point':[26.10181,119.36598000000001],'Elevation':50.4232},{'Point':[26.10208,119.36621000000001],'Elevation':53.9898},{'Point':[26.102210000000003,119.36674000000001],'Elevation':57.5845},{'Point':[26.101960000000002,119.36725000000001],'Elevation':61.2459},{'Point':[26.101530000000004,119.36721000000001],'Elevation':64.7154},{'Point':[26.100900000000003,119.36697000000001],'Elevation':68.1881},{'Point':[26.100415000136522,119.36697500001934],'Elevation':71.7923},{'Point':[26.09993,119.36698000000001],'Elevation':75.4172},{'Point':[26.099330000000002,119.36702000000001],'Elevation':79.066},{'Poin
Line truncated
|
||||
return Newtonsoft.Json.JsonConvert.DeserializeObject<MapDataModel>(json);
|
||||
}
|
||||
/// <summary>
|
||||
/// 海拔图数据
|
||||
/// </summary>
|
||||
public float[] GetLineChartData()
|
||||
{
|
||||
return mapData.List.Select(c => (float) c.Elevation ).ToArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Mapbox.Utils;
|
||||
using System.Collections;
|
||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||
using Mapbox.Unity.MeshGeneration.Data;
|
||||
using Mapbox.Unity.Utilities;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
@@ -13,9 +14,8 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
[SerializeField]
|
||||
AbstractMap _map;
|
||||
|
||||
[SerializeField]
|
||||
MeshModifier[] MeshModifiers;
|
||||
MeshModifier SnapModifier;
|
||||
[SerializeField]
|
||||
Material _material;
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
private int _counter;
|
||||
|
||||
GameObject _directionsGO;
|
||||
GameObject _mipMapRoute;
|
||||
MainController mainCotroller;
|
||||
|
||||
protected virtual void Awake()
|
||||
@@ -36,16 +37,12 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
_map.OnInitialized += CreateRoute;
|
||||
_map.OnUpdated += CreateRoute;
|
||||
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
mainCotroller = transform.parent.GetComponent<MainController>();
|
||||
foreach (var modifier in MeshModifiers)
|
||||
{
|
||||
modifier.Initialize();
|
||||
}
|
||||
|
||||
StartCoroutine(QueryTimer());
|
||||
}
|
||||
|
||||
@@ -65,60 +62,86 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
void CreateRoute()
|
||||
{
|
||||
var meshData = new MeshData();
|
||||
var dat = new List<Vector3>();
|
||||
|
||||
var mapData = mainCotroller.GetMapData();
|
||||
if (mapData != null)
|
||||
UnityTile tile;
|
||||
bool foundTile = _map.MapVisualizer.ActiveTiles.TryGetValue(Conversions.LatitudeLongitudeToTileId(_map.CenterLatitudeLongitude.x, _map.CenterLatitudeLongitude.y, (int)_map.Zoom), out tile);
|
||||
if (foundTile)
|
||||
{
|
||||
foreach (var mapDataItem in mapData.List)
|
||||
{
|
||||
var point = mapDataItem.Point;
|
||||
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
|
||||
item.y += 0.2f;
|
||||
dat.Add(item);
|
||||
}
|
||||
var feat = new VectorFeatureUnity();
|
||||
feat.Points.Add(dat);
|
||||
foreach (MeshModifier mod in MeshModifiers.Where(x => x.Active))
|
||||
{
|
||||
mod.Run(feat, meshData, _map.WorldRelativeScale * 8);
|
||||
var meshData = new MeshData();
|
||||
var dat = new List<Vector3>();
|
||||
|
||||
var mapData = mainCotroller.GetMapData();
|
||||
if (mapData != null)
|
||||
{
|
||||
foreach (var mapDataItem in mapData.List)
|
||||
{
|
||||
var point = mapDataItem.Point;
|
||||
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
|
||||
item.y += 0.3f;
|
||||
dat.Add(item);
|
||||
}
|
||||
var feat = new VectorFeatureUnity();
|
||||
feat.Points.Add(dat);
|
||||
//处理海拔高度的问题
|
||||
SnapModifier.Run(feat, meshData, tile);
|
||||
CreatMapRoute(feat);//创建路线
|
||||
CreateMiniMapRoute(feat);//创建小地图路线
|
||||
}
|
||||
CreateGameObject(meshData);
|
||||
}
|
||||
}
|
||||
|
||||
GameObject CreateGameObject(MeshData data)
|
||||
void CreatMapRoute(VectorFeatureUnity feat)
|
||||
{
|
||||
if (_directionsGO != null)
|
||||
{
|
||||
_directionsGO.Destroy();
|
||||
}
|
||||
_directionsGO = new GameObject("MapRoute");
|
||||
var mesh = _directionsGO.AddComponent<MeshFilter>().mesh;
|
||||
mesh.subMeshCount = data.Triangles.Count;
|
||||
var lineRender = _directionsGO.AddComponent<LineRenderer>();
|
||||
lineRender.material = new Material(Shader.Find("Sprites/Default"));
|
||||
var dat = feat.Points[0];
|
||||
ColorUtility.TryParseHtmlString("#FF2742", out Color c);
|
||||
lineRender.endColor = c;
|
||||
lineRender.startColor = c;
|
||||
//设置宽度
|
||||
lineRender.SetWidth(0.8f, 0.8f);
|
||||
lineRender.SetVertexCount(dat.Count);
|
||||
lineRender.SetPositions(feat.Points[0].ToArray());
|
||||
//lineRender.numCapVertices = 90;
|
||||
float alpha = 1.0f;
|
||||
//Gradient gradient = new Gradient();
|
||||
//gradient.SetKeys(
|
||||
// new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f) },
|
||||
// new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) }
|
||||
//);
|
||||
//lineRender.colorGradient = gradient;
|
||||
lineRender.numCornerVertices = 90;
|
||||
|
||||
mesh.SetVertices(data.Vertices);
|
||||
_counter = data.Triangles.Count;
|
||||
for (int i = 0; i < _counter; i++)
|
||||
}
|
||||
void CreateMiniMapRoute(VectorFeatureUnity feat)
|
||||
{
|
||||
if (_mipMapRoute != null)
|
||||
{
|
||||
var triangle = data.Triangles[i];
|
||||
mesh.SetTriangles(triangle, i);
|
||||
_mipMapRoute.Destroy();
|
||||
}
|
||||
|
||||
_counter = data.UV.Count;
|
||||
for (int i = 0; i < _counter; i++)
|
||||
{
|
||||
var uv = data.UV[i];
|
||||
mesh.SetUVs(i, uv);
|
||||
}
|
||||
|
||||
mesh.RecalculateNormals();
|
||||
_directionsGO.AddComponent<MeshRenderer>().material = _material;
|
||||
|
||||
return _directionsGO;
|
||||
_mipMapRoute = new GameObject("MiniMapRoute");
|
||||
var lineRender = _mipMapRoute.AddComponent<LineRenderer>();
|
||||
lineRender.material = new Material(Shader.Find("Sprites/Default"));
|
||||
var dat = feat.Points[0];
|
||||
lineRender.endColor = Color.red;
|
||||
lineRender.startColor = Color.blue;
|
||||
//设置宽度
|
||||
lineRender.SetWidth(3f, 3f);
|
||||
lineRender.SetVertexCount(dat.Count);
|
||||
lineRender.SetPositions(feat.Points[0].ToArray());
|
||||
lineRender.numCapVertices = 90;
|
||||
float alpha = 1.0f;
|
||||
Gradient gradient = new Gradient();
|
||||
gradient.SetKeys(
|
||||
new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f) },
|
||||
new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) }
|
||||
);
|
||||
lineRender.colorGradient = gradient;
|
||||
lineRender.numCornerVertices = 90;
|
||||
_mipMapRoute.layer = 9;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using XCharts;
|
||||
using XUGL;
|
||||
using System.Linq;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
@@ -21,18 +24,28 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
[SerializeField]
|
||||
Text countDownTxt;
|
||||
|
||||
[SerializeField]
|
||||
LineChart elevationChart;
|
||||
|
||||
PlayerController playerController;
|
||||
MainController mainController;
|
||||
private float timeRemaining = 1f;
|
||||
private int count = 0;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
startBtn.onClick.AddListener(StartRide);
|
||||
playerController = transform.parent.Find("Player").GetComponent<PlayerController>();
|
||||
mainController = FindObjectOfType<MainController>();
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
startBtn.onClick.AddListener(StartRide);
|
||||
RenderChart();
|
||||
}
|
||||
|
||||
private void StartRide()
|
||||
{
|
||||
playerController = transform.parent.Find("Player").GetComponent<PlayerController>();
|
||||
//加个5秒钟倒计时
|
||||
count = 5;
|
||||
startBtn.gameObject.SetActive(false);
|
||||
@@ -41,7 +54,6 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
@@ -59,14 +71,34 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
count--;
|
||||
if (count == 0)
|
||||
{
|
||||
playerController.SetStart(true);
|
||||
playerController.SetStart();
|
||||
countDownTxt.gameObject.SetActive(false);
|
||||
}
|
||||
timeRemaining = 1.0f;
|
||||
}
|
||||
}
|
||||
countDownTxt.text = count.ToString();
|
||||
|
||||
UpdateChartMarkPoint();
|
||||
}
|
||||
}
|
||||
|
||||
void RenderChart()
|
||||
{
|
||||
elevationChart.ClearData();
|
||||
var elevationArr = mainController.GetLineChartData();
|
||||
foreach (var elevation in elevationArr)
|
||||
{
|
||||
elevationChart.AddData(0, elevation);
|
||||
}
|
||||
}
|
||||
VertexHelper Vh;
|
||||
[SerializeField] Image img;
|
||||
void UpdateChartMarkPoint()
|
||||
{
|
||||
var dataPoints = elevationChart.series.list[0].dataPoints;
|
||||
var pinLoction = dataPoints[playerController.CurrentIndex];
|
||||
img.transform.localPosition = pinLoction;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user