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-05-10 18:13:27 +08:00
|
|
|
|
using Assets.Scenes.Ride.Scripts.Model.RiderModels;
|
|
|
|
|
|
using System.IO;
|
2021-07-06 18:24:15 +08:00
|
|
|
|
using ChartAndGraph;
|
|
|
|
|
|
using UnityEngine.UI;
|
2021-07-09 18:16:50 +08:00
|
|
|
|
using System.Diagnostics;
|
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-05-12 18:51:03 +08:00
|
|
|
|
public Dictionary<int, SeletedPlayerScript> selectPlayerDic { set; get; } = new Dictionary<int, SeletedPlayerScript>();
|
|
|
|
|
|
|
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-07-16 18:37:02 +08:00
|
|
|
|
public MapRoute mapRoute { get; set; }//当前路书数据
|
|
|
|
|
|
public MapCompetition competition { get; set; }//当前赛事数据
|
|
|
|
|
|
private MapDataModel mapData { get; set; }//当前路书数据
|
2021-04-22 19:29:59 +08:00
|
|
|
|
private Route route;//当前路书综合数据
|
2021-05-13 17:48:28 +08:00
|
|
|
|
public List<MapRouteRanking> mapRouteRankingList { get; set; }
|
2021-04-19 14:38:31 +08:00
|
|
|
|
private Vector2d coordiantes;//当前地图中心
|
2021-04-15 10:13:01 +08:00
|
|
|
|
|
2021-07-27 19:34:33 +08:00
|
|
|
|
public bool isStart { get; set; }//当前游戏是否开始
|
2021-07-06 18:24:15 +08:00
|
|
|
|
public CyclingModel cyclingModel { get; set; }//当前骑行模式
|
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-07-06 18:24:15 +08:00
|
|
|
|
public int competitionId { get; set; }
|
2021-04-19 14:38:31 +08:00
|
|
|
|
|
2021-03-31 20:46:57 +08:00
|
|
|
|
private MapApi mapApi;
|
2021-07-09 18:16:50 +08:00
|
|
|
|
public DateTime startTime { get; set; }
|
2021-04-19 18:03:04 +08:00
|
|
|
|
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-07-01 18:41:35 +08:00
|
|
|
|
AbstratctLoadingController loadingController;
|
2021-04-21 14:08:45 +08:00
|
|
|
|
private async Task Login()
|
|
|
|
|
|
{
|
2021-05-10 18:13:27 +08:00
|
|
|
|
var result = await new UserApi().Login("15261826280", "123456", "");
|
2021-04-21 14:08:45 +08:00
|
|
|
|
App.CurrentUser = result.data;
|
|
|
|
|
|
}
|
2021-07-06 18:24:15 +08:00
|
|
|
|
GameObject miniMap { get; set; }
|
2021-04-22 19:29:59 +08:00
|
|
|
|
GameObject resultPanel;
|
2021-07-06 18:24:15 +08:00
|
|
|
|
public ChartDataSourceScript chartDataSourceScript { get; set; }
|
|
|
|
|
|
public GraphChartBase graph { get; set; }
|
2021-09-02 10:08:46 +08:00
|
|
|
|
|
|
|
|
|
|
private float activeSeconds { get; set; }//移动端用户进入骑行超过2min,界面进入沉浸状态
|
2021-06-10 18:14:14 +08:00
|
|
|
|
protected override void Awake()
|
2021-03-25 16:22:09 +08:00
|
|
|
|
{
|
2021-06-10 18:14:14 +08:00
|
|
|
|
base.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-06-29 18:03:20 +08:00
|
|
|
|
competitionId = App.CompetionId;
|
2021-07-01 18:41:35 +08:00
|
|
|
|
App.CompetionId = 0;//清空比赛参数
|
2021-09-13 18:21:43 +08:00
|
|
|
|
Resources.UnloadUnusedAssets();
|
2021-03-30 17:15:16 +08:00
|
|
|
|
}
|
2021-04-22 19:29:59 +08:00
|
|
|
|
|
2021-05-14 16:11:22 +08:00
|
|
|
|
void OnDestroy()
|
|
|
|
|
|
{
|
2021-09-13 18:21:43 +08:00
|
|
|
|
Resources.UnloadUnusedAssets();
|
2021-05-14 16:11:22 +08:00
|
|
|
|
}
|
2021-05-07 18:41:37 +08:00
|
|
|
|
Transform target;
|
2021-07-06 18:24:15 +08:00
|
|
|
|
GameObject watcher;
|
|
|
|
|
|
Transform uiParent;
|
2021-09-02 10:08:46 +08:00
|
|
|
|
|
|
|
|
|
|
GameObject uipanel { get; set; }
|
2021-09-24 19:16:40 +08:00
|
|
|
|
GameObject onlineUserPrefab3d { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
GameObject OnlineHeadPanel { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public GameObject GetOnlineheadPanel()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (OnlineHeadPanel == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnlineHeadPanel = Resources.Load<GameObject>("UI/Prefab/Ride/OnlineHeadPanel");
|
|
|
|
|
|
}
|
|
|
|
|
|
return OnlineHeadPanel;
|
|
|
|
|
|
}
|
|
|
|
|
|
Material Graph3d { get; set; }
|
|
|
|
|
|
public Material Get3dGraph2()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Graph3d == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Graph3d = Resources.Load<Material>("UI/Material/3dGraph2");
|
|
|
|
|
|
}
|
|
|
|
|
|
return Graph3d;
|
|
|
|
|
|
}
|
|
|
|
|
|
Image CompetitionArrow { get; set; }
|
|
|
|
|
|
public Image GetCompetitionArrow()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CompetitionArrow == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
CompetitionArrow = Resources.Load<Image>("UI/Prefab/Match/CompetitionArrow");
|
|
|
|
|
|
}
|
|
|
|
|
|
return CompetitionArrow;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Image CompetitionMobileArrow { get; set; }
|
|
|
|
|
|
public Image GetCompetitionMobileArrow()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CompetitionMobileArrow == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
CompetitionMobileArrow = Resources.Load<Image>("UI/Prefab/Match/Mobile/CompetitionArrow");
|
|
|
|
|
|
}
|
|
|
|
|
|
return CompetitionMobileArrow;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-15 17:09:35 +08:00
|
|
|
|
private void Start()
|
|
|
|
|
|
{
|
2021-09-02 10:08:46 +08:00
|
|
|
|
var uicanvasScaler = UIObject.GetComponent<CanvasScaler>();
|
|
|
|
|
|
var loadingcanvasScaler = transform.Find("LoadingCanvas").GetComponent<CanvasScaler>();
|
|
|
|
|
|
#if UNITY_ANDROID || UNITY_IOS
|
|
|
|
|
|
uipanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Ride/Mobile/Panel"), UIObject.transform);
|
|
|
|
|
|
uicanvasScaler.referenceResolution = App.MobileResolution;
|
|
|
|
|
|
loadingcanvasScaler.referenceResolution = App.MobileResolution;
|
|
|
|
|
|
#else
|
|
|
|
|
|
uipanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Ride/Panel"), UIObject.transform);
|
|
|
|
|
|
uicanvasScaler.referenceResolution = App.PcResolution;
|
|
|
|
|
|
loadingcanvasScaler.referenceResolution = App.PcResolution;
|
2021-11-04 13:24:40 +08:00
|
|
|
|
var modalRect = transform.Find("UI/ModalPanel").GetComponent<RectTransform>();
|
|
|
|
|
|
modalRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
|
|
|
|
modalRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
|
|
|
|
modalRect.offsetMin = Vector2.zero;
|
|
|
|
|
|
modalRect.offsetMax = Vector2.zero;
|
|
|
|
|
|
modalRect.sizeDelta = new Vector2(1600, 900);
|
2021-09-02 10:08:46 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
uipanel.transform.SetAsFirstSibling();
|
|
|
|
|
|
uiParent = uipanel.transform;
|
|
|
|
|
|
resultPanel = uiParent.Find("ResultPanel").gameObject;
|
|
|
|
|
|
|
|
|
|
|
|
//获取海拔图UI对象
|
|
|
|
|
|
var graphObject = uiParent.Find("GraphChart");
|
|
|
|
|
|
chartDataSourceScript = graphObject.GetComponent<ChartDataSourceScript>();
|
|
|
|
|
|
graph = graphObject.GetComponent<GraphChartBase>();
|
|
|
|
|
|
|
|
|
|
|
|
UIManager.Instance.MainPanel = uipanel.GetComponent<PFUIPanel>();
|
2021-07-16 18:37:02 +08:00
|
|
|
|
UIManager.Instance.ModalsPanel = this.transform.Find("UI/ModalPanel").GetComponent<PFUIPanel>();
|
2021-09-24 19:16:40 +08:00
|
|
|
|
onlineUserPrefab = Resources.Load<GameObject>("UI/Prefab/Ride/EmptyOnlinePlayer");
|
|
|
|
|
|
onlineUserPrefab3d = Resources.Load<GameObject>("UI/Prefab/Match/onlinePlayerNoScript");
|
2021-05-10 18:13:27 +08:00
|
|
|
|
miniMapPlayerPrefab = Resources.Load<GameObject>("UI/Prefab/Ride/MiniMapPlayer");
|
2021-07-06 18:24:15 +08:00
|
|
|
|
watcher = Resources.Load<GameObject>("UI/Prefab/Match/Watcher");
|
2021-05-07 18:41:37 +08:00
|
|
|
|
target = transform.Find("Target");
|
2021-06-29 18:03:20 +08:00
|
|
|
|
miniMap = transform.Find("MiniMap").gameObject;//小地图
|
2021-09-02 10:08:46 +08:00
|
|
|
|
|
2021-04-30 17:25:28 +08:00
|
|
|
|
//进入倒计时
|
2021-06-24 18:19:28 +08:00
|
|
|
|
singleUIManager = UIObject.GetComponent<BaseUIManager>();
|
2021-06-29 18:03:20 +08:00
|
|
|
|
TrailRenderer trail = player.GetComponent<TrailRenderer>();
|
|
|
|
|
|
trail.Clear();
|
|
|
|
|
|
playerController = player.GetComponent<PlayerController>();
|
|
|
|
|
|
currentPlayer = playerController;//当前选中用户
|
2021-07-06 18:24:15 +08:00
|
|
|
|
|
|
|
|
|
|
if (competitionId > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
loadingController = transform.Find("LoadingCanvas").gameObject.AddComponent<CompetitionLoadingController>();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
loadingController = transform.Find("LoadingCanvas").gameObject.AddComponent<LoadingController>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-01 18:41:35 +08:00
|
|
|
|
//loadingController = FindObjectOfType<LoadingController>();
|
|
|
|
|
|
//
|
2021-04-22 19:29:59 +08:00
|
|
|
|
loadingController.InjectController(this);
|
2021-06-29 18:03:20 +08:00
|
|
|
|
//进入比赛
|
|
|
|
|
|
if (competitionId > 0)
|
|
|
|
|
|
{
|
2021-07-28 18:56:23 +08:00
|
|
|
|
this.cyclingModel = CyclingModel.Competition;
|
2021-06-29 18:03:20 +08:00
|
|
|
|
StartCoroutine(InitRace());
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
//进入单人骑行
|
|
|
|
|
|
if (routeId > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
StartCoroutine(Init());
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2021-04-22 19:29:59 +08:00
|
|
|
|
}
|
2021-07-06 18:24:15 +08:00
|
|
|
|
float timer = 1f;
|
2021-09-02 10:08:46 +08:00
|
|
|
|
bool clearLock = false;
|
2021-11-09 11:37:10 +08:00
|
|
|
|
protected override void Update()
|
2021-07-06 18:24:15 +08:00
|
|
|
|
{
|
2021-11-09 11:37:10 +08:00
|
|
|
|
base.Update();
|
2021-07-06 18:24:15 +08:00
|
|
|
|
//CamControl();
|
2021-09-03 15:12:01 +08:00
|
|
|
|
#if UNITY_IOS || UNITY_ANDROID
|
2021-09-03 13:06:26 +08:00
|
|
|
|
if (competitionId == 0 && singleUIManager != null)
|
2021-09-02 10:08:46 +08:00
|
|
|
|
{
|
2021-09-03 13:06:26 +08:00
|
|
|
|
var mouse = Input.GetMouseButton(0);
|
|
|
|
|
|
if (mouse && clearLock && singleUIManager.clearLock)
|
|
|
|
|
|
{
|
|
|
|
|
|
clearLock = false;
|
|
|
|
|
|
activeSeconds = 0;
|
|
|
|
|
|
singleUIManager?.ClearPanel(null);
|
|
|
|
|
|
}
|
2021-09-02 10:08:46 +08:00
|
|
|
|
}
|
2021-09-03 15:12:01 +08:00
|
|
|
|
#endif
|
2021-09-02 10:08:46 +08:00
|
|
|
|
|
2021-07-06 18:24:15 +08:00
|
|
|
|
timer -= Time.deltaTime;
|
|
|
|
|
|
if (timer <= 0)//定时器 一秒执行一次
|
|
|
|
|
|
{
|
|
|
|
|
|
TcpHandler();
|
2021-07-29 20:01:38 +08:00
|
|
|
|
App.CurrentScene = "Ride";
|
2021-07-23 18:07:12 +08:00
|
|
|
|
if (competitionId == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.SendCompetitionStartMessage("Ride");
|
|
|
|
|
|
}
|
2021-09-03 15:12:01 +08:00
|
|
|
|
#if UNITY_IOS || UNITY_ANDROID
|
2021-09-02 10:08:46 +08:00
|
|
|
|
if (isStart)
|
|
|
|
|
|
{
|
|
|
|
|
|
activeSeconds++;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (activeSeconds >= App.autoClearTimes && !clearLock)
|
|
|
|
|
|
{
|
2021-09-03 13:06:26 +08:00
|
|
|
|
if (competitionId == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
clearLock = true;
|
|
|
|
|
|
singleUIManager?.ClearPanel(null);
|
|
|
|
|
|
}
|
2021-09-02 10:08:46 +08:00
|
|
|
|
}
|
2021-09-03 15:12:01 +08:00
|
|
|
|
#endif
|
2021-09-02 10:08:46 +08:00
|
|
|
|
timer += 1.0f;
|
2021-07-06 18:24:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-04-22 19:29:59 +08:00
|
|
|
|
|
2021-06-29 18:03:20 +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;
|
2021-07-16 18:37:02 +08:00
|
|
|
|
loadingController.Init();//初始化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
|
|
|
|
}
|
2021-07-06 18:24:15 +08:00
|
|
|
|
public bool isWatch { get; set; }
|
2021-06-29 18:03:20 +08:00
|
|
|
|
//初始比赛
|
|
|
|
|
|
private IEnumerator InitRace()
|
|
|
|
|
|
{
|
|
|
|
|
|
yield return new WaitForSeconds(1);
|
|
|
|
|
|
mapRoute = mapApi.GetById(routeId).data;
|
2021-07-16 18:37:02 +08:00
|
|
|
|
var mapCompetitionApi = new MapCompetitionApi();
|
|
|
|
|
|
competition = mapCompetitionApi.GetById(competitionId).data;
|
|
|
|
|
|
loadingController.Init();//初始化loading页面
|
2021-06-29 18:03:20 +08:00
|
|
|
|
loadingController.AddProcess(10);
|
|
|
|
|
|
InitRaceData();//初始化比赛数据
|
|
|
|
|
|
InitRaceGameObject();//初始化比赛场景
|
2021-07-06 18:24:15 +08:00
|
|
|
|
//MapUDPService.Init(competitionId,isWatch);//初始化比赛TCP
|
2021-06-29 18:03:20 +08:00
|
|
|
|
loadingController.AddProcess(10);
|
|
|
|
|
|
}
|
2021-07-06 18:24:15 +08:00
|
|
|
|
public void InitTcp()
|
|
|
|
|
|
{
|
|
|
|
|
|
MapUDPService.Init(competitionId, isWatch);//初始化比赛TCP
|
|
|
|
|
|
}
|
2021-06-29 18:03:20 +08:00
|
|
|
|
|
2021-04-22 19:29:59 +08:00
|
|
|
|
//初始化数据
|
|
|
|
|
|
private void InitData()
|
|
|
|
|
|
{
|
|
|
|
|
|
mapData = mapApi.GetData(routeId);//获取路书地理数据
|
|
|
|
|
|
route = new Route(mapData, mapRoute);
|
|
|
|
|
|
loadingController.AddProcess(10);
|
2021-09-02 10:08:46 +08:00
|
|
|
|
#region 其他场景传参处理
|
2021-04-22 19:29:59 +08:00
|
|
|
|
//骑行结果
|
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-09-02 10:08:46 +08:00
|
|
|
|
#endregion
|
2021-04-22 19:29:59 +08:00
|
|
|
|
double endDistance = selectParamModel.EndDistance;
|
|
|
|
|
|
coordiantes = Along(endDistance);
|
2021-05-13 17:48:28 +08:00
|
|
|
|
var shaowList = mapApi.GetShadowList(App.RouteIdParam, "", 0, 10);
|
|
|
|
|
|
if (shaowList.result)
|
|
|
|
|
|
{
|
|
|
|
|
|
mapRouteRankingList = shaowList.data.list;
|
2021-04-22 19:29:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-06-08 17:39:51 +08:00
|
|
|
|
|
2021-06-29 18:03:20 +08:00
|
|
|
|
private void InitRaceData()
|
|
|
|
|
|
{
|
|
|
|
|
|
mapData = mapApi.GetData(routeId);//获取路书地理数据
|
|
|
|
|
|
route = new Route(mapData, mapRoute);
|
|
|
|
|
|
loadingController.AddProcess(10);
|
2021-09-02 10:08:46 +08:00
|
|
|
|
#region 其他场景传参处理
|
2021-06-29 18:03:20 +08:00
|
|
|
|
selectParamModel = new RouteResultParam
|
|
|
|
|
|
{
|
|
|
|
|
|
CompetitionId = competitionId,
|
|
|
|
|
|
ContinueIndex = 0,
|
|
|
|
|
|
ContinueMark = "",
|
|
|
|
|
|
GlobalContinue = false,
|
|
|
|
|
|
EndDistance = 0,
|
|
|
|
|
|
RankingsId = new List<string>(),
|
|
|
|
|
|
OnlineUserId = 0,
|
|
|
|
|
|
RouteId = App.RouteIdParam
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-09-02 10:08:46 +08:00
|
|
|
|
#endregion
|
2021-07-16 18:37:02 +08:00
|
|
|
|
|
2021-06-29 18:03:20 +08:00
|
|
|
|
//计算上次骑行距离调整地图中心点
|
|
|
|
|
|
double endDistance = selectParamModel.EndDistance;
|
|
|
|
|
|
coordiantes = Along(endDistance);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-08 17:39:51 +08:00
|
|
|
|
private Vector3 mapPos = Vector3.zero;
|
2021-04-22 19:29:59 +08:00
|
|
|
|
//加载人物和地图以及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-06-29 18:03:20 +08:00
|
|
|
|
singleUIManager = UIObject.AddComponent<SingleUIManager>();
|
2021-04-22 19:29:59 +08:00
|
|
|
|
miniMap.SetActive(true);
|
2021-04-30 17:45:21 +08:00
|
|
|
|
map.OnTileFinished += Map_OnTileFinished;
|
2021-06-08 17:39:51 +08:00
|
|
|
|
mapPos = map.transform.position;
|
2021-04-30 17:45:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-29 18:03:20 +08:00
|
|
|
|
private void InitRaceGameObject()
|
|
|
|
|
|
{
|
|
|
|
|
|
map.gameObject.SetActive(true);
|
|
|
|
|
|
player.SetActive(true);
|
|
|
|
|
|
UIObject.SetActive(true);
|
|
|
|
|
|
singleUIManager = UIObject.AddComponent<CompetitionUIManager>();
|
2021-07-06 18:24:15 +08:00
|
|
|
|
//miniMap.SetActive(true);
|
2021-06-29 18:03:20 +08:00
|
|
|
|
map.OnTileFinished += Map_OnTileFinished;
|
|
|
|
|
|
mapPos = map.transform.position;
|
2021-07-09 18:16:50 +08:00
|
|
|
|
//为了解决比赛观看模式下,切换观看用户之前跨度过大导致地图海拔信息不完整的问题
|
|
|
|
|
|
RangeAroundTransformTileProviderOptions options = new RangeAroundTransformTileProviderOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
targetTransform = target,
|
2021-11-14 16:27:00 +08:00
|
|
|
|
visibleBuffer = 2,
|
|
|
|
|
|
disposeBuffer = 2
|
2021-07-09 18:16:50 +08:00
|
|
|
|
};
|
|
|
|
|
|
map.SetExtent(MapExtentType.RangeAroundTransform, options);
|
|
|
|
|
|
map.SetExtentOptions(options);
|
2021-06-29 18:03:20 +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-06-24 18:19:28 +08:00
|
|
|
|
case CyclingModel.Competition:
|
2021-06-29 18:03:20 +08:00
|
|
|
|
cyclingController = new CompetitionModel(route, selectParamModel, currentPlayer);
|
2021-06-24 18:19:28 +08:00
|
|
|
|
break;
|
2021-04-19 14:38:31 +08:00
|
|
|
|
}
|
2021-06-29 18:03:20 +08:00
|
|
|
|
GameStart();
|
2021-06-24 18:19:28 +08:00
|
|
|
|
InitPlayer();//初始化人物方向等
|
2021-05-07 18:41:37 +08:00
|
|
|
|
}
|
2021-05-12 18:51:03 +08:00
|
|
|
|
PlayerController playerController;
|
2021-07-01 18:41:35 +08:00
|
|
|
|
public AbstractPlayer currentPlayer { get; set; }
|
2021-07-06 18:24:15 +08:00
|
|
|
|
|
|
|
|
|
|
private GameObject onlinePlayer { get; set; }
|
2021-07-16 18:37:02 +08:00
|
|
|
|
|
|
|
|
|
|
Vector3 MAX_SIZE = new Vector3(3f, 3f, 3f);
|
2021-09-24 19:16:40 +08:00
|
|
|
|
Vector3 MIN_SIZE = new Vector3(1f, 1f, 1f);
|
2021-07-01 18:41:35 +08:00
|
|
|
|
public void ChangeCurrentPlayer(int userId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var coll = FindObjectsOfType<AbstractPlayer>();
|
|
|
|
|
|
var selectedPlayer =coll.Where(c => c.UserId == userId).FirstOrDefault();
|
|
|
|
|
|
if (selectedPlayer != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentPlayer = selectedPlayer;
|
2021-09-24 19:16:40 +08:00
|
|
|
|
if (selectedPlayer is PlayerController)
|
|
|
|
|
|
{
|
|
|
|
|
|
selectedPlayer.transform.localScale = Is3dView ? MAX_SIZE : MIN_SIZE;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-09-27 18:43:41 +08:00
|
|
|
|
Utils.DestroyChildren(selectedPlayer.transform);
|
2021-09-24 19:16:40 +08:00
|
|
|
|
var ss = Instantiate(onlineUserPrefab3d, selectedPlayer.transform);
|
|
|
|
|
|
ss.transform.localScale = Is3dView ? MAX_SIZE : MIN_SIZE;
|
|
|
|
|
|
}
|
2021-07-09 18:16:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var unselectedPlayers = coll.Where(c => c.UserId != userId).ToList();
|
|
|
|
|
|
foreach (var item in unselectedPlayers)
|
|
|
|
|
|
{
|
2021-07-16 18:37:02 +08:00
|
|
|
|
item.transform.localScale = MIN_SIZE;
|
2021-09-24 19:16:40 +08:00
|
|
|
|
if (item.transform.childCount > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Utils.DestroyChildren(item.transform);
|
|
|
|
|
|
}
|
2021-07-01 18:41:35 +08:00
|
|
|
|
}
|
2021-07-16 18:37:02 +08:00
|
|
|
|
//重置海拔图进度
|
2021-07-23 09:04:56 +08:00
|
|
|
|
var currentIndex = currentPlayer.CurrentIndex;
|
|
|
|
|
|
graph.HorizontalScrolling = chartDataSourceScript.GetCurrentStart(currentIndex);
|
2021-07-06 18:24:15 +08:00
|
|
|
|
}
|
2021-09-28 11:30:51 +08:00
|
|
|
|
|
2021-05-07 18:41:37 +08:00
|
|
|
|
//初始化人物位置角度
|
|
|
|
|
|
private void InitPlayer()
|
|
|
|
|
|
{
|
2021-04-30 23:45:50 +08:00
|
|
|
|
lockView = true;
|
2021-06-29 18:03:20 +08:00
|
|
|
|
|
2021-05-07 18:41:37 +08:00
|
|
|
|
Vector2d lastLatLon = Along(recorderData.EndDistance);
|
|
|
|
|
|
Vector3 currentPos = map.GeoToWorldPosition(lastLatLon);
|
|
|
|
|
|
currentPos.y += 1f;
|
|
|
|
|
|
player.transform.position = currentPos;
|
|
|
|
|
|
playerController.currentPos = currentPos;
|
2021-09-24 19:16:40 +08:00
|
|
|
|
var trail = FindObjectOfType<TrailRenderer>();
|
|
|
|
|
|
trail.enabled = true;
|
2021-05-07 18:41:37 +08:00
|
|
|
|
|
|
|
|
|
|
Vector2d nextLatLon = Along(recorderData.EndDistance + 0.1);
|
|
|
|
|
|
//设定人物方向
|
|
|
|
|
|
var s = map.GeoToWorldPosition(lastLatLon);
|
|
|
|
|
|
var e = map.GeoToWorldPosition(nextLatLon);
|
|
|
|
|
|
Quaternion neededRotation = Quaternion.LookRotation(s - e);
|
|
|
|
|
|
player.transform.rotation = Quaternion.Euler(0, neededRotation.eulerAngles.y, 0);
|
|
|
|
|
|
playerController.currentRotation = neededRotation;
|
2021-05-24 10:16:35 +08:00
|
|
|
|
//初始化海拔图头像位置
|
|
|
|
|
|
var index = GetCurrentIndex(recorderData.EndDistance);
|
2021-07-06 18:24:15 +08:00
|
|
|
|
InitGraph(index);
|
2021-11-11 15:55:58 +08:00
|
|
|
|
playerController.CurrentIndex = index;
|
2021-07-06 18:24:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
public void InitGraph(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
chartDataSourceScript.InitHorizontalScrolling(index);
|
2021-04-30 17:25:28 +08:00
|
|
|
|
}
|
2021-06-24 18:19:28 +08:00
|
|
|
|
//SingleUIManager singleUIManager;
|
2021-09-13 18:21:43 +08:00
|
|
|
|
public BaseUIManager singleUIManager;
|
2021-06-24 18:19:28 +08:00
|
|
|
|
public void GameStart()
|
2021-04-30 17:25:28 +08:00
|
|
|
|
{
|
2021-11-01 11:04:22 +08:00
|
|
|
|
var check = CheckAnt();
|
2021-11-11 15:55:58 +08:00
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
check = true;
|
|
|
|
|
|
#endif
|
2021-11-01 11:04:22 +08:00
|
|
|
|
if (check)
|
|
|
|
|
|
{
|
|
|
|
|
|
singleUIManager.StartRide();
|
|
|
|
|
|
transform.Find("UI/Panel(Clone)/ToolBarPanel/StartOrPauseButton").GetComponent<Button>().enabled = true;
|
2021-11-02 17:55:49 +08:00
|
|
|
|
transform.Find("UI/Panel(Clone)/ToolBarPanel/SettingButton").GetComponent<Button>().enabled = true;
|
2021-11-01 11:04:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
transform.Find("UI/Panel(Clone)/ToolBarPanel/StartOrPauseButton").GetComponent<Button>().enabled = false;
|
2021-11-02 17:55:49 +08:00
|
|
|
|
transform.Find("UI/Panel(Clone)/ToolBarPanel/SettingButton").GetComponent<Button>().enabled = false;
|
2021-11-01 11:04:22 +08:00
|
|
|
|
Utils.showToast(null, "Please connect the device!", duration: int.MaxValue, isLowest: true
|
2021-11-04 13:24:40 +08:00
|
|
|
|
, stopFunc: () => !(!CheckAnt() && !isWatch) || transform.Find("UI/Panel(Clone)/SelectPlayer").gameObject.activeInHierarchy
|
2021-11-01 11:04:22 +08:00
|
|
|
|
, endCallback: () =>
|
|
|
|
|
|
{
|
2021-11-04 13:24:40 +08:00
|
|
|
|
if (!transform.Find("UI/Panel(Clone)/SelectPlayer").gameObject.activeInHierarchy)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance.DevicePanel.Close();
|
|
|
|
|
|
singleUIManager.StartRide();
|
|
|
|
|
|
transform.Find("UI/Panel(Clone)/ToolBarPanel/StartOrPauseButton").GetComponent<Button>().enabled = true;
|
|
|
|
|
|
transform.Find("UI/Panel(Clone)/ToolBarPanel/SettingButton").GetComponent<Button>().enabled = true;
|
|
|
|
|
|
}
|
2021-11-01 11:04:22 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2021-04-19 14:38:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-30 17:25:28 +08:00
|
|
|
|
public void GoContinueRide()
|
|
|
|
|
|
{
|
2021-06-29 18:03:20 +08:00
|
|
|
|
singleUIManager.ContinueRide();
|
2021-04-30 17:25:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-02 10:08:46 +08:00
|
|
|
|
#region TCP相关
|
2021-05-10 18:13:27 +08:00
|
|
|
|
|
|
|
|
|
|
public void TcpHandler()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (cyclingController != null)
|
|
|
|
|
|
{
|
2021-09-17 22:20:05 +08:00
|
|
|
|
////tcp数据传输
|
|
|
|
|
|
//if (competition != null && !cyclingController.recorderData.Saved)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// cyclingController.recorderData.Saved = competition.HasRecord;
|
|
|
|
|
|
//}
|
2021-05-10 18:13:27 +08:00
|
|
|
|
cyclingController.Run(null);
|
|
|
|
|
|
//在线人物或比赛人物渲染
|
|
|
|
|
|
ShowOnlineUsers();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<OnlinePlayerController> otherList = new List<OnlinePlayerController>();
|
|
|
|
|
|
GameObject onlineUserPrefab;
|
|
|
|
|
|
GameObject miniMapPlayerPrefab;
|
|
|
|
|
|
|
2021-05-13 17:48:28 +08:00
|
|
|
|
int messageIndex = 0;
|
2021-05-10 18:13:27 +08:00
|
|
|
|
private void ShowOnlineUsers()
|
|
|
|
|
|
{
|
|
|
|
|
|
var onlineRiders = cyclingController.riders;
|
2021-05-13 17:48:28 +08:00
|
|
|
|
var currentOnlineUserList = FindObjectsOfType<OnlinePlayerController>();
|
2021-05-10 18:13:27 +08:00
|
|
|
|
//新增或者更新
|
|
|
|
|
|
foreach (var item in onlineRiders)
|
|
|
|
|
|
{
|
|
|
|
|
|
var onlineRider = item as OnlineRiderModel;
|
|
|
|
|
|
var currentUser = currentOnlineUserList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
|
|
|
|
|
var onlineDistance = onlineRider.EndDistance - onlineRider.PreDistance;
|
2021-07-29 16:13:23 +08:00
|
|
|
|
var onlineTotalDistance = onlineRider.PreDistance;
|
2021-05-24 10:16:35 +08:00
|
|
|
|
var index = GetCurrentIndex(onlineTotalDistance);
|
2021-05-13 17:48:28 +08:00
|
|
|
|
|
2021-05-10 18:13:27 +08:00
|
|
|
|
if (currentUser == null)
|
|
|
|
|
|
{
|
2021-05-11 18:21:32 +08:00
|
|
|
|
//大地图人物
|
|
|
|
|
|
GameObject otherPlayerObj = (GameObject)Instantiate(onlineUserPrefab, transform);
|
|
|
|
|
|
otherPlayerObj.transform.position = map.GeoToWorldPosition(Along(onlineTotalDistance));
|
|
|
|
|
|
var onlinePlayerController = otherPlayerObj.GetComponent<OnlinePlayerController>();
|
|
|
|
|
|
otherList.Add(onlinePlayerController);
|
2021-05-13 17:48:28 +08:00
|
|
|
|
|
2021-05-11 18:21:32 +08:00
|
|
|
|
onlinePlayerController.UserId = onlineRider.UserId;
|
2021-05-24 10:16:35 +08:00
|
|
|
|
|
2021-07-23 09:04:56 +08:00
|
|
|
|
onlinePlayerController.SetDataSource(onlineTotalDistance, onlineDistance, onlineRider.Power, onlineRider.HeartRate, onlineRider.Cadence, onlineRider.TotalTicks, onlineRider.NickName, onlineRider.WeightKg, new Vector2d(onlineRider.Point.Latitude, onlineRider.Point.Longitude),index);
|
2021-05-11 18:21:32 +08:00
|
|
|
|
onlinePlayerController.SetHead(onlineRider.WxHeadImg);
|
2021-09-16 15:59:08 +08:00
|
|
|
|
if (competitionId == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
//小地图人物
|
|
|
|
|
|
GameObject miniPlayer = (GameObject)Instantiate(miniMapPlayerPrefab, transform);
|
|
|
|
|
|
var miniController = miniPlayer.GetComponent<MiniMapPlayerController>();
|
|
|
|
|
|
miniController.SetController(onlinePlayerController);
|
|
|
|
|
|
}
|
2021-05-13 17:48:28 +08:00
|
|
|
|
//发消息xx进入路书
|
|
|
|
|
|
if(messageIndex > 0)
|
|
|
|
|
|
EventQueueSystem.QueueEvent(new JoinMessageEvent(onlineRider.NickName, onlineRider.WxHeadImg));
|
|
|
|
|
|
|
2021-05-10 18:13:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-07-23 09:04:56 +08:00
|
|
|
|
currentUser.SetDataSource(onlineTotalDistance, onlineDistance, onlineRider.Power, onlineRider.HeartRate, onlineRider.Cadence, onlineRider.TotalTicks, onlineRider.NickName, onlineRider.WeightKg, new Vector2d(onlineRider.Point.Latitude, onlineRider.Point.Longitude), index);
|
2021-05-10 18:13:27 +08:00
|
|
|
|
}
|
2021-07-06 18:24:15 +08:00
|
|
|
|
//如果是观察者且当前第一此进入场景(TODO:这样切换会闪一下待解决)
|
2021-09-27 18:43:41 +08:00
|
|
|
|
if (isWatch && (currentPlayer is PlayerController || currentPlayer == null))
|
2021-07-06 18:24:15 +08:00
|
|
|
|
{
|
2021-09-27 18:43:41 +08:00
|
|
|
|
var userId = onlineRiders.FirstOrDefault()?.UserId ?? 0;
|
2021-07-06 18:24:15 +08:00
|
|
|
|
ChangeCurrentPlayer(userId);
|
2021-09-27 18:43:41 +08:00
|
|
|
|
var competitionRankingFactory = FindObjectOfType<CompetitionRankingFactory>();
|
|
|
|
|
|
if (competitionRankingFactory != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
competitionRankingFactory.isInit = false;
|
|
|
|
|
|
}
|
2021-07-06 18:24:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
//显示观察者头像
|
2021-05-10 18:13:27 +08:00
|
|
|
|
}
|
2021-05-13 17:48:28 +08:00
|
|
|
|
if(onlineRiders.Count > 0)
|
|
|
|
|
|
messageIndex++;
|
2021-05-12 18:51:03 +08:00
|
|
|
|
//移除
|
|
|
|
|
|
foreach (var item in currentOnlineUserList)
|
|
|
|
|
|
{
|
|
|
|
|
|
var currentItem = onlineRiders.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
|
|
|
|
|
if (currentItem == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.RemoveSelf();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//显示面板信息
|
|
|
|
|
|
var others = FindObjectsOfType<AbstractPlayer>();
|
|
|
|
|
|
foreach (var item in others)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.IsShowInfo = false;
|
|
|
|
|
|
}
|
2021-07-09 18:16:50 +08:00
|
|
|
|
var frontPlayer = others.Where(c => c.TotalDistance - currentPlayer.TotalDistance < 0.25 && c.TotalDistance - currentPlayer.TotalDistance >= 0 && c.UserId != currentPlayer.UserId).OrderBy(c=>c.TotalDistance).FirstOrDefault();
|
|
|
|
|
|
var bakePlayer = others.Where(c => c.TotalDistance - currentPlayer.TotalDistance >-0.25 && c.TotalDistance - currentPlayer.TotalDistance < 0 && c.UserId != currentPlayer.UserId).OrderByDescending(c=>c.TotalDistance).FirstOrDefault();
|
2021-05-12 18:51:03 +08:00
|
|
|
|
if(frontPlayer != null)
|
|
|
|
|
|
frontPlayer.IsShowInfo = true;
|
|
|
|
|
|
if (bakePlayer != null)
|
|
|
|
|
|
bakePlayer.IsShowInfo = true;
|
2021-05-10 18:13:27 +08:00
|
|
|
|
}
|
2021-07-23 09:04:56 +08:00
|
|
|
|
|
2021-07-16 18:37:02 +08:00
|
|
|
|
//查询赛事观看者列表(取前5)
|
|
|
|
|
|
public List<OnlineUser> GetWatcherList()
|
|
|
|
|
|
{
|
|
|
|
|
|
return MapUDPService.GetCompetitionWatchers(competitionId);
|
2021-07-06 18:24:15 +08:00
|
|
|
|
}
|
2021-09-02 10:08:46 +08:00
|
|
|
|
#endregion
|
2021-05-10 18:13:27 +08:00
|
|
|
|
|
2021-06-29 18:03:20 +08:00
|
|
|
|
public void SetUIManager(PFUIPanel mainPanel, PFUIPanel model)
|
|
|
|
|
|
{
|
2021-07-16 18:37:02 +08:00
|
|
|
|
UIManager.Instance.MainPanel = mainPanel;
|
|
|
|
|
|
UIManager.Instance.ModalsPanel = model;
|
2021-06-29 18:03:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ReSetUIManager()
|
|
|
|
|
|
{
|
2021-09-02 10:08:46 +08:00
|
|
|
|
UIManager.Instance.MainPanel = uipanel.GetComponent<PFUIPanel>();
|
2021-07-16 18:37:02 +08:00
|
|
|
|
UIManager.Instance.ModalsPanel = this.transform.Find("UI/ModalPanel").GetComponent<PFUIPanel>();
|
2021-06-29 18:03:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddEvent(GameObject sender, EventTriggerType eventType, UnityAction<BaseEventData> unityAction)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.AddEvent(sender, eventType, unityAction);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void ShowDevice(PFUIPanel pFUIPanel)
|
|
|
|
|
|
{
|
2021-09-02 11:04:50 +08:00
|
|
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
|
|
|
|
UIManager.ShowDevicePanel();
|
|
|
|
|
|
#else
|
2021-11-02 17:55:49 +08:00
|
|
|
|
UIManager.Show(UIManager.Instance.DevicePanel,null,true);
|
2021-09-02 11:04:50 +08:00
|
|
|
|
#endif
|
2021-06-29 18:03:20 +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-09-02 10:08:46 +08:00
|
|
|
|
#region 视角切换
|
2021-05-10 18:13:27 +08:00
|
|
|
|
|
|
|
|
|
|
public AbstractMap map3d;
|
2021-04-21 14:08:45 +08:00
|
|
|
|
public bool Is3dView;
|
|
|
|
|
|
public void ChangeMapImageStyle(GameObject arrowGameObj)
|
|
|
|
|
|
{
|
2021-10-12 20:43:33 +08:00
|
|
|
|
var trailRendererList = transform.GetComponentsInChildren<TrailRenderer>();
|
|
|
|
|
|
foreach (var item in trailRendererList)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.time = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
StartCoroutine(EnableTrailRenderer(trailRendererList.ToList()));
|
|
|
|
|
|
|
2021-04-21 14:08:45 +08:00
|
|
|
|
if (!Is3dView)
|
|
|
|
|
|
{
|
2021-05-07 18:41:37 +08:00
|
|
|
|
//地图属性变更
|
2021-04-21 14:08:45 +08:00
|
|
|
|
map.Terrain.ExaggerationFactor = 1.5f;
|
|
|
|
|
|
map.Terrain.SetElevationType(ElevationLayerType.TerrainWithElevation);
|
|
|
|
|
|
map.ImageLayer.SetLayerSource(ImagerySourceType.Custom);
|
2021-07-01 18:41:35 +08:00
|
|
|
|
map.SetCenterLatitudeLongitude(currentPlayer.Currentlatlong);
|
2021-06-08 17:39:51 +08:00
|
|
|
|
map.transform.position = mapPos;
|
2021-05-10 18:13:27 +08:00
|
|
|
|
//map3d.gameObject.SetActive(true);
|
|
|
|
|
|
//map.gameObject.SetActive(false);
|
2021-05-07 18:41:37 +08:00
|
|
|
|
//人物属性变更
|
2021-07-01 18:41:35 +08:00
|
|
|
|
var pos = map.GeoToWorldPosition(currentPlayer.Currentlatlong);
|
2021-05-07 18:41:37 +08:00
|
|
|
|
playerController.currentPos = pos;
|
|
|
|
|
|
target.position = pos;
|
|
|
|
|
|
player.transform.localScale = new Vector3(3f, 3f, 3f);
|
|
|
|
|
|
player.transform.position = pos;
|
|
|
|
|
|
|
2021-04-21 14:08:45 +08:00
|
|
|
|
arrowGameObj.SetActive(false);
|
2021-05-07 18:41:37 +08:00
|
|
|
|
Is3dView = true;
|
2021-04-21 14:08:45 +08:00
|
|
|
|
}
|
2021-05-07 18:41:37 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//地图属性变更
|
|
|
|
|
|
map.ImageLayer.SetLayerSource(ImagerySourceType.JuzeTest);
|
|
|
|
|
|
map.Terrain.ExaggerationFactor = 0f;
|
|
|
|
|
|
map.Terrain.SetElevationType(ElevationLayerType.FlatTerrain);
|
2021-07-01 18:41:35 +08:00
|
|
|
|
map.SetCenterLatitudeLongitude(currentPlayer.Currentlatlong);
|
2021-06-08 17:39:51 +08:00
|
|
|
|
map.transform.position = Vector3.zero;
|
2021-05-10 18:13:27 +08:00
|
|
|
|
//map.gameObject.SetActive(true);
|
|
|
|
|
|
//map3d.gameObject.SetActive(false);
|
2021-05-07 18:41:37 +08:00
|
|
|
|
//人物属性变更
|
2021-07-01 18:41:35 +08:00
|
|
|
|
var pos = map.GeoToWorldPosition(currentPlayer.Currentlatlong);
|
2021-05-07 18:41:37 +08:00
|
|
|
|
player.transform.position = pos;
|
2021-07-29 16:13:23 +08:00
|
|
|
|
player.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f);
|
2021-05-07 18:41:37 +08:00
|
|
|
|
target.position = pos;
|
2021-06-10 18:14:14 +08:00
|
|
|
|
//playerController.currentPos = Vector3.zero;
|
2021-05-07 18:41:37 +08:00
|
|
|
|
arrowGameObj.SetActive(true);
|
|
|
|
|
|
Is3dView = false;
|
|
|
|
|
|
}
|
2021-11-02 14:38:05 +08:00
|
|
|
|
if (competitionId > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
ChangeCurrentPlayer(currentPlayer.UserId);
|
|
|
|
|
|
}
|
2021-04-30 23:45:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
private bool lockView = false;
|
|
|
|
|
|
private void Map_OnTileFinished(Mapbox.Unity.MeshGeneration.Data.UnityTile obj)
|
|
|
|
|
|
{
|
2021-11-02 14:38:05 +08:00
|
|
|
|
if (!lockView)
|
|
|
|
|
|
{
|
2021-04-30 23:45:50 +08:00
|
|
|
|
|
|
|
|
|
|
var playerController = player.GetComponent<PlayerController>();
|
|
|
|
|
|
player.transform.localScale = new Vector3(3f, 3f, 3f);
|
|
|
|
|
|
var locations = playerController.Currentlatlong == null ? playerController.Currentlatlong : new Vector2d(mapData.List[0].Point[0], mapData.List[0].Point[1]);
|
|
|
|
|
|
player.transform.position = map.GeoToWorldPosition(locations);
|
2021-06-08 17:39:51 +08:00
|
|
|
|
mapPos = map.transform.position;
|
2021-04-30 23:45:50 +08:00
|
|
|
|
if (recorderData != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var lastLatLon = Along(recorderData.EndDistance);
|
2021-05-07 18:41:37 +08:00
|
|
|
|
var nextLatLon = Along(recorderData.EndDistance+0.1);
|
2021-04-30 23:45:50 +08:00
|
|
|
|
player.transform.position = map.GeoToWorldPosition(lastLatLon);
|
2021-05-07 18:41:37 +08:00
|
|
|
|
//设定人物方向
|
|
|
|
|
|
var s = map.GeoToWorldPosition(lastLatLon);
|
|
|
|
|
|
var e = map.GeoToWorldPosition(nextLatLon);
|
|
|
|
|
|
Quaternion neededRotation = Quaternion.LookRotation(s - e);
|
|
|
|
|
|
player.transform.rotation = Quaternion.Euler(0, neededRotation.eulerAngles.y, 0);
|
2021-04-30 23:45:50 +08:00
|
|
|
|
}
|
2021-04-21 14:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-12 20:43:33 +08:00
|
|
|
|
IEnumerator EnableTrailRenderer(List<TrailRenderer> trailRendererList)
|
2021-04-27 15:15:51 +08:00
|
|
|
|
{
|
2021-05-07 18:41:37 +08:00
|
|
|
|
yield return new WaitForSeconds(2f);
|
2021-10-12 20:43:33 +08:00
|
|
|
|
foreach (var item in trailRendererList)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.Clear();
|
|
|
|
|
|
item.time = 30;
|
|
|
|
|
|
}
|
2021-04-27 15:15:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-02 10:08:46 +08:00
|
|
|
|
#endregion
|
2021-04-21 14:08:45 +08:00
|
|
|
|
|
2021-09-02 10:08:46 +08:00
|
|
|
|
#region 游戏状态控制
|
2021-07-09 18:16:50 +08:00
|
|
|
|
Stopwatch sw { get; set; }
|
2021-04-19 18:03:04 +08:00
|
|
|
|
//开始骑行
|
|
|
|
|
|
public void SetStart()
|
|
|
|
|
|
{
|
2021-05-07 18:41:37 +08:00
|
|
|
|
if (!isPause || DateTime.MinValue == startTime)
|
2021-04-19 18:03:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
isStart = true;
|
2021-05-08 18:36:59 +08:00
|
|
|
|
startTime = UIManager.Now.GetDateTime();
|
2021-07-30 09:53:49 +08:00
|
|
|
|
////骑行累计毫秒
|
|
|
|
|
|
//sw = new Stopwatch();
|
|
|
|
|
|
//sw.Start();
|
2021-09-02 10:08:46 +08:00
|
|
|
|
activeSeconds = 0f;
|
2021-04-19 18:03:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SetContinue();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//继续骑行
|
|
|
|
|
|
public void SetContinue()
|
|
|
|
|
|
{
|
|
|
|
|
|
isStart = true;
|
|
|
|
|
|
isPause = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
//暂停骑行
|
|
|
|
|
|
public void SetPause()
|
|
|
|
|
|
{
|
|
|
|
|
|
isStart = false;
|
|
|
|
|
|
isPause = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
//退出或者完成骑行
|
|
|
|
|
|
public void SetQuit()
|
|
|
|
|
|
{
|
2021-07-30 09:53:49 +08:00
|
|
|
|
////耗时巨大的代码
|
|
|
|
|
|
//if (sw != null)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// sw.Stop();
|
|
|
|
|
|
// TimeSpan ts2 = (TimeSpan)(sw.Elapsed);
|
|
|
|
|
|
// UnityEngine.Debug.Log(string.Format("Stopwatch总共花费{0}ms.", ts2.TotalMilliseconds));
|
|
|
|
|
|
// //TODO后算接口需要增加累计毫秒字段
|
|
|
|
|
|
//}
|
2021-04-19 18:03:04 +08:00
|
|
|
|
isStart = false;
|
|
|
|
|
|
isQuit = true;
|
|
|
|
|
|
}
|
2021-09-02 10:08:46 +08:00
|
|
|
|
#endregion
|
2021-04-19 18:03:04 +08:00
|
|
|
|
|
2021-09-02 10:08:46 +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
|
|
|
|
|
2021-09-02 10:08:46 +08:00
|
|
|
|
public GameObject GetUIPanel()
|
|
|
|
|
|
{
|
|
|
|
|
|
return uipanel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-07-30 19:39:01 +08:00
|
|
|
|
cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime();
|
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();
|
2021-05-10 18:13:27 +08:00
|
|
|
|
//var path = Helper.GetDataDir("MapWorkoutRecords/"+ recordId);
|
|
|
|
|
|
var path = PFConstants.MapWorkoutRecordFolder + "/" + recordId;
|
|
|
|
|
|
Helper.CreateDirectoryIfNotExsit(path);
|
|
|
|
|
|
|
2021-04-29 18:07:30 +08:00
|
|
|
|
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;
|
2021-07-30 19:39:01 +08:00
|
|
|
|
cyclingController.recorderData.IsCompleted = totalDistance >= mapData.TotalDistance;
|
2021-04-19 18:03:04 +08:00
|
|
|
|
cyclingController.recorderData.EndDistance = totalDistance;
|
|
|
|
|
|
cyclingController.recorderData.AntModelId = AntModelId;
|
|
|
|
|
|
cyclingController.recorderData.ManufacturerId = ManufacturerId;
|
2021-06-08 16:28:00 +08:00
|
|
|
|
cyclingController.recorderData.ManufacturerName = ManufacturerName;
|
2021-04-19 18:03:04 +08:00
|
|
|
|
cyclingController.recorderData.DeviceNumber = DeviceNumber;
|
2021-07-06 18:24:15 +08:00
|
|
|
|
//显示骑行结果(如果是比赛模式显示比赛最终排名)
|
|
|
|
|
|
if (cyclingModel != CyclingModel.Competition)
|
|
|
|
|
|
{
|
|
|
|
|
|
resultPanel.SetActive(true);
|
|
|
|
|
|
var rs = resultPanel.GetComponent<ResultPanelScript>();
|
|
|
|
|
|
rs.InjectController(this);
|
|
|
|
|
|
rs.SetDataSource(cyclingController.recorderData);
|
|
|
|
|
|
}
|
2021-05-10 18:13:27 +08:00
|
|
|
|
cyclingController.recorderData.SaveWithLocalRecordAysnc(cyclingModel, selectParamModel, imageFileName, recordId, path);
|
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-05-24 10:16:35 +08:00
|
|
|
|
|
|
|
|
|
|
public int GetCurrentIndex(double endDistance)
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
var pointList = mapData.List;
|
|
|
|
|
|
double sumDistance = 0;
|
2021-09-27 18:43:41 +08:00
|
|
|
|
if (endDistance >= mapData.TotalDistance)
|
|
|
|
|
|
{
|
|
|
|
|
|
return pointList.Count - 1;
|
|
|
|
|
|
}
|
2021-05-24 10:16:35 +08:00
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < pointList.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
sumDistance += pointList[i].Distance;
|
2021-07-06 18:24:15 +08:00
|
|
|
|
decimal left = (decimal)(endDistance * 1000);
|
|
|
|
|
|
decimal right = (decimal)sumDistance;
|
|
|
|
|
|
if (left <= right)
|
2021-05-24 10:16:35 +08:00
|
|
|
|
{
|
|
|
|
|
|
index = i;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-09-27 18:43:41 +08:00
|
|
|
|
index = endDistance >= mapData.TotalDistance ? pointList.Count - 1 : index;
|
2021-05-24 10:16:35 +08:00
|
|
|
|
return index;
|
|
|
|
|
|
}
|
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-07-09 18:16:50 +08:00
|
|
|
|
private double CurrentMaxAp = 0;//当前最大AP
|
|
|
|
|
|
public void ComputeMaxAP(double power,int ticks)
|
2021-03-28 18:17:15 +08:00
|
|
|
|
{
|
2021-07-09 18:16:50 +08:00
|
|
|
|
//计算当前最大AP
|
|
|
|
|
|
if (power > CurrentMaxAp)
|
2021-03-29 20:32:30 +08:00
|
|
|
|
{
|
2021-07-09 18:16:50 +08:00
|
|
|
|
CurrentMaxAp = power;
|
|
|
|
|
|
}
|
|
|
|
|
|
//分段记录MaxAp
|
|
|
|
|
|
switch (ticks)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 5: recorderData.FiveSecondsMaxAP = CurrentMaxAp; break;
|
|
|
|
|
|
case 10: recorderData.TenSecondsMaxAP = CurrentMaxAp; break;
|
|
|
|
|
|
case 60: recorderData.OneMinuteMaxAP = CurrentMaxAp; break;
|
|
|
|
|
|
case 300: recorderData.FiveMinutesMaxAp = CurrentMaxAp; break;
|
|
|
|
|
|
case 1200: recorderData.TwentyMinutesMaxAP = CurrentMaxAp; break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
2021-03-29 20:32:30 +08:00
|
|
|
|
}
|
2021-04-07 17:22:45 +08:00
|
|
|
|
}
|
2021-09-02 10:08:46 +08:00
|
|
|
|
#endregion
|
2021-03-25 16:22:09 +08:00
|
|
|
|
}
|