动态海拔图,全路线小地图,骑行记录上传增加截图
This commit is contained in:
parent
65fc5b5c50
commit
725b510748
File diff suppressed because it is too large
Load Diff
@ -21,11 +21,13 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
GameObject character;
|
GameObject character;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Animator characterAnimator;
|
Animator characterAnimator;
|
||||||
|
[SerializeField]
|
||||||
AbstractMap map;
|
AbstractMap map;
|
||||||
|
//AbstractMap map;
|
||||||
|
|
||||||
#region 动画控制参数
|
#region 动画控制参数
|
||||||
Vector3 nextPos;
|
Vector3 nextPos;
|
||||||
Vector3 prePos;
|
Vector3 prePos = Vector3.zero;
|
||||||
float timer = 1.0f;//计时器
|
float timer = 1.0f;//计时器
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -104,11 +106,11 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
Excute();
|
||||||
}
|
}
|
||||||
private void FixedUpdate()
|
private void FixedUpdate()
|
||||||
{
|
{
|
||||||
Excute();
|
|
||||||
}
|
}
|
||||||
#region 骑行逻辑
|
#region 骑行逻辑
|
||||||
//初始化骑行数据
|
//初始化骑行数据
|
||||||
@ -118,7 +120,7 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
{
|
{
|
||||||
characterAnimator = GetComponentInChildren<Animator>();
|
characterAnimator = GetComponentInChildren<Animator>();
|
||||||
mainController = transform.parent.GetComponent<CyclingController>();
|
mainController = transform.parent.GetComponent<CyclingController>();
|
||||||
map = FindObjectOfType<AbstractMap>();
|
//map = FindObjectOfType<AbstractMap>();
|
||||||
mapData = mainController.GetMapData();//获取路书信息
|
mapData = mainController.GetMapData();//获取路书信息
|
||||||
nextlatlong = new Vector2d(mapData.List[0].Point[0], mapData.List[0].Point[1]);//初始化人物位置 TODO加上之前骑行距离
|
nextlatlong = new Vector2d(mapData.List[0].Point[0], mapData.List[0].Point[1]);//初始化人物位置 TODO加上之前骑行距离
|
||||||
cyclingExcutor = mainController.cyclingController;
|
cyclingExcutor = mainController.cyclingController;
|
||||||
@ -126,6 +128,7 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
|
|
||||||
protected virtual void Excute()
|
protected virtual void Excute()
|
||||||
{
|
{
|
||||||
|
//CamControl();
|
||||||
timer -= Time.deltaTime;
|
timer -= Time.deltaTime;
|
||||||
if (timer <= 0)//定时器 一秒执行一次
|
if (timer <= 0)//定时器 一秒执行一次
|
||||||
{
|
{
|
||||||
@ -147,7 +150,7 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
//数据处理
|
//数据处理
|
||||||
nextlatlong = Along(totalDistance);//下一个坐标
|
nextlatlong = Along(totalDistance);//下一个坐标
|
||||||
nextPos = map.GeoToWorldPosition(nextlatlong);//下一个点
|
nextPos = map.GeoToWorldPosition(nextlatlong);//下一个点
|
||||||
nextPos.y += 0.3f;//提高y轴让人物站在地图上面
|
nextPos.y += 0.5f;//提高y轴让人物站在地图上面
|
||||||
prePos = transform.localPosition;//当前点
|
prePos = transform.localPosition;//当前点
|
||||||
thisRotation = transform.localRotation;
|
thisRotation = transform.localRotation;
|
||||||
//动画控制
|
//动画控制
|
||||||
@ -181,11 +184,42 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
//当前用户调用来上传骑行记录
|
//当前用户调用来上传骑行记录
|
||||||
protected virtual void Upload()
|
protected virtual void Upload()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 工具类
|
#region 工具类
|
||||||
|
|
||||||
|
protected string CaptureCamera(Camera camera, Rect rect)
|
||||||
|
{
|
||||||
|
// 创建一个RenderTexture对象
|
||||||
|
RenderTexture rt = new RenderTexture((int)rect.width, (int)rect.height, 0);
|
||||||
|
// 临时设置相关相机的targetTexture为rt, 并手动渲染相关相机
|
||||||
|
camera.targetTexture = rt;
|
||||||
|
camera.Render();
|
||||||
|
//ps: --- 如果这样加上第二个相机,可以实现只截图某几个指定的相机一起看到的图像。
|
||||||
|
//ps: camera2.targetTexture = rt;
|
||||||
|
//ps: camera2.Render();
|
||||||
|
//ps: -------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 激活这个rt, 并从中中读取像素。
|
||||||
|
RenderTexture.active = rt;
|
||||||
|
Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
|
||||||
|
screenShot.ReadPixels(rect, 0, 0);// 注:这个时候,它是从RenderTexture.active中读取像素
|
||||||
|
screenShot.Apply();
|
||||||
|
|
||||||
|
// 重置相关参数,以使用camera继续在屏幕上显示
|
||||||
|
camera.targetTexture = null;
|
||||||
|
//ps: camera2.targetTexture = null;
|
||||||
|
RenderTexture.active = null; // JC: added to avoid errors
|
||||||
|
GameObject.Destroy(rt);
|
||||||
|
// 最后将这些纹理数据,成一个图片文件
|
||||||
|
byte[] bytes = screenShot.EncodeToJPG();
|
||||||
|
string filename = Application.dataPath + "/"+Guid.NewGuid().ToString() +".jpg";
|
||||||
|
System.IO.File.WriteAllBytes(filename, bytes);
|
||||||
|
//Debug.Log(string.Format("截屏了一张照片: {0}", filename));
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
public int CurrentIndex;
|
public int CurrentIndex;
|
||||||
//当前距离所在的海拔/坡度/距离 下一个点的坡度以及剩余距离
|
//当前距离所在的海拔/坡度/距离 下一个点的坡度以及剩余距离
|
||||||
void ComputeNextSlope()
|
void ComputeNextSlope()
|
||||||
@ -244,7 +278,15 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
yield return null;
|
yield return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Vector3 deltaPos = Vector3.zero;
|
||||||
|
Vector3 previousPos = Vector3.zero;
|
||||||
|
void CamControl()
|
||||||
|
{
|
||||||
|
deltaPos = transform.position - previousPos;
|
||||||
|
deltaPos.y = 0;
|
||||||
|
Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position, Camera.main.transform.position + deltaPos, Time.time);
|
||||||
|
previousPos = transform.position;
|
||||||
|
}
|
||||||
//人物移动控制
|
//人物移动控制
|
||||||
IEnumerator MoveTo()
|
IEnumerator MoveTo()
|
||||||
{
|
{
|
||||||
@ -255,8 +297,13 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
{
|
{
|
||||||
t += Time.deltaTime;
|
t += Time.deltaTime;
|
||||||
Vector3 v = Vector3.Lerp(prePos, nextPos, t);
|
Vector3 v = Vector3.Lerp(prePos, nextPos, t);
|
||||||
|
Vector3 nextPosition = new Vector3((float)Math.Round(v.x, 2), (float)Math.Round(v.y, 2), (float)Math.Round(v.z, 2));
|
||||||
|
if (!nextPosition.Equals(transform.localPosition))
|
||||||
|
{
|
||||||
|
transform.localPosition = nextPosition;
|
||||||
|
//Camera.main.transform.localPosition = nextPosition;
|
||||||
|
}
|
||||||
|
|
||||||
transform.localPosition = new Vector3((float)Math.Round(v.x,4), (float)Math.Round(v.y, 4), (float)Math.Round(v.z, 4));
|
|
||||||
//控制海拔图的位置
|
//控制海拔图的位置
|
||||||
yield return null;
|
yield return null;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
149
Assets/Scenes/Ride/Scripts/InitMiniMapProvider.cs
Normal file
149
Assets/Scenes/Ride/Scripts/InitMiniMapProvider.cs
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
using Mapbox.Unity.Map;
|
||||||
|
using Mapbox.Unity.MeshGeneration.Data;
|
||||||
|
using Mapbox.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Assets.Scenes.Ride.Scripts
|
||||||
|
{
|
||||||
|
public class InitMiniMapProvider : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField]
|
||||||
|
AbstractMap _map;
|
||||||
|
[SerializeField]
|
||||||
|
Camera _minicamera;
|
||||||
|
[SerializeField]
|
||||||
|
GameObject _player;
|
||||||
|
CyclingController cyclingCotroller;
|
||||||
|
PlayerController playerController;
|
||||||
|
GameObject _mipMapRoute;
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
cyclingCotroller = FindObjectOfType<CyclingController>();
|
||||||
|
playerController = FindObjectOfType<PlayerController>();
|
||||||
|
if (cyclingCotroller != null)
|
||||||
|
{
|
||||||
|
var mapdata = cyclingCotroller.GetMapData();
|
||||||
|
//初始化map
|
||||||
|
var point = cyclingCotroller.GetCenterCoordinate();
|
||||||
|
if (_map != null)
|
||||||
|
{
|
||||||
|
_map.OnInitialized += _map_OnInitialized;
|
||||||
|
_map.OnUpdated += _map_OnUpdated;
|
||||||
|
_map.Initialize(new Vector2d(mapdata.Center[0], mapdata.Center[1]), 12);
|
||||||
|
var bbox = mapdata.Bbox;
|
||||||
|
var targetbounds = new Vector2dBounds(new Vector2d(bbox[0], bbox[1]), new Vector2d(bbox[2], bbox[3]));
|
||||||
|
var screenBounds = GetScreenBounds();
|
||||||
|
SetZoomToFitBounds(targetbounds, screenBounds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
_player.transform.localPosition = _map.GeoToWorldPosition(playerController.Nextlatlong);
|
||||||
|
}
|
||||||
|
private bool init = false;
|
||||||
|
private void _map_OnInitialized()
|
||||||
|
{
|
||||||
|
init = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Camera 自适应
|
||||||
|
/// <summary>
|
||||||
|
/// https://github.com/mapbox/mapbox-unity-sdk/issues/1580
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="targetBounds">路线的边界</param>
|
||||||
|
/// <param name="screenBounds">小地图边界</param>
|
||||||
|
private void SetZoomToFitBounds(Vector2dBounds targetBounds, Vector2dBounds screenBounds)
|
||||||
|
{
|
||||||
|
var targetLonDelta = targetBounds.East - targetBounds.West;
|
||||||
|
var targetLatDelta = targetBounds.North - targetBounds.South;
|
||||||
|
|
||||||
|
var screenLonDelta = screenBounds.East - screenBounds.West;
|
||||||
|
var screenLatDelta = screenBounds.North - screenBounds.South;
|
||||||
|
|
||||||
|
var zoomLatMultiplier = screenLatDelta / targetLatDelta;
|
||||||
|
var zoomLonMultiplier = screenLonDelta / targetLonDelta;
|
||||||
|
|
||||||
|
var latZoom = Math.Log(zoomLatMultiplier, 2);
|
||||||
|
var lonZoom = Math.Log(zoomLonMultiplier, 2);
|
||||||
|
|
||||||
|
var zoom = (float)(_map.Zoom + Math.Min(latZoom, lonZoom));
|
||||||
|
|
||||||
|
_map.SetZoom((float)Math.Floor(zoom));
|
||||||
|
_map.UpdateMap();
|
||||||
|
}
|
||||||
|
private Vector2dBounds GetScreenBounds()
|
||||||
|
{
|
||||||
|
var screenWidth = UnityEngine.Screen.width;
|
||||||
|
var screenHeight = UnityEngine.Screen.height;
|
||||||
|
|
||||||
|
var sw_world = _minicamera.ViewportToWorldPoint(new Vector3(0, 0, 180));
|
||||||
|
var sw = _map.WorldToGeoPosition(sw_world);
|
||||||
|
|
||||||
|
var ne_world = _minicamera.ViewportToWorldPoint(new Vector3(0.6f, 0.6f, 180));
|
||||||
|
var ne = _map.WorldToGeoPosition(ne_world);
|
||||||
|
|
||||||
|
return new Vector2dBounds(new Vector2d(sw.x, sw.y), new Vector2d(ne.x, ne.y));
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 创建小地图路线
|
||||||
|
private void _map_OnUpdated()
|
||||||
|
{
|
||||||
|
CreateMiniRoute();
|
||||||
|
}
|
||||||
|
void CreateMiniRoute()
|
||||||
|
{
|
||||||
|
var meshData = new MeshData();
|
||||||
|
var dat = new List<Vector3>();
|
||||||
|
var mapData = cyclingCotroller.GetMapData();
|
||||||
|
if (mapData != null)
|
||||||
|
{
|
||||||
|
var count = mapData.List.Count;
|
||||||
|
var interval = Math.Max(Math.Ceiling(count / 500D),1f);
|
||||||
|
for (int i = 0; i < mapData.List.Count; i++)
|
||||||
|
{
|
||||||
|
if(i% interval == 0)
|
||||||
|
{
|
||||||
|
var point = mapData.List[i].Point;
|
||||||
|
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
|
||||||
|
item.y += 1f;
|
||||||
|
dat.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var feat = new VectorFeatureUnity();
|
||||||
|
feat.Points.Add(dat);
|
||||||
|
CreateLineRender(feat);//创建小地图路线
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//创建小地图路线
|
||||||
|
void CreateLineRender(VectorFeatureUnity feat)
|
||||||
|
{
|
||||||
|
if (_mipMapRoute != null)
|
||||||
|
{
|
||||||
|
_mipMapRoute.Destroy();
|
||||||
|
}
|
||||||
|
_mipMapRoute = new GameObject("MiniMapRoute");
|
||||||
|
_mipMapRoute.transform.parent = transform;
|
||||||
|
var lineRender = _mipMapRoute.AddComponent<LineRenderer>();
|
||||||
|
lineRender.material = new Material(Shader.Find("Sprites/Default"));
|
||||||
|
var dat = feat.Points[0];
|
||||||
|
lineRender.endColor = Color.blue;
|
||||||
|
lineRender.startColor = Color.blue;
|
||||||
|
//设置宽度
|
||||||
|
lineRender.startWidth = 0.6f;
|
||||||
|
lineRender.endWidth = 0.6f;
|
||||||
|
lineRender.positionCount = dat.Count;
|
||||||
|
lineRender.SetPositions(feat.Points[0].ToArray());
|
||||||
|
lineRender.numCornerVertices = 90;
|
||||||
|
_mipMapRoute.layer = 9;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scenes/Ride/Scripts/InitMiniMapProvider.cs.meta
Normal file
11
Assets/Scenes/Ride/Scripts/InitMiniMapProvider.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7e94e95c463c5914d99fb16ff1047af4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -71,7 +71,6 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
var t = _curve.Evaluate(Time.time);
|
var t = _curve.Evaluate(Time.time);
|
||||||
Debug.Log(t);
|
|
||||||
_text.color = Color.Lerp(Color.clear, Color.white, t);
|
_text.color = Color.Lerp(Color.clear, Color.white, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,7 +109,7 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="base64Image"></param>
|
/// <param name="base64Image"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public JsonResult<AddMapRecordResultModel> SaveData(CyclingModel cyclingModel, SelectParamModel selectParam, string base64Image = "")
|
public JsonResult<AddMapRecordResultModel> SaveData(CyclingModel cyclingModel, SelectParamModel selectParam, string imageName = "")
|
||||||
{
|
{
|
||||||
if (RiderDatas.Count <= 0)
|
if (RiderDatas.Count <= 0)
|
||||||
{
|
{
|
||||||
@ -196,19 +196,10 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
|||||||
stream.Close();
|
stream.Close();
|
||||||
files.Add(fname);
|
files.Add(fname);
|
||||||
}
|
}
|
||||||
#region TODO 截图
|
#region 截图
|
||||||
if (!string.IsNullOrEmpty(base64Image))
|
if (!string.IsNullOrEmpty(imageName))
|
||||||
{
|
{
|
||||||
//var imageName = path + "/" + Guid.NewGuid().ToString() + ".png";
|
files.Add(imageName);
|
||||||
//base64Image = base64Image.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "").Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", ""); ;
|
|
||||||
//byte[] image = Convert.FromBase64String(base64Image);
|
|
||||||
//using (MemoryStream ms = new MemoryStream(image))
|
|
||||||
//using (Image img = Image.FromStream(ms))
|
|
||||||
//{
|
|
||||||
// img.Save(imageName, System.Drawing.Imaging.ImageFormat.Png);
|
|
||||||
// //img.Dispose();
|
|
||||||
//}
|
|
||||||
//files.Add(imageName);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
var result = service.Add(interruptRecord, files);
|
var result = service.Add(interruptRecord, files);
|
||||||
|
|||||||
@ -35,9 +35,7 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
distance = mainController.UpdateDistance(speed);
|
distance = mainController.UpdateDistance(speed);
|
||||||
totalDistance += distance;
|
totalDistance += distance;
|
||||||
//记录骑行数据
|
//记录骑行数据
|
||||||
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) }");
|
#if UNITY_EDITOR
|
||||||
Debug.Log(recordText);
|
|
||||||
#if !UNITY_EDITOR
|
|
||||||
var recorderData = cyclingExcutor.recorderData;
|
var recorderData = cyclingExcutor.recorderData;
|
||||||
recorderData.RiderDatas.Add(new TargetData
|
recorderData.RiderDatas.Add(new TargetData
|
||||||
{
|
{
|
||||||
@ -51,14 +49,15 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
_Lon = nextlatlong.y
|
_Lon = nextlatlong.y
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
//上传数据
|
//上传数据
|
||||||
protected override void Upload()
|
protected override void Upload()
|
||||||
{
|
{
|
||||||
#if !UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
|
string imageFileName = base.CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.5f, Screen.height * 0.5f));
|
||||||
cyclingExcutor.recorderData.IsCompleted = totalDistance == mapData.TotalDistance;
|
cyclingExcutor.recorderData.IsCompleted = totalDistance == mapData.TotalDistance;
|
||||||
cyclingExcutor.recorderData.EndDistance = totalDistance;
|
cyclingExcutor.recorderData.EndDistance = totalDistance;
|
||||||
cyclingExcutor.recorderData.SaveData(cyclingExcutor.Mode,null,string.Empty);
|
cyclingExcutor.recorderData.SaveData(cyclingExcutor.Mode,null, imageFileName);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -7,6 +7,7 @@ using System.Collections;
|
|||||||
using Mapbox.Unity.MeshGeneration.Modifiers;
|
using Mapbox.Unity.MeshGeneration.Modifiers;
|
||||||
using Mapbox.Unity.MeshGeneration.Data;
|
using Mapbox.Unity.MeshGeneration.Data;
|
||||||
using Mapbox.Unity.Utilities;
|
using Mapbox.Unity.Utilities;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Assets.Scenes.Ride.Scripts
|
namespace Assets.Scenes.Ride.Scripts
|
||||||
{
|
{
|
||||||
@ -18,7 +19,6 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
MeshModifier SnapModifier;
|
MeshModifier SnapModifier;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Material _material;
|
Material _material;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
[Range(1, 10)]
|
[Range(1, 10)]
|
||||||
private float UpdateFrequency = 2;
|
private float UpdateFrequency = 2;
|
||||||
@ -36,14 +36,14 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
{
|
{
|
||||||
_map = FindObjectOfType<AbstractMap>();
|
_map = FindObjectOfType<AbstractMap>();
|
||||||
}
|
}
|
||||||
// _map.OnInitialized += _map_OnInitialized; ;
|
// _map.OnInitialized += _map_OnInitialized; ;
|
||||||
//_map.OnUpdated += _map_OnUpdated; ;
|
//_map.OnUpdated += _map_OnUpdated; ;
|
||||||
//_map.OnTileFinished += _map_OnTileFinished; ;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _map_OnUpdated()
|
private void _map_OnUpdated()
|
||||||
{
|
{
|
||||||
Debug.Log("_map_OnUpdated");
|
Debug.Log("_map_OnUpdated");
|
||||||
}
|
}
|
||||||
@ -59,7 +59,6 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
|
|
||||||
if (!initComplete)
|
if (!initComplete)
|
||||||
{
|
{
|
||||||
Debug.Log(47);
|
|
||||||
CreateRoute(obj);
|
CreateRoute(obj);
|
||||||
initComplete = true;
|
initComplete = true;
|
||||||
}
|
}
|
||||||
@ -71,6 +70,7 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
{
|
{
|
||||||
cyclingCotroller = transform.parent.GetComponent<CyclingController>();
|
cyclingCotroller = transform.parent.GetComponent<CyclingController>();
|
||||||
playerController = FindObjectOfType<PlayerController>();
|
playerController = FindObjectOfType<PlayerController>();
|
||||||
|
_map.OnTileFinished += _map_OnTileFinished;
|
||||||
StartCoroutine(QueryTimer());
|
StartCoroutine(QueryTimer());
|
||||||
//CreateRoute();
|
//CreateRoute();
|
||||||
}
|
}
|
||||||
@ -85,9 +85,8 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Debug.Log(88);
|
|
||||||
yield return new WaitForSeconds(UpdateFrequency);
|
|
||||||
CreateRoute(null);
|
CreateRoute(null);
|
||||||
|
yield return new WaitForSeconds(UpdateFrequency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,15 +99,18 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
var mapData = cyclingCotroller.GetMapData();
|
var mapData = cyclingCotroller.GetMapData();
|
||||||
if (mapData != null)
|
if (mapData != null)
|
||||||
{
|
{
|
||||||
foreach (var mapDataItem in mapData.List)
|
//foreach (var mapDataItem in mapData.List)
|
||||||
|
for (int i = 0; i < mapData.List.Count; i++)
|
||||||
{
|
{
|
||||||
var point = mapDataItem.Point;
|
var point = mapData.List[i].Point;
|
||||||
|
|
||||||
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
|
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
|
||||||
var distance = TurfCS.Turf.Distance(TurfCS.Turf.Point(new double[] { playerController.Nextlatlong.x, playerController.Nextlatlong.y }), TurfCS.Turf.Point(new double[] { point[0], point[1]}));
|
item.y += 0.3f;
|
||||||
if (distance<10)
|
if (!posInScreen(item) && i > playerController.CurrentIndex)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (posInScreen(item))
|
||||||
{
|
{
|
||||||
item.y += 0.3f;
|
|
||||||
dat.Add(item);
|
dat.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +119,7 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
//处理海拔高度的问题
|
//处理海拔高度的问题
|
||||||
//SnapModifier.Run(feat, meshData, tile);
|
//SnapModifier.Run(feat, meshData, tile);
|
||||||
CreatMapRoute(feat);//创建路线
|
CreatMapRoute(feat);//创建路线
|
||||||
CreateMiniMapRoute(feat);//创建小地图路线
|
//CreateMiniMapRoute(feat);//创建小地图路线
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,7 +129,7 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
Vector3 viewPos = Camera.main.WorldToViewportPoint(position);
|
Vector3 viewPos = Camera.main.WorldToViewportPoint(position);
|
||||||
Vector3 dir = (position - camreatra.position).normalized;
|
Vector3 dir = (position - camreatra.position).normalized;
|
||||||
float dot = Vector3.Dot(camreatra.forward, dir);
|
float dot = Vector3.Dot(camreatra.forward, dir);
|
||||||
if (dot > 0 && viewPos.x > 0 && viewPos.x < 1 && viewPos.y > 0 && viewPos.y < 1)
|
if (dot > -1 && viewPos.x > -1 && viewPos.x < 2 && viewPos.y > -1 && viewPos.y < 2)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -155,9 +157,10 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
var feat = new VectorFeatureUnity();
|
var feat = new VectorFeatureUnity();
|
||||||
feat.Points.Add(dat);
|
feat.Points.Add(dat);
|
||||||
//处理海拔高度的问题
|
//处理海拔高度的问题
|
||||||
SnapModifier.Run(feat, meshData, tile);
|
//SnapModifier.Run(feat, meshData, tile);
|
||||||
CreatMapRoute(feat);//创建路线
|
//CreatMapRoute(feat);//创建路线
|
||||||
CreateMiniMapRoute(feat);//创建小地图路线
|
//CreateMiniMapRoute(feat);//创建小地图路线
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,7 +179,7 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
lineRender.endColor = c;
|
lineRender.endColor = c;
|
||||||
lineRender.startColor = c;
|
lineRender.startColor = c;
|
||||||
//设置宽度
|
//设置宽度
|
||||||
lineRender.SetWidth(0.5f, 0.5f);
|
lineRender.SetWidth(0.2f, 0.2f);
|
||||||
lineRender.SetVertexCount(dat.Count);
|
lineRender.SetVertexCount(dat.Count);
|
||||||
lineRender.SetPositions(feat.Points[0].ToArray());
|
lineRender.SetPositions(feat.Points[0].ToArray());
|
||||||
//lineRender.numCapVertices = 90;
|
//lineRender.numCapVertices = 90;
|
||||||
@ -190,33 +193,5 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
lineRender.numCornerVertices = 90;
|
lineRender.numCornerVertices = 90;
|
||||||
|
|
||||||
}
|
}
|
||||||
void CreateMiniMapRoute(VectorFeatureUnity feat)
|
|
||||||
{
|
|
||||||
if (_mipMapRoute != null)
|
|
||||||
{
|
|
||||||
_mipMapRoute.Destroy();
|
|
||||||
}
|
|
||||||
_mipMapRoute = new GameObject("MiniMapRoute");
|
|
||||||
_mipMapRoute.transform.parent = transform;
|
|
||||||
var lineRender = _mipMapRoute.AddComponent<LineRenderer>();
|
|
||||||
lineRender.material = new Material(Shader.Find("Sprites/Default"));
|
|
||||||
var dat = feat.Points[0];
|
|
||||||
lineRender.endColor = Color.white;
|
|
||||||
lineRender.startColor = Color.white;
|
|
||||||
//设置宽度
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,8 @@ using DG.Tweening;
|
|||||||
using System;
|
using System;
|
||||||
using Assets.Scenes.Ride.Scripts.Model;
|
using Assets.Scenes.Ride.Scripts.Model;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Assets.Cyp.Common;
|
||||||
|
|
||||||
namespace Assets.Scenes.Ride.Scripts
|
namespace Assets.Scenes.Ride.Scripts
|
||||||
{
|
{
|
||||||
@ -57,7 +59,7 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
Text mapName;//路书名称
|
Text mapName;//路书名称
|
||||||
[SerializeField] LineChart elevationChart;//海拔图
|
[SerializeField] LineChart elevationChart;//海拔图
|
||||||
[SerializeField] Image img;//当前用户头像
|
[SerializeField] RawImage img;//当前用户头像
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Button StartOrPauseButton;//暂停按钮
|
Button StartOrPauseButton;//暂停按钮
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
@ -66,6 +68,9 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
Button DeviceButton;//设备按钮
|
Button DeviceButton;//设备按钮
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Button ExitButton;//退出按钮
|
Button ExitButton;//退出按钮
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
GameObject target;//开始按钮
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 控制器
|
#region 控制器
|
||||||
@ -86,8 +91,6 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
SettingButton.onClick.AddListener(ShowSettingPanel);
|
SettingButton.onClick.AddListener(ShowSettingPanel);
|
||||||
DeviceButton.onClick.AddListener(ShowDevicePanel);
|
DeviceButton.onClick.AddListener(ShowDevicePanel);
|
||||||
ExitButton.onClick.AddListener(StopRide);
|
ExitButton.onClick.AddListener(StopRide);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
@ -97,6 +100,7 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
mapName.text = route.RouteInstance.Name;
|
mapName.text = route.RouteInstance.Name;
|
||||||
totalDistance.text = "/" + Math.Round(mainController.GetMapData().TotalDistance, 2).ToString() + "KM";
|
totalDistance.text = "/" + Math.Round(mainController.GetMapData().TotalDistance, 2).ToString() + "KM";
|
||||||
RenderChart();
|
RenderChart();
|
||||||
|
startIndex = playerController.CurrentIndex;
|
||||||
}
|
}
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
float tt = 1f;
|
float tt = 1f;
|
||||||
@ -139,15 +143,20 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
currentSlopeText.text = Math.Round(playerController.CurrentSlope, 1).ToString() + "%";
|
currentSlopeText.text = Math.Round(playerController.CurrentSlope, 1).ToString() + "%";
|
||||||
currentSlopeDistanceText.text = Math.Round(playerController.CurrentSlopeDistance, 0).ToString() + "M";
|
currentSlopeDistanceText.text = Math.Round(playerController.CurrentSlopeDistance, 0).ToString() + "M";
|
||||||
//移动海拔图头像 TODO:移动所有人的头像
|
//移动海拔图头像 TODO:移动所有人的头像
|
||||||
MoveChartMarkPoint();
|
UpdateRealTimeChart();
|
||||||
|
//MoveChartMarkPoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//根据不同的骑行模式渲染不同的UI界面
|
private void LateUpdate()
|
||||||
void InitUI(CyclingModel cyclingModel)
|
|
||||||
{
|
{
|
||||||
|
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()
|
private void StartRide()
|
||||||
{
|
{
|
||||||
//加个5秒钟倒计时
|
//加个5秒钟倒计时
|
||||||
@ -188,25 +197,79 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
isSimple *= -1;
|
isSimple *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int maxCacheDataNumber = 100;//海拔图最大点数
|
||||||
|
private int totalCount;//路线实际点数
|
||||||
|
private int startIndex;//选中玩家起始索引
|
||||||
|
private int interval = 50;//选中玩家移动索引个数
|
||||||
|
private float[] elevationList;
|
||||||
//初始化海拔图
|
//初始化海拔图
|
||||||
void RenderChart()
|
void RenderChart()
|
||||||
{
|
{
|
||||||
elevationChart.ClearData();
|
elevationChart.ClearData();
|
||||||
var elevationArr = mainController.GetLineChartData();
|
elevationList = mainController.GetLineChartData();
|
||||||
foreach (var elevation in elevationArr)
|
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();
|
var dataPoints = elevationChart.series.list[0].dataPoints.OrderBy(c=>c.x).ToList();
|
||||||
if (dataPoints.Count > 0)
|
if (dataPoints.Count > 0)
|
||||||
{
|
{
|
||||||
var pinLoction = dataPoints[playerController.CurrentIndex];
|
var pinLoction = dataPoints[index];
|
||||||
pinLoction.y += 10;
|
pinLoction.y = img.transform.localPosition.y;
|
||||||
img.transform.localPosition = pinLoction;
|
img.transform.localPosition = pinLoction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using GeoJSON.Net.Geometry;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -64,6 +65,8 @@ namespace Assets.Scripts.Apis.Models
|
|||||||
if (_List == null) return;
|
if (_List == null) return;
|
||||||
this.CalcDistance();
|
this.CalcDistance();
|
||||||
this.CalcGrade();
|
this.CalcGrade();
|
||||||
|
this.CalcBbox();
|
||||||
|
this.CalcCenter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +120,22 @@ namespace Assets.Scripts.Apis.Models
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void CalcCenter()
|
||||||
|
{
|
||||||
|
var list = this.List.Select(p => new GeoJSON.Net.Geometry.GeographicPosition(p.Point[0], p.Point[1]));
|
||||||
|
LineString lineString = new LineString(list);
|
||||||
|
var ll = Turf.Centroid(lineString);
|
||||||
|
var p1 = ((Point)ll.Geometry).Coordinates;
|
||||||
|
Center = new double[] { ((GeographicPosition)p1).Latitude, ((GeographicPosition)p1).Longitude };
|
||||||
|
}
|
||||||
|
private void CalcBbox()
|
||||||
|
{
|
||||||
|
var list = this.List.Select(p => new GeoJSON.Net.Geometry.GeographicPosition(p.Point[0], p.Point[1]));
|
||||||
|
LineString lineString = new LineString(list);
|
||||||
|
Bbox = Turf.Bbox(lineString);
|
||||||
|
}
|
||||||
|
public Double[] Center { set; get; }
|
||||||
|
public List<Double> Bbox { set; get; }
|
||||||
public MapDataModel()
|
public MapDataModel()
|
||||||
{
|
{
|
||||||
//List = new List<Item>();
|
//List = new List<Item>();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user