2021-03-25 16:22:09 +08:00
|
|
|
|
using Assets.Scripts.Apis;
|
|
|
|
|
|
using Assets.Scripts.Apis.Models;
|
2021-03-28 18:17:15 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
2021-03-25 16:22:09 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
2021-03-29 20:32:30 +08:00
|
|
|
|
using UnityEngine.Networking;
|
2021-03-30 17:15:16 +08:00
|
|
|
|
using Assets.Scenes.Ride.Scripts.Model;
|
2021-03-31 20:46:57 +08:00
|
|
|
|
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
2021-04-02 19:17:23 +08:00
|
|
|
|
using Assets.Scenes.Ride.Scripts;
|
|
|
|
|
|
using Mapbox.Unity.Map;
|
|
|
|
|
|
using UnityEngine;
|
2021-04-19 14:38:31 +08:00
|
|
|
|
using GeoJSON.Net.Geometry;
|
|
|
|
|
|
using TurfCS;
|
|
|
|
|
|
using Mapbox.Utils;
|
|
|
|
|
|
using Assets.Scripts;
|
2021-04-21 14:08:45 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2021-04-23 09:37:41 +08:00
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
|
using UnityEngine.Events;
|
2021-03-25 16:22:09 +08:00
|
|
|
|
|
2021-04-02 19:17:23 +08:00
|
|
|
|
public class CyclingController : DeviceServiceMonoBase
|
2021-03-25 16:22:09 +08:00
|
|
|
|
{
|
2021-04-02 19:17:23 +08:00
|
|
|
|
public AbstractMap map;
|
|
|
|
|
|
public GameObject player;
|
|
|
|
|
|
public GameObject UIObject;
|
2021-04-19 14:38:31 +08:00
|
|
|
|
public RouteResultParam selectParamModel;
|
|
|
|
|
|
public RouteResult routeResult;
|
2021-04-19 18:03:04 +08:00
|
|
|
|
|
2021-04-19 14:38:31 +08:00
|
|
|
|
public int preticks;
|
2021-04-02 19:17:23 +08:00
|
|
|
|
|
2021-03-31 20:46:57 +08:00
|
|
|
|
#region 参数
|
2021-04-22 19:29:59 +08:00
|
|
|
|
private MapRoute mapRoute;//当前路书数据
|
2021-03-25 16:22:09 +08:00
|
|
|
|
private MapDataModel mapData;//当前路书数据
|
2021-04-22 19:29:59 +08:00
|
|
|
|
private Route route;//当前路书综合数据
|
|
|
|
|
|
public List<MapRouteRanking> mapRouteRankingList;
|
2021-04-19 14:38:31 +08:00
|
|
|
|
private Vector2d coordiantes;//当前地图中心
|
2021-04-15 10:13:01 +08:00
|
|
|
|
|
2021-04-19 14:38:31 +08:00
|
|
|
|
public bool isStart;//当前游戏是否开始
|
2021-04-15 10:13:01 +08:00
|
|
|
|
public CyclingModel cyclingModel;//当前骑行模式
|
2021-03-31 20:46:57 +08:00
|
|
|
|
public BaseCycling cyclingController { get; set; }
|
2021-04-22 19:29:59 +08:00
|
|
|
|
private int routeId;
|
2021-04-19 14:38:31 +08:00
|
|
|
|
|
2021-03-31 20:46:57 +08:00
|
|
|
|
private MapApi mapApi;
|
2021-04-19 18:03:04 +08:00
|
|
|
|
public DateTime startTime;
|
|
|
|
|
|
public DateTime endTime;
|
|
|
|
|
|
public bool isQuit;
|
|
|
|
|
|
public bool isPause;
|
2021-03-31 20:46:57 +08:00
|
|
|
|
#endregion
|
2021-04-16 11:23:18 +08:00
|
|
|
|
GameObject loadingcanvas;
|
2021-04-22 19:29:59 +08:00
|
|
|
|
LoadingController loadingController;
|
2021-04-21 14:08:45 +08:00
|
|
|
|
private async Task Login()
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = await new UserApi().Login("13115011550", "laozhong", "");
|
|
|
|
|
|
App.CurrentUser = result.data;
|
|
|
|
|
|
}
|
2021-04-22 19:29:59 +08:00
|
|
|
|
GameObject miniMap;
|
|
|
|
|
|
GameObject resultPanel;
|
2021-03-25 16:22:09 +08:00
|
|
|
|
void Awake()
|
|
|
|
|
|
{
|
2021-04-21 14:08:45 +08:00
|
|
|
|
#if UNITY_EDITOR
|
2021-04-29 22:16:32 +08:00
|
|
|
|
if (App.CurrentUser == null)
|
|
|
|
|
|
{
|
2021-04-21 14:08:45 +08:00
|
|
|
|
Login();
|
2021-04-29 22:16:32 +08:00
|
|
|
|
}
|
2021-04-21 14:08:45 +08:00
|
|
|
|
#endif
|
2021-03-25 16:22:09 +08:00
|
|
|
|
//获取路书信息
|
2021-04-19 14:38:31 +08:00
|
|
|
|
mapApi = ConfigHelper.mapApi;
|
2021-04-23 19:28:35 +08:00
|
|
|
|
routeId = App.RouteIdParam > 0? App.RouteIdParam : 2633;
|
2021-04-25 19:41:35 +08:00
|
|
|
|
//mapRoute = mapApi.GetById(routeId).data;
|
|
|
|
|
|
//miniMap = transform.Find("MiniMap").gameObject;//小地图
|
2021-04-22 19:29:59 +08:00
|
|
|
|
resultPanel = transform.Find("SingleUI/Panel/ResultPanel").gameObject;
|
2021-03-30 17:15:16 +08:00
|
|
|
|
}
|
2021-04-22 19:29:59 +08:00
|
|
|
|
|
2021-04-15 17:09:35 +08:00
|
|
|
|
private void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance.MainPanel = this.transform.Find("SingleUI/Panel").GetComponent<PFUIPanel>();
|
|
|
|
|
|
UIManager.Instance.ModalsPanel = this.transform.Find("SingleUI/ModalPanel").GetComponent<PFUIPanel>();
|
2021-04-30 17:25:28 +08:00
|
|
|
|
//进入倒计时
|
|
|
|
|
|
singleUIManager = UIObject.GetComponent<SingleUIManager>();
|
2021-04-22 19:29:59 +08:00
|
|
|
|
loadingController = FindObjectOfType<LoadingController>();
|
|
|
|
|
|
loadingController.InjectController(this);
|
|
|
|
|
|
//开始loading
|
2021-04-25 19:41:35 +08:00
|
|
|
|
StartCoroutine(Init());
|
2021-04-15 17:09:35 +08:00
|
|
|
|
}
|
2021-04-28 15:37:18 +08:00
|
|
|
|
public void SetUIManager(PFUIPanel mainPanel, PFUIPanel model)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance.MainPanel = mainPanel;//this.transform.Find("SingleUI/Panel").GetComponent<PFUIPanel>();
|
|
|
|
|
|
UIManager.Instance.ModalsPanel = model;// this.transform.Find("SingleUI/ModalPanel").GetComponent<PFUIPanel>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ReSetUIManager()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance.MainPanel = this.transform.Find("SingleUI/Panel").GetComponent<PFUIPanel>();
|
|
|
|
|
|
UIManager.Instance.ModalsPanel = this.transform.Find("SingleUI/ModalPanel").GetComponent<PFUIPanel>();
|
|
|
|
|
|
}
|
2021-04-22 19:29:59 +08:00
|
|
|
|
|
2021-04-23 09:37:41 +08:00
|
|
|
|
public void AddEvent(GameObject sender, EventTriggerType eventType,UnityAction<BaseEventData> unityAction)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.AddEvent(sender, eventType, unityAction);
|
|
|
|
|
|
}
|
2021-04-27 20:28:03 +08:00
|
|
|
|
public void ShowDevice(PFUIPanel pFUIPanel)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Show(UIManager.Instance.DevicePanel, pFUIPanel);
|
|
|
|
|
|
}
|
2021-04-23 09:37:41 +08:00
|
|
|
|
|
2021-04-22 19:29:59 +08:00
|
|
|
|
public Texture GetCountryImageByCode(string code)
|
|
|
|
|
|
{
|
|
|
|
|
|
return UIManager.Instance.loginRegOptions.GetCountryImage(code);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Texture GetCountryImageByName(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return UIManager.Instance.loginRegOptions.GetCountryImageByName(name);
|
|
|
|
|
|
}
|
2021-04-25 19:41:35 +08:00
|
|
|
|
private IEnumerator Init()
|
2021-04-15 10:13:01 +08:00
|
|
|
|
{
|
2021-04-25 19:41:35 +08:00
|
|
|
|
yield return new WaitForSeconds(1);
|
|
|
|
|
|
mapRoute = mapApi.GetById(routeId).data;
|
|
|
|
|
|
miniMap = transform.Find("MiniMap").gameObject;//小地图
|
|
|
|
|
|
loadingController.Init(mapRoute);//初始化loading页面
|
2021-04-22 19:29:59 +08:00
|
|
|
|
loadingController.AddProcess(10);
|
|
|
|
|
|
InitData();//初始化数据
|
|
|
|
|
|
InitGameObject();//初始化场景
|
2021-04-25 19:41:35 +08:00
|
|
|
|
MapUDPService.Init();//初始化TCP
|
|
|
|
|
|
loadingController.AddProcess(10);
|
2021-04-22 19:29:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
//初始化数据
|
|
|
|
|
|
private void InitData()
|
|
|
|
|
|
{
|
|
|
|
|
|
mapData = mapApi.GetData(routeId);//获取路书地理数据
|
|
|
|
|
|
route = new Route(mapData, mapRoute);
|
|
|
|
|
|
loadingController.AddProcess(10);
|
|
|
|
|
|
#region 其他场景传参处理
|
|
|
|
|
|
//骑行结果
|
2021-04-19 14:38:31 +08:00
|
|
|
|
if (App.routeResult != null )
|
|
|
|
|
|
{
|
|
|
|
|
|
routeResult = App.routeResult;
|
2021-04-22 19:29:59 +08:00
|
|
|
|
selectParamModel = App.routeResult.ContinueCyclingParam;//继续骑行
|
2021-04-19 14:38:31 +08:00
|
|
|
|
preticks = App.routeResult.Ticks;
|
|
|
|
|
|
}
|
2021-04-22 19:29:59 +08:00
|
|
|
|
|
2021-04-19 14:38:31 +08:00
|
|
|
|
if (selectParamModel == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
selectParamModel = new RouteResultParam
|
|
|
|
|
|
{
|
|
|
|
|
|
CompetitionId = 0,
|
|
|
|
|
|
ContinueIndex = 0,
|
|
|
|
|
|
ContinueMark = "",
|
|
|
|
|
|
GlobalContinue = false,
|
|
|
|
|
|
EndDistance = 0,
|
|
|
|
|
|
RankingsId = new List<string>(),
|
|
|
|
|
|
OnlineUserId = 0,
|
|
|
|
|
|
RouteId = App.RouteIdParam
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
App.routeResult = null;
|
|
|
|
|
|
|
2021-04-22 19:29:59 +08:00
|
|
|
|
#endregion
|
2021-04-25 19:41:35 +08:00
|
|
|
|
//异步请求mapbox画出当前路书路线图
|
|
|
|
|
|
loadingController.DrawMapRoute(mapData);
|
2021-04-22 19:29:59 +08:00
|
|
|
|
//计算上次骑行距离调整地图中心点
|
|
|
|
|
|
double endDistance = selectParamModel.EndDistance;
|
|
|
|
|
|
coordiantes = Along(endDistance);
|
|
|
|
|
|
loadingController.AddProcess(10);
|
|
|
|
|
|
//查询排行榜
|
|
|
|
|
|
var list = mapApi.GetRouteRanking(App.RouteIdParam, "1", 0, 10, "");
|
|
|
|
|
|
if (list.result)
|
|
|
|
|
|
{
|
|
|
|
|
|
mapRouteRankingList = list.data.list;
|
|
|
|
|
|
loadingController.CreateRankingList(mapRouteRankingList);
|
|
|
|
|
|
loadingController.AddProcess(10);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//加载人物和地图以及UI界面
|
|
|
|
|
|
private void InitGameObject()
|
|
|
|
|
|
{
|
2021-04-02 19:17:23 +08:00
|
|
|
|
map.gameObject.SetActive(true);
|
2021-04-16 11:23:18 +08:00
|
|
|
|
player.SetActive(true);
|
2021-04-02 19:17:23 +08:00
|
|
|
|
UIObject.SetActive(true);
|
2021-04-22 19:29:59 +08:00
|
|
|
|
miniMap.SetActive(true);
|
2021-04-02 19:17:23 +08:00
|
|
|
|
}
|
2021-03-29 20:32:30 +08:00
|
|
|
|
|
2021-04-21 14:08:45 +08:00
|
|
|
|
//设置骑行模式
|
2021-04-19 14:38:31 +08:00
|
|
|
|
public void SetCyclingModel(CyclingModel mode)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.cyclingModel = mode;
|
|
|
|
|
|
|
|
|
|
|
|
switch (cyclingModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
case CyclingModel.Single:
|
2021-04-22 19:29:59 +08:00
|
|
|
|
cyclingController = new SingleModel(route, selectParamModel);
|
2021-04-19 14:38:31 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case CyclingModel.Review:
|
2021-04-28 15:37:18 +08:00
|
|
|
|
cyclingController = new ReviewModel(route, selectParamModel);
|
2021-04-19 14:38:31 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2021-04-30 17:25:28 +08:00
|
|
|
|
AutoStart();
|
|
|
|
|
|
}
|
|
|
|
|
|
SingleUIManager singleUIManager;
|
|
|
|
|
|
public void AutoStart()
|
|
|
|
|
|
{
|
2021-04-25 13:33:43 +08:00
|
|
|
|
singleUIManager.StartRide(null);
|
2021-04-19 14:38:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-30 17:25:28 +08:00
|
|
|
|
public void GoContinueRide()
|
|
|
|
|
|
{
|
|
|
|
|
|
singleUIManager.ContinueRide();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-21 14:08:45 +08:00
|
|
|
|
#region
|
|
|
|
|
|
public bool Is3dView;
|
|
|
|
|
|
public void ChangeMapImageStyle(GameObject arrowGameObj)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Is3dView)
|
|
|
|
|
|
{
|
|
|
|
|
|
map.Terrain.ExaggerationFactor = 1.5f;
|
|
|
|
|
|
map.Terrain.SetElevationType(ElevationLayerType.TerrainWithElevation);
|
|
|
|
|
|
map.ImageLayer.SetLayerSource(ImagerySourceType.Custom);
|
|
|
|
|
|
//map.SetTileMaterial(new Material());
|
|
|
|
|
|
player.transform.localScale = new Vector3(3f, 3f, 3f);
|
|
|
|
|
|
Is3dView = true;
|
|
|
|
|
|
arrowGameObj.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
map.Terrain.ExaggerationFactor = 0f;
|
|
|
|
|
|
map.Terrain.SetElevationType(ElevationLayerType.FlatTerrain);
|
|
|
|
|
|
map.ImageLayer.SetLayerSource(ImagerySourceType.MapboxDark);
|
|
|
|
|
|
player.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
|
2021-04-27 15:15:51 +08:00
|
|
|
|
var trailRenderer = player.GetComponent<TrailRenderer>();
|
|
|
|
|
|
trailRenderer.time = 0;
|
|
|
|
|
|
StartCoroutine(EnableTrailRenderer(trailRenderer));
|
2021-04-21 14:08:45 +08:00
|
|
|
|
Is3dView = false;
|
|
|
|
|
|
arrowGameObj.SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-27 15:15:51 +08:00
|
|
|
|
IEnumerator EnableTrailRenderer(TrailRenderer trailRenderer)
|
|
|
|
|
|
{
|
|
|
|
|
|
yield return new WaitForSeconds(1f);
|
|
|
|
|
|
trailRenderer.time = 10;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-21 14:08:45 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2021-04-19 18:03:04 +08:00
|
|
|
|
#region 游戏状态控制
|
|
|
|
|
|
//开始骑行
|
|
|
|
|
|
public void SetStart()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!isPause)
|
|
|
|
|
|
{
|
|
|
|
|
|
isStart = true;
|
|
|
|
|
|
startTime = DateTime.Now;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SetContinue();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//继续骑行
|
|
|
|
|
|
public void SetContinue()
|
|
|
|
|
|
{
|
|
|
|
|
|
isStart = true;
|
|
|
|
|
|
isPause = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
//暂停骑行
|
|
|
|
|
|
public void SetPause()
|
|
|
|
|
|
{
|
|
|
|
|
|
isStart = false;
|
|
|
|
|
|
isPause = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
//退出或者完成骑行
|
|
|
|
|
|
public void SetQuit()
|
|
|
|
|
|
{
|
|
|
|
|
|
isStart = false;
|
|
|
|
|
|
isQuit = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2021-04-02 19:17:23 +08:00
|
|
|
|
#region 数据处理
|
2021-03-31 20:46:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 当前骑行数据的记录器
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private RecorderDataModel recorderData
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return cyclingController?.recorderData;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-04-02 19:17:23 +08:00
|
|
|
|
public Route GetRoute()
|
|
|
|
|
|
{
|
2021-04-22 19:29:59 +08:00
|
|
|
|
return route;
|
2021-04-02 19:17:23 +08:00
|
|
|
|
}
|
2021-03-31 20:46:57 +08:00
|
|
|
|
|
|
|
|
|
|
public MapDataModel GetMapData()
|
|
|
|
|
|
{
|
|
|
|
|
|
return mapData;
|
|
|
|
|
|
}
|
2021-04-22 19:29:59 +08:00
|
|
|
|
|
2021-04-19 18:03:04 +08:00
|
|
|
|
public void Save(double totalDistance)
|
|
|
|
|
|
{
|
2021-04-27 15:15:51 +08:00
|
|
|
|
isQuit = true;
|
2021-04-19 18:03:04 +08:00
|
|
|
|
isStart = false;
|
2021-04-29 18:07:30 +08:00
|
|
|
|
|
|
|
|
|
|
string recordId = Guid.NewGuid().ToString();
|
|
|
|
|
|
var path = Helper.GetDataDir("MapWorkoutRecords/"+ recordId);
|
|
|
|
|
|
string imageFileName = path +"/"+ Guid.NewGuid().ToString() + ".png";
|
|
|
|
|
|
CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.5f, Screen.height * 0.5f), imageFileName);
|
|
|
|
|
|
|
2021-04-19 18:03:04 +08:00
|
|
|
|
cyclingController.recorderData.StartTime = startTime;
|
|
|
|
|
|
cyclingController.recorderData.IsCompleted = totalDistance == mapData.TotalDistance;
|
|
|
|
|
|
cyclingController.recorderData.EndDistance = totalDistance;
|
|
|
|
|
|
cyclingController.recorderData.AntModelId = AntModelId;
|
|
|
|
|
|
cyclingController.recorderData.ManufacturerId = ManufacturerId;
|
|
|
|
|
|
cyclingController.recorderData.DeviceNumber = DeviceNumber;
|
2021-04-22 19:29:59 +08:00
|
|
|
|
//显示骑行结果
|
|
|
|
|
|
resultPanel.SetActive(true);
|
|
|
|
|
|
var rs = resultPanel.GetComponent<ResultPanelScript>();
|
|
|
|
|
|
rs.InjectController(this);
|
|
|
|
|
|
rs.SetDataSource(cyclingController.recorderData);
|
2021-04-29 18:07:30 +08:00
|
|
|
|
cyclingController.recorderData.SaveLocal(cyclingModel, selectParamModel, imageFileName, recordId);
|
2021-04-19 18:03:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-29 18:07:30 +08:00
|
|
|
|
protected void CaptureCamera(Camera camera, Rect rect,string fileName)
|
2021-04-19 18:03:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
// 创建一个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.EncodeToPNG();
|
2021-04-28 17:23:29 +08:00
|
|
|
|
|
2021-04-29 18:07:30 +08:00
|
|
|
|
//var path = Helper.GetDataDir("MapWorkoutRecords/images");
|
|
|
|
|
|
//string filename = path + "/" + Guid.NewGuid().ToString() + ".png";
|
|
|
|
|
|
System.IO.File.WriteAllBytes(fileName, bytes);
|
2021-04-19 18:03:04 +08:00
|
|
|
|
//Debug.Log(string.Format("截屏了一张照片: {0}", filename));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-19 14:38:31 +08:00
|
|
|
|
public Vector2d GetCenterCoordinate()
|
2021-03-31 20:46:57 +08:00
|
|
|
|
{
|
|
|
|
|
|
return coordiantes;
|
|
|
|
|
|
}
|
2021-04-19 14:38:31 +08:00
|
|
|
|
public Vector2d Along(double endDistance)
|
2021-03-25 16:22:09 +08:00
|
|
|
|
{
|
2021-04-19 14:38:31 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return new Vector2d(0,0);
|
|
|
|
|
|
}
|
2021-03-25 16:22:09 +08:00
|
|
|
|
}
|
2021-03-28 18:17:15 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 海拔图数据
|
|
|
|
|
|
/// </summary>
|
2021-04-07 17:22:45 +08:00
|
|
|
|
public float[] GetRealTimeLineChartData(int index)
|
2021-03-28 18:17:15 +08:00
|
|
|
|
{
|
2021-03-29 20:32:30 +08:00
|
|
|
|
List<float> dist = new List<float>();
|
|
|
|
|
|
var list = mapData.List.Select(c => (float) c.Elevation ).ToArray();
|
|
|
|
|
|
var count = list.Count();
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
|
{
|
2021-04-07 17:22:45 +08:00
|
|
|
|
if (i > index)
|
2021-03-29 20:32:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
dist.Add(list[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return dist.ToArray();
|
2021-03-28 18:17:15 +08:00
|
|
|
|
}
|
2021-04-07 17:22:45 +08:00
|
|
|
|
|
|
|
|
|
|
public float[] GetLineChartData()
|
|
|
|
|
|
{
|
|
|
|
|
|
var list = mapData.List.Select(c => (float)c.Elevation).ToArray();
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
2021-04-25 13:33:43 +08:00
|
|
|
|
#endregion
|
2021-04-02 19:17:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
2021-03-25 16:22:09 +08:00
|
|
|
|
}
|