loading页&结果页面&代码结构微调
This commit is contained in:
1 parent
eb1803c9ef
commit
eed2d13624
99 files changed
+14567
-7299
No files matched your search
@@ -114,7 +114,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
mapData = mainController.GetMapData();//获取路书信息
|
||||
|
||||
////获取海拔图UI对象
|
||||
//var graphObject = transform.parent.Find("SingleUI/Panel/GraphChart");
|
||||
//var graphObject = transform.parent.Find("UI/Panel/GraphChart");
|
||||
//chartDataSourceScript = graphObject.GetComponent<ChartDataSourceScript>();
|
||||
//graph = graphObject.GetComponent<GraphChartBase>();
|
||||
chartDataSourceScript = mainController.chartDataSourceScript;
|
||||
|
||||
@@ -16,67 +16,112 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class AbstratctLoadingController : MonoBehaviour
|
||||
{
|
||||
#region GameObject
|
||||
protected Text mapName;
|
||||
protected AbstractMap _map;
|
||||
protected Text level;
|
||||
protected Text mapName;
|
||||
protected AbstractMap _map { get; set; }
|
||||
protected MapApi mapApi { get; set; }
|
||||
protected RawImage mapRouteImage;
|
||||
protected CanvasGroup canvasGroup;
|
||||
protected Slider slider;
|
||||
protected Text processText;
|
||||
protected Text rideNowText;
|
||||
protected Button rideNow;
|
||||
protected Button cancel;
|
||||
protected Text mapDescText;
|
||||
protected Text distance;
|
||||
protected Text elevaction;
|
||||
protected Text slope;
|
||||
protected Text rideNum;
|
||||
protected Text uploadByUserName;
|
||||
protected Text processText;
|
||||
protected Text mapDescText;
|
||||
protected Text rideNowText;
|
||||
protected RawImage head;
|
||||
protected RawImage country;
|
||||
protected RawImage mapCountry;
|
||||
protected RawImage mapRouteImage;
|
||||
protected RawImage altitudeGraph;
|
||||
protected Button rideNow;
|
||||
protected Button cancel;
|
||||
protected MapApi mapApi { get; set; }
|
||||
protected GameObject panel;
|
||||
protected CanvasGroup canvasGroup;
|
||||
protected Transform mapRanking;
|
||||
protected Slider slider;
|
||||
#endregion
|
||||
protected GameObject loadingPanel;
|
||||
|
||||
protected GameObject loadingPanel { get; set; }
|
||||
|
||||
#region 属性
|
||||
protected float process = 0;//0-100 %
|
||||
public float targetAlpha = 0f;
|
||||
public float alphaSpeed = 2.0f;
|
||||
private bool depressFlag = false;
|
||||
|
||||
protected CyclingController cyclingController { get; set; }
|
||||
#endregion
|
||||
protected CyclingController cyclingController;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
App.TextureCache.Clear();
|
||||
loadingPanel = transform.Find("Panel/LoadingPanel").gameObject;
|
||||
loadingPanel.showLoadingExtension();
|
||||
mapApi = new MapApi();
|
||||
ShowLoading();
|
||||
}
|
||||
public void InjectController(CyclingController controller)
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (canvasGroup == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetAlpha != canvasGroup.alpha && depressFlag)
|
||||
{
|
||||
canvasGroup.alpha = Mathf.Lerp(canvasGroup.alpha, targetAlpha, alphaSpeed * Time.deltaTime);
|
||||
if (Mathf.Abs(targetAlpha - canvasGroup.alpha) <= 0.01f)
|
||||
{
|
||||
canvasGroup.alpha = targetAlpha;
|
||||
}
|
||||
if (canvasGroup.alpha == 0)
|
||||
{
|
||||
transform.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
//显示loading动画
|
||||
protected virtual void ShowLoading()
|
||||
{
|
||||
}
|
||||
//在awake前触发。注入主控制器并设置UIManager
|
||||
public virtual void InjectController(CyclingController controller)
|
||||
{
|
||||
cyclingController = controller;
|
||||
PFUIPanel mainPanel = transform.Find("Panel").GetComponent<PFUIPanel>();
|
||||
PFUIPanel modelPanel = transform.Find("ModalPanel").GetComponent<PFUIPanel>();
|
||||
cyclingController.SetUIManager(mainPanel, modelPanel);
|
||||
}
|
||||
//提供给主控制器初始化用
|
||||
public void Init(MapRoute route)
|
||||
//初始化
|
||||
public virtual void Init()
|
||||
{
|
||||
InitGameObject();
|
||||
InitGameObjectData(route);
|
||||
InitGameObjectData();
|
||||
}
|
||||
//展示当前路书图片
|
||||
public void SetMapRouteImage(string url)
|
||||
//加载界面
|
||||
protected virtual void InitGameObject()
|
||||
{
|
||||
Utils.DisplayImage(mapRouteImage, url);
|
||||
mapName = panel.transform.Find("MapName").GetComponent<Text>();
|
||||
distance = panel.transform.Find("Distance").GetComponent<Text>();
|
||||
elevaction = panel.transform.Find("Elevaction").GetComponent<Text>();
|
||||
slope = panel.transform.Find("Slope").GetComponent<Text>();
|
||||
mapRouteImage = panel.transform.Find("MapRouteImage").GetComponent<RawImage>();
|
||||
slider = panel.transform.Find("Process").GetComponent<Slider>();
|
||||
processText = panel.transform.Find("ProcessText").GetComponent<Text>();
|
||||
mapDescText = panel.transform.Find("MapDesc").GetComponent<Text>();
|
||||
rideNow = panel.transform.Find("RideNow").GetComponent<Button>();
|
||||
rideNowText = rideNow.transform.Find("Text").GetComponent<Text>();
|
||||
cancel = panel.transform.Find("Cancel").GetComponent<Button>();
|
||||
|
||||
var root = transform.parent;
|
||||
_map = root.Find("Map").GetComponent<AbstractMap>();
|
||||
_map.OnInitialized += _map_OnInitialized;
|
||||
|
||||
canvasGroup = transform.GetComponent<CanvasGroup>();
|
||||
rideNow.enabled = false;
|
||||
rideNow.interactable = false;
|
||||
UIManager.AddEvent(rideNow.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, StartRide);
|
||||
UIManager.AddEvent(cancel.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, Cancel);
|
||||
|
||||
}
|
||||
public async void DrawMapRouteAsync(int routeId)
|
||||
//加载数据
|
||||
protected virtual void InitGameObjectData()
|
||||
{
|
||||
|
||||
}
|
||||
//绘制地图
|
||||
public virtual async void DrawMapRouteAsync(int routeId,int type=0)
|
||||
{
|
||||
this.AddProcess(10);
|
||||
//var url = Helper.GetMapboxApiUrl(mapData.List);
|
||||
mapApi = new MapApi();
|
||||
var result = await mapApi.GetMapLoadingCoverageUrl(routeId);
|
||||
var result = await mapApi.GetMapLoadingCoverageUrl(routeId, type);
|
||||
if (!result.result)
|
||||
return;
|
||||
var url = result.data;
|
||||
@@ -85,38 +130,33 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
mapRouteImage.texture = App.TextureCache[url];
|
||||
var canvasGroup = mapRouteImage.GetComponent<CanvasGroup>();
|
||||
canvasGroup.DOFade(1, 1);
|
||||
//this.AddProcess(10);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.DisplayImageAysnc(StartCoroutine, mapRouteImage, url, dowloadCallBack);
|
||||
//this.AddProcess(10);
|
||||
else
|
||||
{
|
||||
Utils.DisplayImageAysnc(StartCoroutine, mapRouteImage, url, DowloadCallBack);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void dowloadCallBack(string url)
|
||||
protected void DowloadCallBack(string url)
|
||||
{
|
||||
if (!App.TextureCache.ContainsKey(url))
|
||||
{
|
||||
App.TextureCache.Add(url, mapRouteImage.texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
App.TextureCache[url] = mapRouteImage.texture;
|
||||
}
|
||||
var canvasGroup = mapRouteImage.GetComponent<CanvasGroup>();
|
||||
var canvasGroup = mapRouteImage.GetComponent<CanvasGroup>();
|
||||
canvasGroup.DOFade(1, 1);
|
||||
|
||||
}
|
||||
//设定当前loading进度
|
||||
public void AddProcess(float v)
|
||||
public virtual void AddProcess(float v)
|
||||
{
|
||||
process += v;
|
||||
slider.value = process;
|
||||
slider.onValueChanged.AddListener((f) =>
|
||||
{
|
||||
processText.text = $"{(f ).ToString("#0")}%";
|
||||
processText.text = $"{(f).ToString("#0")}%";
|
||||
});
|
||||
|
||||
if (process == 100)
|
||||
@@ -125,72 +165,18 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
rideNow.enabled = true;
|
||||
}
|
||||
}
|
||||
//创建排行榜
|
||||
public void CreateRankingList(List<MapRouteRanking> list)
|
||||
{
|
||||
var prefab = Resources.Load<GameObject>("UI/Prefab/Ride/RankingItem");
|
||||
var parent = transform.Find("Panel/MapRanking");
|
||||
var title = transform.Find("Panel/RankingTitle").gameObject;
|
||||
if (list.Count == 0)
|
||||
{
|
||||
title.SetActive(false);
|
||||
}
|
||||
foreach (var item in list)
|
||||
{
|
||||
GameObject newObj = (GameObject)Instantiate(prefab, parent);
|
||||
var selectPlayerItemScript = newObj.GetComponent<RankingItemScript>();
|
||||
selectPlayerItemScript.SetRanking(item.RowNumber.ToString());
|
||||
selectPlayerItemScript.SetName(item.NickName);
|
||||
selectPlayerItemScript.SetTimer(item.IsDNF?"DNF":item.TotalTime);
|
||||
selectPlayerItemScript.SetHead(item.WxHeadImg);
|
||||
var texture = cyclingController.GetCountryImageByCode(item.CountryCode);
|
||||
selectPlayerItemScript.SetCountry(texture);
|
||||
}
|
||||
}
|
||||
protected virtual void InitGameObject()
|
||||
{
|
||||
panel = transform.Find("Panel").gameObject;
|
||||
mapName = transform.Find("Panel/MapName").GetComponent<Text>();
|
||||
distance = transform.Find("Panel/Distance").GetComponent<Text>();
|
||||
level = transform.Find("Panel/level/Text").GetComponent<Text>();
|
||||
elevaction = transform.Find("Panel/Elevaction").GetComponent<Text>();
|
||||
slope = transform.Find("Panel/Slope").GetComponent<Text>();
|
||||
rideNum = transform.Find("Panel/RideNum").GetComponent<Text>();
|
||||
uploadByUserName = transform.Find("Panel/UploadByUserName").GetComponent<Text>();
|
||||
country = transform.Find("Panel/UploadByCountry").GetComponent<RawImage>();
|
||||
mapCountry = transform.Find("Panel/Country").GetComponent<RawImage>();
|
||||
|
||||
head = transform.Find("Panel/UploadByHead").GetComponent<RawImage>();
|
||||
mapRouteImage = transform.Find("Panel/MapRouteImage").GetComponent<RawImage>();
|
||||
altitudeGraph = transform.Find("Panel/AltitudeGraph").GetComponent<RawImage>();
|
||||
mapRanking = transform.Find("Panel/MapRanking");
|
||||
slider = transform.Find("Panel/Process").GetComponent<Slider>();
|
||||
processText = transform.Find("Panel/ProcessText").GetComponent<Text>();
|
||||
mapDescText = transform.Find("Panel/MapDesc").GetComponent<Text>();
|
||||
rideNow = transform.Find("Panel/RideNow").GetComponent<Button>();
|
||||
rideNowText = rideNow.transform.Find("Text").GetComponent<Text>();
|
||||
cancel = transform.Find("Panel/Cancel").GetComponent<Button>();
|
||||
var root = transform.parent;
|
||||
_map = root.Find("Map").GetComponent<AbstractMap>();
|
||||
canvasGroup = transform.GetComponent<CanvasGroup>();
|
||||
rideNow.enabled = false;
|
||||
rideNow.interactable = false;
|
||||
UIManager.AddEvent(rideNow.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, StartRide);
|
||||
UIManager.AddEvent(cancel.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, Cancel);
|
||||
|
||||
}
|
||||
protected virtual void StartRide(BaseEventData baseEvent)
|
||||
{
|
||||
var checkAnt = cyclingController.CheckAnt();
|
||||
#if UNITY_EDITOR
|
||||
checkAnt = true;
|
||||
checkAnt = true;
|
||||
#endif
|
||||
if (!checkAnt)
|
||||
{
|
||||
if (!checkAnt)
|
||||
{
|
||||
var alert = (GameObject)Instantiate(Resources.Load("UI/Prefab/Ride/Alert"), panel.transform);
|
||||
alert.SetActive(true);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
cyclingController.InitTcp();
|
||||
MapUDPService.SendGizpModel();
|
||||
@@ -200,44 +186,11 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
depressFlag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void Cancel(BaseEventData baseEvent)
|
||||
{
|
||||
SceneManager.LoadScene("MainScene");
|
||||
}
|
||||
protected void InitGameObjectData(MapRoute route)
|
||||
{
|
||||
if (route != null)
|
||||
{
|
||||
#region 绑定路书基本信息
|
||||
mapName.text = route.Name;
|
||||
level.text = route.Hard;
|
||||
elevaction.text = Math.Round(route.TotalClimb.GetValueOrDefault(0), 2).ToString() + "M";
|
||||
slope.text = Math.Round(route.AverageGrade, 2).ToString() + "%";
|
||||
rideNum.text = route.TheHeat.ToString();
|
||||
distance.text = route.Distance.ToString("f1") + "KM";
|
||||
mapDescText.text = route.Dec;
|
||||
var userList = ConfigHelper.mapApi.GetOnlineUserInfo(new int[] { route.UserId }).data;
|
||||
if (userList.Count > 0)
|
||||
{
|
||||
uploadByUserName.text = userList[0].Name;
|
||||
var countryUrl = App.Host + $"User/GetCountryImg?userid={userList[0].Id}";
|
||||
Utils.DisplayImage(head, userList[0].HeadImage);//头像
|
||||
|
||||
country.texture = cyclingController.GetCountryImageByCode(route.CountryCode);//上传者国家
|
||||
mapCountry.texture = cyclingController.GetCountryImageByName(userList[0].Country);//路书国家
|
||||
|
||||
Utils.DisplayImage(altitudeGraph, route.AltitudeGraph);//海拔图
|
||||
}
|
||||
#endregion
|
||||
StartCoroutine(HiddenLoading());
|
||||
#region 地图注册 排行榜等接口
|
||||
_map.OnInitialized += _map_OnInitialized;
|
||||
_map.OnEditorPreviewEnabled += OnEditorPreviewEnabled;
|
||||
_map.OnEditorPreviewDisabled += OnEditorPreviewDisabled;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
protected IEnumerator HiddenLoading()
|
||||
{
|
||||
yield return new WaitForSeconds(1f);
|
||||
@@ -254,37 +207,5 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
};
|
||||
}
|
||||
protected void OnEditorPreviewEnabled()
|
||||
{
|
||||
//transform.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
protected void OnEditorPreviewDisabled()
|
||||
{
|
||||
//transform.gameObject.SetActive(true);
|
||||
}
|
||||
public float targetAlpha = 0f;
|
||||
public float alphaSpeed = 2.0f;
|
||||
private bool depressFlag = false;
|
||||
void Update()
|
||||
{
|
||||
if (canvasGroup == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetAlpha != canvasGroup.alpha && depressFlag)
|
||||
{
|
||||
canvasGroup.alpha = Mathf.Lerp(canvasGroup.alpha, targetAlpha, alphaSpeed * Time.deltaTime);
|
||||
if (Mathf.Abs(targetAlpha - canvasGroup.alpha) <= 0.01f)
|
||||
{
|
||||
canvasGroup.alpha = targetAlpha;
|
||||
}
|
||||
if (canvasGroup.alpha == 0)
|
||||
{
|
||||
transform.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bccf1279e24ed4840896f68bc2bac5d1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,51 +0,0 @@
|
||||
using Assets.Scripts.Apis;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class CompetitionLoadingController : AbstratctLoadingController
|
||||
{
|
||||
private GameObject Watch;
|
||||
private bool hasJoin = false;
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
}
|
||||
//先报名后开始
|
||||
protected override void StartRide(BaseEventData baseEvent)
|
||||
{
|
||||
//先报名
|
||||
if (!hasJoin)
|
||||
{
|
||||
MapCompetitionApi s = new MapCompetitionApi();
|
||||
_ = s.ApplyMapCompetition(cyclingController.competitionId);
|
||||
rideNowText.text = "RideNow";
|
||||
hasJoin = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
base.StartRide(baseEvent);
|
||||
}
|
||||
}
|
||||
|
||||
protected void StartWatch(BaseEventData baseEvent)
|
||||
{
|
||||
//隐藏当前用户
|
||||
cyclingController.isWatch = true;
|
||||
cyclingController.player.SetActive(false);
|
||||
base.StartRide(baseEvent);
|
||||
}
|
||||
protected override void InitGameObject()
|
||||
{
|
||||
base.InitGameObject();
|
||||
//比赛相关数据绑定
|
||||
//显示报名按钮 观战按钮 TODO
|
||||
rideNowText.text = "Apply";
|
||||
Watch = transform.Find("Panel/Watch").gameObject;
|
||||
|
||||
UIManager.AddEvent(Watch, EventTriggerType.PointerClick, StartWatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bfe4d27e49e6bea4a88d5982e6e6aa19
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,137 +0,0 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class CompetitionRankingFactory : BaseListFactory
|
||||
{
|
||||
private bool isInit = false;
|
||||
private bool isnext = false;
|
||||
private List<CompetitionRankingSortModel> rankingList {get;set;}
|
||||
private AbstractPlayer currentPlayer { get; set; }
|
||||
private Text Title { get; set; }
|
||||
private Text OnlineUserNum { get; set; }
|
||||
private Text Rank { get; set; }
|
||||
private GameObject PreBtn { get; set; }
|
||||
private GameObject NextBtn { get; set; }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
//base.Awake();
|
||||
scroll = transform.Find("List").gameObject;
|
||||
if (scroll != null)
|
||||
{
|
||||
UIManager.AddEvent(scroll, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
|
||||
}
|
||||
parent = scroll.transform.Find("Viewport/Content");
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
playerController = FindObjectOfType<PlayerController>();
|
||||
currentPlayer = cyclingController.currentPlayer;
|
||||
nearByItem = Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingItem");
|
||||
nearByMajorItem = Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingMajorItem");
|
||||
Title = transform.Find("Title").GetComponent<Text>();
|
||||
OnlineUserNum = transform.Find("Head/OnlineUserNum").GetComponent<Text>();
|
||||
PreBtn = transform.Find("Pre").gameObject;//上一页
|
||||
NextBtn = transform.Find("Next").gameObject;//下一页
|
||||
Rank = transform.Find("Rank").GetComponent<Text>();
|
||||
UIManager.AddEvent(PreBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, PrePage);
|
||||
UIManager.AddEvent(NextBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, NextPage);
|
||||
}
|
||||
private void PrePage(BaseEventData baseEventData)
|
||||
{
|
||||
SetPreIndex();
|
||||
isInit = true;
|
||||
isnext = false;
|
||||
CreateList();
|
||||
}
|
||||
private void NextPage(BaseEventData baseEventData)
|
||||
{
|
||||
SetNextIndex();
|
||||
isInit = true;
|
||||
isnext = true;
|
||||
CreateList();
|
||||
}
|
||||
protected override void CreateList()
|
||||
{
|
||||
CompetitionModel s = cyclingController.cyclingController as CompetitionModel;
|
||||
var ss = s?.competitionRankingModel;
|
||||
rankingList = ss?.Sorts;
|
||||
|
||||
if (rankingList == null) return;
|
||||
//当前参赛总人数
|
||||
var totalCount = rankingList.Count();
|
||||
OnlineUserNum.text = totalCount.ToString();
|
||||
//当前用户排名
|
||||
var currentIndex = rankingList.Where(c => c.UserId == cyclingController.currentPlayer.UserId).FirstOrDefault()?.Index ?? 0;
|
||||
totalPages = (pageSize>0?totalCount / pageSize:0) + (totalCount % pageSize> 0? 1:0);
|
||||
if (!isInit)
|
||||
{
|
||||
//当前用户在第几页
|
||||
pageIndex = (pageSize > 0 ? currentIndex / pageSize : 0) + (totalCount % pageSize > 0 ? 1 : 0);
|
||||
}
|
||||
Rank.text = $"{pageIndex}/{totalPages}";
|
||||
var pagedList = rankingList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
||||
//删除
|
||||
var currentList = FindObjectsOfType<CompetitionRankingItem>();
|
||||
foreach (var item in currentList)
|
||||
{
|
||||
var e = pagedList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||
if (e == null)
|
||||
{
|
||||
item.transform.gameObject.SetActive(false);//TODO:这里暂时不删除,删除对应的图片和脚本依赖这个对象;脚本提供一个dispose
|
||||
bufferSize--;
|
||||
}
|
||||
}
|
||||
//创建或者新增
|
||||
for (int i = 0; i < pagedList.Count(); i++)
|
||||
{
|
||||
CreateOrUpdate(pagedList[i]);
|
||||
}
|
||||
|
||||
}
|
||||
private void CreateOrUpdate(CompetitionRankingSortModel item)
|
||||
{
|
||||
var rankingList = FindObjectsOfType<CompetitionRankingItem>();
|
||||
var competitionRankingItem = rankingList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||
//如果当前有这个用户则更新没有则创建并setslibingindex
|
||||
if (competitionRankingItem == null)
|
||||
{
|
||||
//创建
|
||||
if (bufferSize < pageSize)
|
||||
{
|
||||
//情况一:还有足够的buffer,直接创建
|
||||
GameObject prefabItem = cyclingController.currentPlayer.UserId == item.UserId ? nearByMajorItem : nearByItem;
|
||||
GameObject newObj = (GameObject)Instantiate(prefabItem, parent);
|
||||
competitionRankingItem = newObj.GetComponent<CompetitionRankingItem>();
|
||||
bufferSize++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//情况二:没有足够的buffer,找到要被淘汰的buffer()最后一名
|
||||
if (isnext) {
|
||||
competitionRankingItem = rankingList.OrderBy(c => c.rank).FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
competitionRankingItem = rankingList.OrderByDescending(c => c.rank).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
competitionRankingItem.setUserId(item.UserId);
|
||||
competitionRankingItem.SetRank(item.Index);
|
||||
competitionRankingItem.setName(item.Name);
|
||||
competitionRankingItem.setRatio(item.KGWeight + "W/KG");
|
||||
competitionRankingItem.setSpeed(item.Speed.ToString() + "KM/H");
|
||||
competitionRankingItem.setHead(item.Headimage);
|
||||
competitionRankingItem.setCountry(item.CountryImg);
|
||||
competitionRankingItem.setDistance(currentPlayer.UserId == item.UserId?"0KM": item.Near.ToString() + "KM");
|
||||
competitionRankingItem.transform.SetSiblingIndex(item.Index);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab8fe28fa979675468c81d99ce5ad389
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,123 +0,0 @@
|
||||
using Assets.Scripts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class CompetitionRankingItem : MonoBehaviour
|
||||
{
|
||||
private RawImage Head;
|
||||
private RawImage Country;
|
||||
private Image Background;
|
||||
private Text Name;
|
||||
private Text Speed;
|
||||
private Text Distance;
|
||||
private Text Ratio;//功体比
|
||||
private Text Rank;//当前排名
|
||||
private Text Timer;
|
||||
|
||||
private int _userId = 0;
|
||||
public int UserId { get { return _userId; } }
|
||||
private string _headUrl=string.Empty;
|
||||
private string _countryUrl = string.Empty;
|
||||
private string _name = string.Empty;
|
||||
private string _speed = string.Empty;
|
||||
private string _distance = string.Empty;
|
||||
private string _ratio = string.Empty;
|
||||
public int rank { get; set; }
|
||||
private Texture countryTexture;
|
||||
CyclingController cyclingController;
|
||||
Color selectedColor = new Color(0.9764706f, 0.1882353f, 0.5254902f);
|
||||
Color unselectedColor = new Color(0.2078431f, 0.2078431f, 0.2627451f);
|
||||
private void Awake()
|
||||
{
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
Background = transform.GetComponent<Image>();
|
||||
Head = transform.Find("Head").GetComponent<RawImage>();
|
||||
Country = transform.Find("Country").GetComponent<RawImage>();
|
||||
Name = transform.Find("Name").GetComponent<Text>();
|
||||
Speed = transform.Find("Speed").GetComponent<Text>();
|
||||
Distance = transform.Find("Distance").GetComponent<Text>();
|
||||
Ratio = transform.Find("Ratio").GetComponent<Text>();
|
||||
Rank = transform.Find("Rank").GetComponent<Text>();
|
||||
Timer = transform.Find("Timer")?.GetComponent<Text>();
|
||||
countryTexture = Resources.Load<Sprite>("Images/flag_China_Person").texture;
|
||||
UIManager.AddEvent(this.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, Watch);
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (cyclingController.currentPlayer.UserId == UserId)
|
||||
{
|
||||
Background.color = selectedColor;
|
||||
Ratio.color = Color.white;
|
||||
}
|
||||
else
|
||||
{
|
||||
Background.color = unselectedColor;
|
||||
}
|
||||
}
|
||||
|
||||
//切换到当前用户视角
|
||||
public void Watch(BaseEventData baseEventData)
|
||||
{
|
||||
cyclingController.ChangeCurrentPlayer(_userId);
|
||||
}
|
||||
public void setTimer(string timer)
|
||||
{
|
||||
Timer.text = timer;
|
||||
}
|
||||
public void setRatio(string ratio)
|
||||
{
|
||||
if (!_ratio.Equals(ratio))
|
||||
{
|
||||
Ratio.text = ratio;
|
||||
}
|
||||
}
|
||||
//设置当前排名
|
||||
public void SetRank(int rank)
|
||||
{
|
||||
Rank.text = rank.ToString().PadLeft(3,'0');
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
public void setHead(string url)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
{
|
||||
Utils.DisplayImage(Head, url, true);
|
||||
var rect = ((RectTransform)Head.transform).rect;
|
||||
Material material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
||||
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
|
||||
Head.material = material;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCountry(string url)
|
||||
{
|
||||
Utils.DisplayImage(Country, url, true);
|
||||
}
|
||||
public void setName(string name)
|
||||
{
|
||||
if (!_name.Equals(name))
|
||||
Name.text = name;
|
||||
}
|
||||
|
||||
public void setSpeed(string speed)
|
||||
{
|
||||
if (!_speed.Equals(speed))
|
||||
Speed.text = speed;
|
||||
}
|
||||
|
||||
public void setDistance(string distance)
|
||||
{
|
||||
if (!_distance.Equals(distance))
|
||||
Distance.text = distance;
|
||||
}
|
||||
|
||||
public void setUserId(int userId)
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 897973ae3dd02d545b786cae2278c710
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,64 +0,0 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using Assets.Scripts;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class CompetitionResultFactory: MonoBehaviour
|
||||
{
|
||||
int pageIndex = 1;
|
||||
int pageSize = 8;
|
||||
CyclingController cyclingController;
|
||||
private void Awake()
|
||||
{
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
var closeBtn = transform.Find("Close").gameObject;
|
||||
UIManager.AddEvent(closeBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Close);
|
||||
}
|
||||
|
||||
float time = 1;
|
||||
private void Update()
|
||||
{
|
||||
time -= Time.deltaTime;
|
||||
while (time < 0)
|
||||
{
|
||||
Refresh();
|
||||
time = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (cyclingController.cyclingController is CompetitionModel model)
|
||||
{
|
||||
var list = model?.competitionRankingModel?.Results;
|
||||
if (list == null) return;
|
||||
var parent = transform.Find("ScrollView/Viewport/Content");
|
||||
Utils.DestroyChildren(parent);
|
||||
|
||||
var pagedList = list.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
||||
foreach (var item in pagedList)
|
||||
{
|
||||
var finalRankingItem = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/FinalRankingItem"), parent);
|
||||
var finalRankingItemScript = finalRankingItem.GetComponent<FinalRankingItemScript>();
|
||||
finalRankingItemScript.setRanking(item.Index.ToString());
|
||||
finalRankingItemScript.setHeartRate(item.HeartRate.ToString("f0"));
|
||||
finalRankingItemScript.setName(item.Name);
|
||||
finalRankingItemScript.setPower(item.Power.ToString());
|
||||
finalRankingItemScript.setRatio(item.WeightKg.ToString("f2"));
|
||||
finalRankingItemScript.setTimer(item.TripTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Close(BaseEventData baseEventData)
|
||||
{
|
||||
this.gameObject.SetActive(false);
|
||||
this.Destroy();
|
||||
//SceneManager.LoadScene("MainScene");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53789e6465db91d43adaa58df5c0e72d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,170 +0,0 @@
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using UnityEngine.EventSystems;
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class CompetitionUIManager : BaseUIManager
|
||||
{
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
GameObject countDownPanel;
|
||||
Text title;
|
||||
Text timer;
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
//创建倒计时面板
|
||||
countDownPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CountDownPanel"), transform.Find("Panel"));
|
||||
title = countDownPanel.transform.Find("Title").GetComponent<Text>();
|
||||
timer = countDownPanel.transform.Find("Timer").GetComponent<Text>();
|
||||
reviewPanel.SetActive(false);
|
||||
countDownPanel.SetActive(false);
|
||||
ShowCurrentRanking();
|
||||
}
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
CountDown();
|
||||
}
|
||||
|
||||
//开始游戏触发事件
|
||||
public void StartRide(BaseEventData baseEventData)
|
||||
{
|
||||
this.StartRide();
|
||||
}
|
||||
CompetitionModel competitionModel;
|
||||
bool canStart = false;
|
||||
//开始骑行-加个5秒钟倒计时
|
||||
public override void StartRide()
|
||||
{
|
||||
competitionModel = mainController.cyclingController as CompetitionModel;
|
||||
}
|
||||
|
||||
private void CountDown()
|
||||
{
|
||||
miniMap.SetActive(false); //隐藏小地图
|
||||
viewButton.gameObject.SetActive(false);//隐藏切换视角
|
||||
headPanel.SetActive(!mainController.isWatch); //隐藏海拔图观察者的头像
|
||||
|
||||
//比赛进行中
|
||||
if (competitionModel != null)
|
||||
{
|
||||
count = competitionModel.StartCountdown();
|
||||
canStart = competitionModel.CanStart();
|
||||
//比赛开始前倒计时
|
||||
if (count >= 0 && !canStart && !competitionModel.recorderData.Saved)
|
||||
{
|
||||
//显示倒计时面板信息
|
||||
showCountDown(count, "Get ready!");
|
||||
//隐藏坡度
|
||||
currentSlopePanel.SetActive(false);
|
||||
nextSlopePanel.SetActive(false);
|
||||
}
|
||||
//比赛开始
|
||||
if (count <= 0 && canStart)
|
||||
{
|
||||
mainController.SetStart();
|
||||
countDownPanel.SetActive(false);
|
||||
}
|
||||
//显示结果(非观战到达终点弹窗)
|
||||
var ishowResult = !mainController.isWatch && (competitionModel.mapCompetition?.HasRecord ?? false) || competitionModel.recorderData.Saved;
|
||||
if (ishowResult)
|
||||
{
|
||||
ShowResultList();
|
||||
}
|
||||
var s = competitionModel?.EndCountDown();
|
||||
//显示关门时间
|
||||
if (s.Value.Item2)
|
||||
{
|
||||
if (s.Value.Item1 <= 0 && !mainController.cyclingController.recorderData.Saved)
|
||||
{
|
||||
//自动保存,游戏设置结束
|
||||
SaveRide(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
//显示倒计时面板信息
|
||||
showCountDown(s.Value.Item1, "get the winner,end tance remains");
|
||||
}
|
||||
}
|
||||
else if (s.Value.Item1 > 0)
|
||||
{
|
||||
//显示倒计时面板信息
|
||||
showCountDown(s.Value.Item1, "remaining");
|
||||
}
|
||||
////显示关门时间
|
||||
//if (s.Value.Item2 && s.Value.Item1 <= 0 && !mainController.cyclingController.recorderData.Saved)
|
||||
//{
|
||||
// //自动保存,游戏设置结束
|
||||
// SaveRide(null);
|
||||
//}
|
||||
//var title = s.Value.Item2 && s.Value.Item1 <= 0 ? "finish" : "remaining";
|
||||
////显示倒计时面板信息
|
||||
//showCountDown(s.Value.Item1, title);
|
||||
//显示当前比赛进行多长时间了
|
||||
timerTxt.text = competitionModel.ShowTime;
|
||||
}
|
||||
}
|
||||
|
||||
private void showCountDown(int count,string text)
|
||||
{
|
||||
countDownPanel.SetActive(true);
|
||||
title.text = text;
|
||||
if (count >= 0)
|
||||
{
|
||||
timer.text = Helper.FormatTicks(count);
|
||||
}
|
||||
}
|
||||
|
||||
public override void SaveRide(BaseEventData baseEventData)
|
||||
{
|
||||
if (!mainController.isQuit)
|
||||
{
|
||||
mainController.SetQuit();
|
||||
playerController.Upload();
|
||||
quitPanel.SetActive(false);
|
||||
}
|
||||
ShowResultList();//保存显示当前排名
|
||||
}
|
||||
|
||||
public override void ContinueRide()
|
||||
{
|
||||
mainController.SetCyclingModel(CyclingModel.Competition);
|
||||
}
|
||||
public override void PauseRide(BaseEventData baseEventData)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//实时显示当前比赛排名
|
||||
GameObject competitionRankingList;
|
||||
public void ShowCurrentRanking()
|
||||
{
|
||||
if (competitionRankingList == null)
|
||||
{
|
||||
competitionRankingList = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingPanel"), transform.Find("Panel"));
|
||||
}
|
||||
if (topRankPanel == null)
|
||||
{
|
||||
topRankPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/TopRankPanel"), transform.Find("Panel"));
|
||||
}
|
||||
}
|
||||
GameObject competitionResultPanel;
|
||||
GameObject topRankPanel;
|
||||
//实时刷新显示比赛结果
|
||||
public void ShowResultList()
|
||||
{
|
||||
if (competitionResultPanel == null)
|
||||
{
|
||||
competitionResultPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CompetitionResultPanel"), transform.Find("Panel"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56d863ea131204b4682725335a6af540
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,62 +0,0 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using Assets.Scripts;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class CompetitionWatcherFactory : MonoBehaviour
|
||||
{
|
||||
int pageIndex = 1;
|
||||
int pageSize = 8;
|
||||
CyclingController cyclingController;
|
||||
private void start()
|
||||
{
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
}
|
||||
|
||||
float time = 1;
|
||||
private void Update()
|
||||
{
|
||||
time -= Time.deltaTime;
|
||||
while (time < 0)
|
||||
{
|
||||
Refresh();
|
||||
time = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (cyclingController.cyclingController is CompetitionModel model)
|
||||
{
|
||||
var list = model?.competitionRankingModel?.Results;
|
||||
if (list == null) return;
|
||||
var parent = transform.Find("ScrollView/Viewport/Content");
|
||||
Utils.DestroyChildren(parent);
|
||||
|
||||
var pagedList = list.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
||||
foreach (var item in pagedList)
|
||||
{
|
||||
var finalRankingItem = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/FinalRankingItem"), parent);
|
||||
var finalRankingItemScript = finalRankingItem.GetComponent<FinalRankingItemScript>();
|
||||
finalRankingItemScript.setRanking(item.Index.ToString());
|
||||
finalRankingItemScript.setHeartRate(item.HeartRate.ToString("f0"));
|
||||
finalRankingItemScript.setName(item.Name);
|
||||
finalRankingItemScript.setPower(item.Power.ToString());
|
||||
finalRankingItemScript.setRatio(item.WeightKg.ToString("f2"));
|
||||
finalRankingItemScript.setTimer(item.TripTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Close(BaseEventData baseEventData)
|
||||
{
|
||||
this.gameObject.SetActive(false);
|
||||
this.Destroy();
|
||||
//SceneManager.LoadScene("MainScene");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 911cdbf2d21e6bc4f8713d8440ea06d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,89 +0,0 @@
|
||||
using Assets.Scripts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class FinalRankingItemScript : MonoBehaviour
|
||||
{
|
||||
private RawImage Head;
|
||||
private RawImage Country;
|
||||
private Text Name;
|
||||
private Text Power;
|
||||
private Text Timer;
|
||||
private Text Ratio;//功体比
|
||||
private Text Ranking;
|
||||
private Text HeartRate;
|
||||
|
||||
private int _userId = 0;
|
||||
public int UserId { get { return _userId; } }
|
||||
private Texture countryTexture;
|
||||
private void Awake()
|
||||
{
|
||||
Head = transform.Find("Head").GetComponent<RawImage>();
|
||||
Country = transform.Find("Country").GetComponent<RawImage>();
|
||||
Name = transform.Find("Name").GetComponent<Text>();
|
||||
HeartRate = transform.Find("Heart").GetComponent<Text>();
|
||||
Power = transform.Find("Power").GetComponent<Text>();
|
||||
Timer = transform.Find("Timer").GetComponent<Text>();
|
||||
Ratio = transform.Find("WKG").GetComponent<Text>();
|
||||
Ranking = transform.Find("Ranking").GetComponent<Text>();
|
||||
countryTexture = Resources.Load<Sprite>("Images/flag_China_Person").texture;
|
||||
}
|
||||
|
||||
public void setRatio(string ratio)
|
||||
{
|
||||
Ratio.text = ratio +"W/KG";
|
||||
}
|
||||
|
||||
public void setHead(string url)
|
||||
{
|
||||
Utils.DisplayImage(Head, url, true);
|
||||
var rect = ((RectTransform)Head.transform).rect;
|
||||
Material material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
||||
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
|
||||
Head.material = material;
|
||||
}
|
||||
|
||||
public void setCountry(Texture texture)
|
||||
{
|
||||
Country.texture = texture;
|
||||
}
|
||||
public void setName(string name)
|
||||
{
|
||||
Name.text = name;
|
||||
}
|
||||
|
||||
public void setPower(string power)
|
||||
{
|
||||
Power.text = power +"W";
|
||||
|
||||
}
|
||||
public void setTimer(string timer)
|
||||
{
|
||||
Timer.text = timer;
|
||||
}
|
||||
|
||||
public void setRanking(string ranking)
|
||||
{
|
||||
Ranking.text = ranking;
|
||||
}
|
||||
|
||||
public void setHeartRate(string heartRate)
|
||||
{
|
||||
if (!heartRate.Equals("0"))
|
||||
{
|
||||
HeartRate.text = heartRate + "bpm";
|
||||
}
|
||||
else
|
||||
{
|
||||
HeartRate.text = "--bpm";
|
||||
}
|
||||
}
|
||||
|
||||
public void setUserId(int userId)
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e64a5b2fb6d4f3418094195460237d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,76 +0,0 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class TopRankingFactory : BaseListFactory
|
||||
{
|
||||
private List<CompetitionRankingSortModel> rankingList {get;set;}
|
||||
private AbstractPlayer currentPlayer { get; set; }
|
||||
private int topSize = 6;//取前6名
|
||||
protected override void Awake()
|
||||
{
|
||||
//base.Awake();
|
||||
scroll = transform.Find("List").gameObject;
|
||||
if (scroll != null)
|
||||
{
|
||||
UIManager.AddEvent(scroll, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
|
||||
}
|
||||
parent = scroll.transform.Find("Viewport/Content");
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
playerController = FindObjectOfType<PlayerController>();
|
||||
currentPlayer = cyclingController.currentPlayer;
|
||||
nearByItem = Resources.Load<GameObject>("UI/Prefab/Match/TopRankingItem");
|
||||
nearByMajorItem = Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingMajorItem");
|
||||
}
|
||||
|
||||
protected override void CreateList()
|
||||
{
|
||||
CompetitionModel s = cyclingController.cyclingController as CompetitionModel;
|
||||
var ss = s?.competitionRankingModel;
|
||||
rankingList = ss?.Sorts;
|
||||
if (rankingList == null) return;
|
||||
var pagedList = rankingList.Take(topSize).ToList();
|
||||
for (int i = 0; i < pagedList.Count(); i++)
|
||||
{
|
||||
Create(pagedList[i]);
|
||||
}
|
||||
}
|
||||
private void Create(CompetitionRankingSortModel item)
|
||||
{
|
||||
var rankingList = FindObjectsOfType<TopRankingItem>();
|
||||
var competitionRankingItem = rankingList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||
//如果当前有这个用户则更新没有则创建并setslibingindex
|
||||
if (competitionRankingItem == null)
|
||||
{
|
||||
//创建
|
||||
if (bufferSize < pageSize)
|
||||
{
|
||||
//情况一:还有足够的buffer,直接创建
|
||||
GameObject prefabItem = nearByItem;
|
||||
GameObject newObj = (GameObject)Instantiate(prefabItem, parent);
|
||||
competitionRankingItem = newObj.GetComponent<TopRankingItem>();
|
||||
bufferSize++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//情况二:没有足够的buffer,找到要被淘汰的buffer()最后一名
|
||||
competitionRankingItem = rankingList.OrderByDescending(c => c.rank).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
competitionRankingItem.setUserId(item.UserId);
|
||||
competitionRankingItem.SetRank(item.Index);
|
||||
competitionRankingItem.setName(item.Name);
|
||||
competitionRankingItem.setRatio(item.KGWeight + "W/KG");
|
||||
competitionRankingItem.setSpeed(item.Speed.ToString() + "KM/H");
|
||||
competitionRankingItem.setHead(item.Headimage);
|
||||
competitionRankingItem.setCountry(item.CountryImg);
|
||||
competitionRankingItem.setDistance(item.Near.ToString() + "KM");
|
||||
competitionRankingItem.transform.SetSiblingIndex(item.Index);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3903e9a2640d3447af0b98a0d6ce664
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,116 +0,0 @@
|
||||
using Assets.Scripts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class TopRankingItem : MonoBehaviour
|
||||
{
|
||||
private RawImage Head;
|
||||
private RawImage Country;
|
||||
private Image Background;
|
||||
private Text Name;
|
||||
private Text Speed;
|
||||
private Text Distance;
|
||||
private Text Ratio;//功体比
|
||||
private Text Rank;//当前排名
|
||||
private Text Timer;
|
||||
|
||||
private int _userId = 0;
|
||||
public int UserId { get { return _userId; } }
|
||||
private string _headUrl = string.Empty;
|
||||
private string _countryUrl = string.Empty;
|
||||
private string _name = string.Empty;
|
||||
private string _speed = string.Empty;
|
||||
private string _distance = string.Empty;
|
||||
private string _ratio = string.Empty;
|
||||
public int rank { get; set; }
|
||||
private Texture countryTexture;
|
||||
CyclingController cyclingController;
|
||||
private void Awake()
|
||||
{
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
Background = transform.GetComponent<Image>();
|
||||
Head = transform.Find("Head").GetComponent<RawImage>();
|
||||
Country = transform.Find("Country").GetComponent<RawImage>();
|
||||
Name = transform.Find("Name").GetComponent<Text>();
|
||||
Speed = transform.Find("Speed").GetComponent<Text>();
|
||||
Distance = transform.Find("Distance").GetComponent<Text>();
|
||||
Ratio = transform.Find("Ratio").GetComponent<Text>();
|
||||
Rank = transform.Find("Rank").GetComponent<Text>();
|
||||
Timer = transform.Find("Timer")?.GetComponent<Text>();
|
||||
countryTexture = Resources.Load<Sprite>("Images/flag_China_Person").texture;
|
||||
var btn = this.gameObject.GetComponent<Button>();
|
||||
btn.onClick.AddListener(() =>
|
||||
{
|
||||
Watch();
|
||||
});
|
||||
///UIManager.AddEvent(this.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, Watch);
|
||||
}
|
||||
//切换到当前用户视角
|
||||
public void Watch()
|
||||
{
|
||||
cyclingController.ChangeCurrentPlayer(_userId);
|
||||
}
|
||||
public void setTimer(string timer)
|
||||
{
|
||||
Timer.text = timer;
|
||||
}
|
||||
public void setRatio(string ratio)
|
||||
{
|
||||
if (!_ratio.Equals(ratio))
|
||||
{
|
||||
Ratio.text = ratio;
|
||||
}
|
||||
}
|
||||
//设置当前排名
|
||||
public void SetRank(int rank)
|
||||
{
|
||||
Rank.text = rank.ToString();
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
public void setHead(string url)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
{
|
||||
Utils.DisplayImage(Head, url, true);
|
||||
var rect = ((RectTransform)Head.transform).rect;
|
||||
Material material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
||||
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
|
||||
Head.material = material;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCountry(string url)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
{
|
||||
Utils.DisplayImage(Country, url, true);
|
||||
}
|
||||
}
|
||||
public void setName(string name)
|
||||
{
|
||||
if (!_name.Equals(name))
|
||||
Name.text = name;
|
||||
}
|
||||
|
||||
public void setSpeed(string speed)
|
||||
{
|
||||
if (!_speed.Equals(speed))
|
||||
Speed.text = speed;
|
||||
}
|
||||
|
||||
public void setDistance(string distance)
|
||||
{
|
||||
if (!_distance.Equals(distance))
|
||||
Distance.text = distance;
|
||||
}
|
||||
|
||||
public void setUserId(int userId)
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2338fbdbfd33753468194151f9b88760
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -36,8 +36,9 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
public int preticks;
|
||||
|
||||
#region 参数
|
||||
private MapRoute mapRoute;//当前路书数据
|
||||
private MapDataModel mapData;//当前路书数据
|
||||
public MapRoute mapRoute { get; set; }//当前路书数据
|
||||
public MapCompetition competition { get; set; }//当前赛事数据
|
||||
private MapDataModel mapData { get; set; }//当前路书数据
|
||||
private Route route;//当前路书综合数据
|
||||
public List<MapRouteRanking> mapRouteRankingList { get; set; }
|
||||
private Vector2d coordiantes;//当前地图中心
|
||||
@@ -79,10 +80,10 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
routeId = App.RouteIdParam > 0? App.RouteIdParam : 2633;
|
||||
//mapRoute = mapApi.GetById(routeId).data;
|
||||
//miniMap = transform.Find("MiniMap").gameObject;//小地图
|
||||
resultPanel = transform.Find("SingleUI/Panel/ResultPanel").gameObject;
|
||||
resultPanel = transform.Find("UI/Panel/ResultPanel").gameObject;
|
||||
|
||||
//获取海拔图UI对象
|
||||
var graphObject = transform.Find("SingleUI/Panel/GraphChart");
|
||||
var graphObject = transform.Find("UI/Panel/GraphChart");
|
||||
chartDataSourceScript = graphObject.GetComponent<ChartDataSourceScript>();
|
||||
graph = graphObject.GetComponent<GraphChartBase>();
|
||||
|
||||
@@ -99,14 +100,14 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
Transform uiParent;
|
||||
private void Start()
|
||||
{
|
||||
UIManager.Instance.MainPanel = this.transform.Find("SingleUI/Panel").GetComponent<PFUIPanel>();
|
||||
UIManager.Instance.ModalsPanel = this.transform.Find("SingleUI/ModalPanel").GetComponent<PFUIPanel>();
|
||||
UIManager.Instance.MainPanel = this.transform.Find("UI/Panel").GetComponent<PFUIPanel>();
|
||||
UIManager.Instance.ModalsPanel = this.transform.Find("UI/ModalPanel").GetComponent<PFUIPanel>();
|
||||
onlineUserPrefab = Resources.Load<GameObject>("UI/Prefab/Match/OnlinePlayer");
|
||||
miniMapPlayerPrefab = Resources.Load<GameObject>("UI/Prefab/Ride/MiniMapPlayer");
|
||||
watcher = Resources.Load<GameObject>("UI/Prefab/Match/Watcher");
|
||||
target = transform.Find("Target");
|
||||
miniMap = transform.Find("MiniMap").gameObject;//小地图
|
||||
uiParent = transform.Find("SingleUI/Panel");
|
||||
uiParent = transform.Find("UI/Panel");
|
||||
//进入倒计时
|
||||
singleUIManager = UIObject.GetComponent<BaseUIManager>();
|
||||
TrailRenderer trail = player.GetComponent<TrailRenderer>();
|
||||
@@ -155,7 +156,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
{
|
||||
yield return new WaitForSeconds(1);
|
||||
mapRoute = mapApi.GetById(routeId).data;
|
||||
loadingController.Init(mapRoute);//初始化loading页面
|
||||
loadingController.Init();//初始化loading页面
|
||||
loadingController.AddProcess(10);
|
||||
InitData();//初始化数据
|
||||
InitGameObject();//初始化场景
|
||||
@@ -168,7 +169,9 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
{
|
||||
yield return new WaitForSeconds(1);
|
||||
mapRoute = mapApi.GetById(routeId).data;
|
||||
loadingController.Init(mapRoute);//初始化loading页面
|
||||
var mapCompetitionApi = new MapCompetitionApi();
|
||||
competition = mapCompetitionApi.GetById(competitionId).data;
|
||||
loadingController.Init();//初始化loading页面
|
||||
loadingController.AddProcess(10);
|
||||
InitRaceData();//初始化比赛数据
|
||||
InitRaceGameObject();//初始化比赛场景
|
||||
@@ -213,19 +216,19 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
App.routeResult = null;
|
||||
|
||||
#endregion
|
||||
//异步请求mapbox画出当前路书路线图
|
||||
loadingController.DrawMapRouteAsync(mapRoute.Id);
|
||||
////异步请求mapbox画出当前路书路线图
|
||||
//loadingController.DrawMapRouteAsync(mapRoute.Id);
|
||||
//loadingController.AddProcess(10);
|
||||
//计算上次骑行距离调整地图中心点
|
||||
double endDistance = selectParamModel.EndDistance;
|
||||
coordiantes = Along(endDistance);
|
||||
loadingController.AddProcess(10);
|
||||
//查询排行榜
|
||||
var list = mapApi.GetRouteRanking(App.RouteIdParam, "1", 0, 10, "");
|
||||
if (list.result)
|
||||
{
|
||||
loadingController.CreateRankingList(list.data.list);
|
||||
loadingController.AddProcess(10);
|
||||
}
|
||||
////查询排行榜
|
||||
//var list = mapApi.GetRouteRanking(App.RouteIdParam, "1", 0, 10, "");
|
||||
//if (list.result)
|
||||
//{
|
||||
// loadingController.CreateRankingList(list.data.list);
|
||||
// loadingController.AddProcess(10);
|
||||
//}
|
||||
var shaowList = mapApi.GetShadowList(App.RouteIdParam, "", 0, 10);
|
||||
if (shaowList.result)
|
||||
{
|
||||
@@ -233,16 +236,12 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
}
|
||||
}
|
||||
|
||||
private MapCompetition competition;
|
||||
private void InitRaceData()
|
||||
{
|
||||
mapData = mapApi.GetData(routeId);//获取路书地理数据
|
||||
route = new Route(mapData, mapRoute);
|
||||
loadingController.AddProcess(10);
|
||||
#region 其他场景传参处理
|
||||
MapCompetitionApi mapCompetitionApi = new MapCompetitionApi();
|
||||
competition = mapCompetitionApi.GetById(competitionId).data;
|
||||
|
||||
selectParamModel = new RouteResultParam
|
||||
{
|
||||
CompetitionId = competitionId,
|
||||
@@ -256,25 +255,10 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
};
|
||||
|
||||
#endregion
|
||||
//异步请求mapbox画出当前路书路线图
|
||||
loadingController.DrawMapRouteAsync(mapRoute.Id);
|
||||
|
||||
//计算上次骑行距离调整地图中心点
|
||||
double endDistance = selectParamModel.EndDistance;
|
||||
coordiantes = Along(endDistance);
|
||||
loadingController.AddProcess(10);
|
||||
#region 查询排行榜
|
||||
var list = mapApi.GetRouteRanking(App.RouteIdParam, "1", 0, 10, "");
|
||||
if (list.result)
|
||||
{
|
||||
loadingController.CreateRankingList(list.data.list);
|
||||
loadingController.AddProcess(10);
|
||||
}
|
||||
var shaowList = mapApi.GetShadowList(App.RouteIdParam, "", 0, 10);
|
||||
if (shaowList.result)
|
||||
{
|
||||
mapRouteRankingList = shaowList.data.list;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
private Vector3 mapPos = Vector3.zero;
|
||||
@@ -334,6 +318,9 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
public AbstractPlayer currentPlayer { get; set; }
|
||||
|
||||
private GameObject onlinePlayer { get; set; }
|
||||
|
||||
Vector3 MAX_SIZE = new Vector3(3f, 3f, 3f);
|
||||
Vector3 MIN_SIZE = new Vector3(0.1f, 0.1f, 0.1f);
|
||||
public void ChangeCurrentPlayer(int userId)
|
||||
{
|
||||
var coll = FindObjectsOfType<AbstractPlayer>();
|
||||
@@ -341,14 +328,16 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
if (selectedPlayer != null)
|
||||
{
|
||||
currentPlayer = selectedPlayer;
|
||||
selectedPlayer.transform.localScale = new Vector3(3f, 3f, 3f);
|
||||
selectedPlayer.transform.localScale = Is3dView? MAX_SIZE : MIN_SIZE;
|
||||
}
|
||||
|
||||
var unselectedPlayers = coll.Where(c => c.UserId != userId).ToList();
|
||||
foreach (var item in unselectedPlayers)
|
||||
{
|
||||
item.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
|
||||
item.transform.localScale = MIN_SIZE;
|
||||
}
|
||||
//重置海拔图进度
|
||||
graph.HorizontalScrolling = 0;
|
||||
}
|
||||
public void ChangeRandomPlayer()
|
||||
{
|
||||
@@ -489,7 +478,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
if (bakePlayer != null)
|
||||
bakePlayer.IsShowInfo = true;
|
||||
}
|
||||
GameObject watcherList;
|
||||
GameObject watcherList { get; set; }
|
||||
//当前比赛观看者
|
||||
private void ShowWatchers()
|
||||
{
|
||||
@@ -498,28 +487,24 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
watcherList = Resources.Load<GameObject>("UI/Prefab/Match/WatcherPanel");
|
||||
watcherList = Instantiate(watcherList, uiParent);
|
||||
}
|
||||
var content = watcherList.transform.Find("List/Viewport/Content");
|
||||
var watchList = MapUDPService.GetCompetitionWatchers(competitionId);
|
||||
Utils.DestroyChildren(content);
|
||||
foreach (var item in watchList)
|
||||
{
|
||||
var head = Instantiate(watcher, content);
|
||||
var headiamge = head.GetComponent<RawImage>();
|
||||
Utils.DisplayImage(headiamge, item.HeadImage, true);
|
||||
}
|
||||
}
|
||||
//查询赛事观看者列表(取前5)
|
||||
public List<OnlineUser> GetWatcherList()
|
||||
{
|
||||
return MapUDPService.GetCompetitionWatchers(competitionId);
|
||||
}
|
||||
#endregion
|
||||
|
||||
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>();
|
||||
UIManager.Instance.MainPanel = mainPanel;
|
||||
UIManager.Instance.ModalsPanel = model;
|
||||
}
|
||||
|
||||
public void ReSetUIManager()
|
||||
{
|
||||
UIManager.Instance.MainPanel = this.transform.Find("SingleUI/Panel").GetComponent<PFUIPanel>();
|
||||
UIManager.Instance.ModalsPanel = this.transform.Find("SingleUI/ModalPanel").GetComponent<PFUIPanel>();
|
||||
UIManager.Instance.MainPanel = this.transform.Find("UI/Panel").GetComponent<PFUIPanel>();
|
||||
UIManager.Instance.ModalsPanel = this.transform.Find("UI/ModalPanel").GetComponent<PFUIPanel>();
|
||||
}
|
||||
|
||||
public void AddEvent(GameObject sender, EventTriggerType eventType, UnityAction<BaseEventData> unityAction)
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
var screenBounds = GetScreenBounds();
|
||||
var z = SetZoomToFitBounds(targetbounds, screenBounds);
|
||||
}
|
||||
RectRoot = transform.parent.Find("SingleUI/Panel/MiniMap/MiniMap").GetComponent<RectTransform>();
|
||||
RectRoot = transform.parent.Find("UI/Panel/MiniMap/MiniMap").GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
trail = transform.parent.Find("Sphere").GetComponent<TrailRenderer>();
|
||||
@@ -57,7 +57,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
if (playerController != null)
|
||||
{
|
||||
var tr = transform.parent.Find("SingleUI/Panel/MiniMap/MiniMap/arrow");
|
||||
var tr = transform.parent.Find("UI/Panel/MiniMap/MiniMap/arrow");
|
||||
tr.SetSiblingIndex(9999);
|
||||
var pos = _map.GeoToWorldPosition(playerController.Currentlatlong);
|
||||
pos.y += 15f;
|
||||
|
||||
@@ -1,24 +1,116 @@
|
||||
using UnityEngine;
|
||||
using Mapbox.Unity.Map;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Scripts.Apis;
|
||||
using System;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.Collections;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
|
||||
//[ExecuteInEditMode]
|
||||
public class LoadingController : AbstratctLoadingController
|
||||
{
|
||||
#region GameObject
|
||||
|
||||
protected Text level;
|
||||
protected Text rideNum;
|
||||
protected Text uploadByUserName;
|
||||
protected RawImage head;
|
||||
protected RawImage country;
|
||||
protected RawImage mapCountry;
|
||||
protected RawImage altitudeGraph;
|
||||
protected Transform mapRanking;
|
||||
#endregion
|
||||
|
||||
public override void InjectController(CyclingController controller)
|
||||
{
|
||||
|
||||
panel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/LoadingPanel"), transform);
|
||||
cyclingController = controller;
|
||||
PFUIPanel mainPanel = panel.GetComponent<PFUIPanel>();
|
||||
PFUIPanel modelPanel = transform.Find("ModalPanel").GetComponent<PFUIPanel>();
|
||||
cyclingController.SetUIManager(mainPanel, modelPanel);
|
||||
}
|
||||
|
||||
protected override void ShowLoading()
|
||||
{
|
||||
loadingPanel = panel.transform.Find("LoadingPanel").gameObject;
|
||||
loadingPanel.showLoadingExtension();
|
||||
}
|
||||
//初始化
|
||||
public override void Init()
|
||||
{
|
||||
InitGameObject();
|
||||
InitGameObjectData();
|
||||
}
|
||||
protected override void InitGameObject()
|
||||
{
|
||||
base.InitGameObject();
|
||||
level = panel.transform.Find("level/Text").GetComponent<Text>();
|
||||
rideNum = panel.transform.Find("RideNum").GetComponent<Text>();
|
||||
uploadByUserName = panel.transform.Find("UploadByUserName").GetComponent<Text>();
|
||||
country = panel.transform.Find("UploadByCountry").GetComponent<RawImage>();
|
||||
mapCountry = panel.transform.Find("Country").GetComponent<RawImage>();
|
||||
head = panel.transform.Find("UploadByHead").GetComponent<RawImage>();
|
||||
altitudeGraph = panel.transform.Find("AltitudeGraph").GetComponent<RawImage>();
|
||||
mapRanking = panel.transform.Find("MapRanking");
|
||||
}
|
||||
protected override void InitGameObjectData()
|
||||
{
|
||||
var route = cyclingController.mapRoute;
|
||||
#region 绑定路书基本信息
|
||||
mapName.text = route.Name;
|
||||
level.text = route.Hard;
|
||||
elevaction.text = Math.Round(route.TotalClimb.GetValueOrDefault(0), 2).ToString() + "M";
|
||||
slope.text = Math.Round(route.AverageGrade, 2).ToString() + "%";
|
||||
rideNum.text = route.TheHeat.ToString();
|
||||
distance.text = route.Distance.ToString("f1") + "KM";
|
||||
mapDescText.text = route.Dec;
|
||||
var userList = ConfigHelper.mapApi.GetOnlineUserInfo(new int[] { route.UserId }).data;
|
||||
if (userList.Count > 0)
|
||||
{
|
||||
uploadByUserName.text = userList[0].Name;
|
||||
var countryUrl = App.Host + $"User/GetCountryImg?userid={userList[0].Id}";
|
||||
Utils.DisplayImage(head, userList[0].HeadImage);//头像
|
||||
country.texture = cyclingController.GetCountryImageByCode(route.CountryCode);//上传者国家
|
||||
mapCountry.texture = cyclingController.GetCountryImageByName(userList[0].Country);//路书国家
|
||||
Utils.DisplayImage(altitudeGraph, route.AltitudeGraph);//海拔图
|
||||
}
|
||||
#endregion
|
||||
//异步请求mapbox画出当前路书路线图
|
||||
DrawMapRouteAsync(route.Id);
|
||||
AddProcess(10);
|
||||
//查询排行榜
|
||||
var list = mapApi.GetRouteRanking(App.RouteIdParam, "1", 0, 10, "");
|
||||
if (list.result)
|
||||
{
|
||||
CreateRankingList(list.data.list);
|
||||
AddProcess(10);
|
||||
}
|
||||
StartCoroutine(HiddenLoading());
|
||||
}
|
||||
|
||||
//创建排行榜
|
||||
public void CreateRankingList(List<MapRouteRanking> list)
|
||||
{
|
||||
var prefab = Resources.Load<GameObject>("UI/Prefab/Ride/RankingItem");
|
||||
var parent = panel.transform.Find("MapRanking");
|
||||
var title = panel.transform.Find("RankingTitle").gameObject;
|
||||
if (list.Count == 0)
|
||||
{
|
||||
title.SetActive(false);
|
||||
}
|
||||
foreach (var item in list)
|
||||
{
|
||||
GameObject newObj = (GameObject)Instantiate(prefab, parent);
|
||||
var selectPlayerItemScript = newObj.GetComponent<RankingItemScript>();
|
||||
selectPlayerItemScript.SetRanking(item.RowNumber.ToString());
|
||||
selectPlayerItemScript.SetName(item.NickName);
|
||||
selectPlayerItemScript.SetTimer(item.IsDNF ? "DNF" : item.TotalTime);
|
||||
selectPlayerItemScript.SetHead(item.WxHeadImg);
|
||||
var texture = cyclingController.GetCountryImageByCode(item.CountryCode);
|
||||
selectPlayerItemScript.SetCountry(texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
_map = transform.parent.Find("MiniMap").GetComponent<AbstractMap>();
|
||||
_minicamera = transform.parent.Find("MiniCamera").GetComponent<Camera>();
|
||||
RectRoot = transform.parent.Find("SingleUI/Panel/MiniMap/MiniMap").GetComponent<RectTransform>();
|
||||
var parent = transform.parent.Find("SingleUI/Panel/MiniMap/MiniMap");
|
||||
RectRoot = transform.parent.Find("UI/Panel/MiniMap/MiniMap").GetComponent<RectTransform>();
|
||||
var parent = transform.parent.Find("UI/Panel/MiniMap/MiniMap");
|
||||
arrow = Instantiate(Resources.Load<GameObject>("UI/Prefab/Ride/MiniArrow"), parent);
|
||||
}
|
||||
public void SetController(AbstractPlayer player)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cdcb8176fafcd62448e8c70ed9d43074
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cab9cf5c3f47cbe498f0cab35b09125e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,135 +0,0 @@
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using GeoJSON.Net.Geometry;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
{
|
||||
public abstract class BaseCycling
|
||||
{
|
||||
public CyclingModel Mode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否记录数据
|
||||
/// </summary>
|
||||
internal bool IsRecord { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 骑行数据记录器
|
||||
/// </summary>
|
||||
public RecorderDataModel recorderData { get; protected set; }
|
||||
|
||||
public List<BaseRider> riders { get; protected set; }
|
||||
/// <summary>
|
||||
/// 骑行的路线
|
||||
/// </summary>
|
||||
public Route route;
|
||||
/// <summary>
|
||||
/// 计时器
|
||||
/// </summary>
|
||||
public int Ticks = 0;
|
||||
/// <summary>
|
||||
/// 当前骑行的距离
|
||||
/// </summary>
|
||||
protected double currentDistance { get; set; }
|
||||
|
||||
public virtual bool CanPause => true;
|
||||
|
||||
protected TurfHelper _turfHelper;
|
||||
|
||||
protected double Zoom { get; private set; }
|
||||
protected string Bounds { get; private set; }
|
||||
|
||||
protected List<OutUser> realRiders;
|
||||
|
||||
protected GeographicPosition CenterPoint { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束的时间
|
||||
/// </summary>
|
||||
protected DateTime? EndTime { get; set; }
|
||||
|
||||
public BaseCycling(Route route, CyclingModel cyclingModel)
|
||||
{
|
||||
this.route = route;
|
||||
this.Mode = cyclingModel;
|
||||
_turfHelper = new TurfHelper(route.JsonData.List.Select(d => d.Point));
|
||||
}
|
||||
|
||||
public virtual DateTime Now
|
||||
{
|
||||
get
|
||||
{
|
||||
return UIManager.Now.GetDateTime();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string ShowTime
|
||||
{
|
||||
get
|
||||
{
|
||||
return Helper.FormatTicks(Ticks);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 骑行函数(如果此方法不满足,可以在子类中重写此方法)
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
public virtual void Run(TargetData targetData)
|
||||
{
|
||||
//将当前用户的位置发送到udf服务
|
||||
SendUserPositionToServer();
|
||||
//OutModel outData = GetSelfTargetData(targetData);
|
||||
BeforeRunAfterPakcData();//执行前的函数
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// =>发送用户的位置信息到服务端
|
||||
/// </summary>
|
||||
private void SendUserPositionToServer()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (recorderData.RiderDatas.Any())
|
||||
{
|
||||
var lastData = recorderData.RiderDatas.Last();
|
||||
var preDistance = recorderData.PreDistance;
|
||||
|
||||
var weightKg = Math.Round(lastData._Power / recorderData.CurrentUser.Weight, 2);
|
||||
MapUDPService.Send(route.RouteInstance.Id, recorderData.BelongUserId,
|
||||
new double[] { lastData._Lat, lastData._Lon },
|
||||
recorderData.IsCompleted, false, recorderData.EndDistance,
|
||||
true, 1, lastData._Speed, false, preDistance, weightKg, competitionId: recorderData.Competitionid, recorderData.Saved);
|
||||
}
|
||||
else if (recorderData.EndDistance > 0)//没有骑,但是有初始位置的情况
|
||||
{
|
||||
var point = _turfHelper.Along(recorderData.EndDistance);
|
||||
//MapUDPService.Send(route.RouteInstance.Id, recorderData.BelongUserId, new double[] { point.Latitude, point.Longitude }, competitionId: recorderData.Competitionid);
|
||||
MapUDPService.Send(route.RouteInstance.Id, recorderData.BelongUserId, new double[] { point.Latitude, point.Longitude }, endDistance:recorderData.EndDistance,preDistance: recorderData.EndDistance, competitionId: recorderData.Competitionid);
|
||||
}
|
||||
else
|
||||
{
|
||||
MapUDPService.Send(route.RouteInstance.Id, recorderData.BelongUserId, route.Point.First().Reverse().ToArray(), competitionId: recorderData.Competitionid);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 执行前,数据打包后
|
||||
/// </summary>
|
||||
/// <param name="outData"></param>
|
||||
protected virtual void BeforeRunAfterPakcData() { }
|
||||
protected double SpeedToDistance(double speed)
|
||||
{
|
||||
return Math.Round(speed / 3600, 5, MidpointRounding.AwayFromZero);
|
||||
//return 0.08;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89d63056e2fd43e41b30635a0036ba33
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,332 +0,0 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model.RiderModels;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Mapbox.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
{
|
||||
public class CompetitionModel : BaseCycling
|
||||
{
|
||||
private Vector2d firstPoint { get; set; }
|
||||
public CompetitionRankingModel competitionRankingModel { get; set; }
|
||||
|
||||
private MapCompetitionApi mapCompetitionApi;
|
||||
|
||||
public MapCompetition mapCompetition;
|
||||
|
||||
private List<CompetitionRankingResultModel> mapWorkoutRecordRankings = new List<CompetitionRankingResultModel>();
|
||||
/// <summary>
|
||||
/// 第一个到终点的时间
|
||||
/// </summary>
|
||||
private DateTime? FirstEndTime { get; set; }
|
||||
|
||||
public override bool CanPause => false;
|
||||
|
||||
public override string ShowTime
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CanStart())
|
||||
{
|
||||
var second = Math.Ceiling((Now - mapCompetition.StartTime.ToLocalTime()).TotalSeconds);
|
||||
|
||||
var ts = TimeSpan.FromSeconds(second);
|
||||
return $"{ (int)ts.TotalHours }:{ts:mm}:{ts:ss}";
|
||||
}
|
||||
return "00:00:00";
|
||||
}
|
||||
}
|
||||
AbstractPlayer currentPlayer;
|
||||
public CompetitionModel(Route route1, RouteResultParam param,AbstractPlayer player)
|
||||
: base(route1, CyclingModel.Competition)
|
||||
{
|
||||
currentPlayer = player;//当前选中用户
|
||||
mapCompetitionApi = new MapCompetitionApi();
|
||||
//param.EndDistance = 18;
|
||||
recorderData = new RecorderDataModel()
|
||||
{
|
||||
CurrentUser = App.CurrentUser,
|
||||
//BelongUserId = PubCommData.CurrentUser.Id,
|
||||
Competitionid = param.CompetitionId??0,
|
||||
ContinueIndex = param.ContinueIndex == null ? 0 : (int)param.ContinueIndex + 1,
|
||||
ContinueMark = string.IsNullOrEmpty(param.ContinueMark) ? Guid.NewGuid().ToString() : param.ContinueMark,
|
||||
EndDistance = param.EndDistance == 0 ? 0 : param.EndDistance,
|
||||
IsCompleted = false,
|
||||
IsNeedRanking = true,
|
||||
CyclingState = CyclingStateEnum.Prepare,
|
||||
//ManufacturerId = ManufacturerId,
|
||||
CurrentRoute = route,
|
||||
CurrentRouteStartDistance = param.EndDistance == 0 ? 0 : param.EndDistance,
|
||||
//DeviceNumber = DeviceNumber,
|
||||
//AntModelId = antModelId
|
||||
};
|
||||
|
||||
IsRecord = true;
|
||||
|
||||
riders = new List<BaseRider>();
|
||||
var rider = new OnlineRiderModel()
|
||||
{
|
||||
NickName = App.CurrentUser.Nickname,
|
||||
UserId = App.CurrentUser.Id,
|
||||
WxHeadImg = App.CurrentUser.WxHeadImg,
|
||||
EndDistance = param.EndDistance == 0 ? 0 : param.EndDistance
|
||||
};
|
||||
if (recorderData.CurrentRouteStartDistance > 0)
|
||||
{
|
||||
rider.Point = _turfHelper.Along(param.EndDistance);
|
||||
}
|
||||
else
|
||||
{
|
||||
rider.Point = new GeoJSON.Net.Geometry.GeographicPosition(this.route.RouteInstance.Point[0], this.route.RouteInstance.Point[1]);
|
||||
}
|
||||
//riders.Add(rider);//剔除自己
|
||||
|
||||
var result = mapCompetitionApi.GetById(param.CompetitionId??0);
|
||||
if (result.result == false || result.data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
mapCompetition = result.data;
|
||||
FirstEndTime = mapCompetition.FirstEndTime;
|
||||
}
|
||||
|
||||
protected override void BeforeRunAfterPakcData()
|
||||
{
|
||||
//#region 设置第一名的坐标
|
||||
//if (!FirstEndTime.HasValue)
|
||||
//{
|
||||
// var firstItem = base.realRiders.OrderByDescending(w => w.NextDistance).FirstOrDefault();
|
||||
// if (firstItem != null)
|
||||
// {
|
||||
// firstPoint = new Vector2d(firstItem.Point.Latitude, firstItem.Point.Longitude);
|
||||
// }
|
||||
//}
|
||||
//#endregion
|
||||
|
||||
var userList = MapUDPService.GetCompetitionOnlineUsers(recorderData.Competitionid).OrderByDescending(u => u.IsCompleted).ThenByDescending(d => d.EndDistance);
|
||||
riders.RemoveAll(r => r.IsSelf == false);
|
||||
int index = 0;
|
||||
List<CompetitionRankingSortModel> sort = new List<CompetitionRankingSortModel>();
|
||||
|
||||
if (userList.Any())
|
||||
{
|
||||
var currentDistance = currentPlayer.TotalDistance;
|
||||
foreach (var item in userList)
|
||||
{
|
||||
#region 记录第一个冲线的时间
|
||||
if (item.IsCompleted && !FirstEndTime.HasValue)
|
||||
{
|
||||
FirstEndTime = Now;
|
||||
}
|
||||
#endregion
|
||||
|
||||
if (item.IsSelf == false)
|
||||
{
|
||||
riders.Add(new OnlineRiderModel
|
||||
{
|
||||
NickName = item.Name,
|
||||
UserId = item.Id,
|
||||
WxHeadImg = item.HeadImage,
|
||||
Point = new GeoJSON.Net.Geometry.GeographicPosition(item.Point[0], item.Point[1]),
|
||||
EndDistance = item.EndDistance,
|
||||
PreDistance = item.PreDistance
|
||||
});
|
||||
}
|
||||
|
||||
index++;
|
||||
double near = Math.Round(item.EndDistance - currentDistance,2); //Math.Round(TurfHelper.GetDistances(point, item.Point), 2);
|
||||
|
||||
sort.Add(new CompetitionRankingSortModel
|
||||
{
|
||||
Index = index,
|
||||
Name = item.Name,
|
||||
Near = near,
|
||||
KGWeight = Math.Round(item.WeightKg, 2).ToString(),
|
||||
Speed = Math.Round(item.Speed, 1),
|
||||
CountryImg = ConfigHelper.Host + $"User/GetCountryImg?userid={ item.Id }",
|
||||
UserId = item.Id,
|
||||
IsSelf = item.IsSelf,
|
||||
Headimage =item.HeadImage
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#region 骑行结束,比赛结果展示数据
|
||||
var results = new List<CompetitionResultModel>();
|
||||
if (recorderData.IsCompleted || recorderData.Saved || mapCompetition.HasRecord)
|
||||
{
|
||||
var users1 = userList.Where(d => d.IsCompleted || d.Saved);
|
||||
if ((users1.Any() && users1.Any(d => mapWorkoutRecordRankings.All(u => u.UserId != d.Id)))
|
||||
|| mapWorkoutRecordRankings.All(u => u.UserId != recorderData.BelongUserId))
|
||||
{
|
||||
var rrr = mapCompetitionApi.GetRankingList(recorderData.Competitionid);
|
||||
if (rrr.result)
|
||||
{
|
||||
mapWorkoutRecordRankings = rrr.data;
|
||||
}
|
||||
}
|
||||
foreach (var ranking in mapWorkoutRecordRankings)
|
||||
{
|
||||
//var ranking = mapWorkoutRecordRankings.SingleOrDefault(r => r.UserId == item.Id);
|
||||
|
||||
var createTime = "";
|
||||
if (ranking != null)
|
||||
{
|
||||
createTime = ranking.CreateTime; //.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
results.Add(new CompetitionResultModel
|
||||
{
|
||||
Index = ranking.Index,
|
||||
Name = ranking.NickName,
|
||||
Weight = ranking?.Weight ?? 0,
|
||||
WeightKg = ranking?.WeightKg ?? 0,
|
||||
//Time = ranking?.TotalTime ?? "",
|
||||
Power = ranking?.AveragePower ?? 0,
|
||||
BicycleWeight = ranking?.BicycleWeight ?? 0,
|
||||
HeartRate = ranking?.AverageHeartRate ?? 0,
|
||||
DeviceType = ranking?.DeviceType ?? "",
|
||||
CreateTime = createTime,
|
||||
TripTime = ranking?.TripTime ?? "",
|
||||
CompleteTime = ranking?.CompleteTime,
|
||||
Gap = ranking?.Gap ?? ""
|
||||
});
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
competitionRankingModel = new CompetitionRankingModel
|
||||
{
|
||||
Sorts = sort,//骑行实时排名
|
||||
MyRanking = sort.FindIndex(n => n.UserId == currentPlayer.UserId) + 1,//切换人物显示对应人物的排名
|
||||
Total = sort.Count,//总人数
|
||||
Results = results//比赛结果列表
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 赛事模式有继续骑行,重写执行方法
|
||||
/// </summary>
|
||||
/// <param name="targetData"></param>
|
||||
public override void Run(TargetData targetData)
|
||||
{
|
||||
|
||||
#region 获取当前路线在线用户
|
||||
riders.RemoveAll(r => r.IsSelf == false);
|
||||
var onlineUsers = MapUDPService.GetCompetitionOnlineUsers(mapCompetition.Id).Where(d => d.IsSelf == false)
|
||||
.ToList();
|
||||
foreach (var item in onlineUsers)
|
||||
{
|
||||
riders.Add(new OnlineRiderModel()
|
||||
{
|
||||
NickName = item.Name,
|
||||
UserId = item.Id,
|
||||
WxHeadImg = item.HeadImage,
|
||||
Point = new GeoJSON.Net.Geometry.GeographicPosition(item.Point[0], item.Point[1]),
|
||||
EndDistance = item.EndDistance,
|
||||
PreDistance = item.PreDistance,
|
||||
WeightKg = item.WeightKg,
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
//TODO:接力赛
|
||||
////base.BeforeRun(targetData);
|
||||
//if (recorderData.CyclingState == CyclingStateEnum.Prepare)
|
||||
//{
|
||||
// if (recorderData.EndDistance != 0)
|
||||
// {
|
||||
// currentDistance = recorderData.EndDistance;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// currentDistance = 0;
|
||||
// }
|
||||
//}
|
||||
//else if (recorderData.CyclingState == CyclingStateEnum.Cycling)
|
||||
//{
|
||||
// currentDistance = recorderData.EndDistance + SpeedToDistance(targetData._Speed);
|
||||
//}
|
||||
base.Run(targetData);
|
||||
}
|
||||
|
||||
//显示结果当前用户保存或者产生第一名
|
||||
public bool CanShowResult()
|
||||
{
|
||||
return mapCompetition?.HasRecord ?? false || mapCompetition ?.FirstEndTime != null;
|
||||
}
|
||||
//关门时间到了退出骑行场景
|
||||
public bool CanQuit()
|
||||
{
|
||||
if (mapCompetition?.FirstEndTime.HasValue??false)
|
||||
{
|
||||
var closeDateTime = mapCompetition?.FirstEndTime.Value.ToLocalTime().AddMinutes(mapCompetition?.CloseTime??0 );
|
||||
return Now >= closeDateTime;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanStart()
|
||||
{
|
||||
if (mapCompetition == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//if (mapCompetition.CanStart)
|
||||
//{
|
||||
// return true;
|
||||
//}
|
||||
|
||||
if (mapCompetition.HasRecord)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//已结束
|
||||
if (mapCompetition.Status == 4)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (mapCompetition.StartTime.ToLocalTime() <= Now && mapCompetition.EndTime.ToLocalTime() > Now)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int StartCountdown()
|
||||
{
|
||||
if (CanStart()) return 0;
|
||||
return (int)Math.Floor((mapCompetition.StartTime.ToLocalTime() - Now).TotalSeconds);
|
||||
}
|
||||
/// <summary>
|
||||
/// 结束倒计时,bool值为true说明倒计时是关门时间
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public (int, bool) EndCountDown()
|
||||
{
|
||||
if (CanStart() == false) return (0, false);
|
||||
//if (recorderData.IsCompleted) return 0;
|
||||
var end1 = (int)Math.Floor((mapCompetition.EndTime.ToLocalTime() - Now).TotalSeconds);
|
||||
if (!FirstEndTime.HasValue)
|
||||
{
|
||||
return (end1, false);
|
||||
}
|
||||
//var end2 = (int)Math.Floor((FirstEndTime.Value - Now).TotalSeconds);
|
||||
var end2 = (int)Math.Floor((FirstEndTime.Value.AddMinutes(mapCompetition.CloseTime) - Now).TotalSeconds);
|
||||
if (end1 < end2)
|
||||
{
|
||||
return (end1, false);
|
||||
}
|
||||
//return Math.Min(end1, end2);
|
||||
return (end2, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44b357cbe9541fa448708b42ff5bf3d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,90 +0,0 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model.RiderModels;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
{
|
||||
public class ReviewModel : BaseCycling
|
||||
{
|
||||
public List<MapRecordRanking> rankings;
|
||||
|
||||
public ReviewModel(Route route1, RouteResultParam param)
|
||||
: base(route1, CyclingModel.Review)
|
||||
{
|
||||
//rankings = service.GetMapRecordRankingsFromServe(param.RankingsId);
|
||||
riders = new List<BaseRider>();
|
||||
//riders.Add(new OnlineRiderModel()
|
||||
//{
|
||||
// NickName = App.CurrentUser.Nickname,
|
||||
// UserId = App.CurrentUser.Id,
|
||||
// WxHeadImg = App.CurrentUser.WxHeadImg,
|
||||
// Point = new GeoJSON.Net.Geometry.GeographicPosition(this.route.RouteInstance.Point[0], this.route.RouteInstance.Point[1])
|
||||
//});
|
||||
//foreach (var item in rankings)
|
||||
//{
|
||||
// riders.Add(new ReviewRiderModel()
|
||||
// {
|
||||
// NickName = item.NickName,
|
||||
// UserId = item.UserId,
|
||||
// WxHeadImg = item.WxHeadImg,
|
||||
// record = item.record,
|
||||
// Point = new GeoJSON.Net.Geometry.GeographicPosition(this.route.RouteInstance.Point[0], this.route.RouteInstance.Point[1])
|
||||
// });
|
||||
//}
|
||||
recorderData = new RecorderDataModel()
|
||||
{
|
||||
CurrentUser = App.CurrentUser,
|
||||
//BelongUserId = PubCommData.CurrentUser.Id,
|
||||
Competitionid = 0,
|
||||
ContinueIndex = 0,
|
||||
ContinueMark = Guid.NewGuid().ToString(),
|
||||
EndDistance = 0,
|
||||
PreDistance = 0,
|
||||
IsCompleted = false,
|
||||
IsNeedRanking = true,
|
||||
CyclingState = CyclingStateEnum.Prepare,
|
||||
//ManufacturerId = ManufacturerId,
|
||||
CurrentRoute = route,
|
||||
CurrentRouteStartDistance = 0,
|
||||
//DeviceNumber = DeviceNumber,
|
||||
//AntModelId = antModelId
|
||||
};
|
||||
|
||||
//recorderData = recorderData1;
|
||||
this.IsRecord = true;
|
||||
//riders = riders1;
|
||||
|
||||
}
|
||||
|
||||
public override void Run(TargetData targetData)
|
||||
{
|
||||
|
||||
#region 获取当前路线在线用户
|
||||
riders.RemoveAll(r => r.IsSelf == false);
|
||||
var onlineUsers = MapUDPService.GetOnlineUsers(recorderData.CurrentRoute.RouteInstance.Id).Where(d => d.IsSelf == false)
|
||||
.ToList();
|
||||
foreach (var item in onlineUsers)
|
||||
{
|
||||
riders.Add(new OnlineRiderModel()
|
||||
{
|
||||
NickName = item.Name,
|
||||
UserId = item.Id,
|
||||
WxHeadImg = item.HeadImage,
|
||||
Point = new GeoJSON.Net.Geometry.GeographicPosition(item.Point[0], item.Point[1]),
|
||||
EndDistance = item.EndDistance,
|
||||
PreDistance = item.PreDistance,
|
||||
WeightKg = item.WeightKg,
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
base.Run(targetData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 363f64631c874c84198aa481f8899911
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,89 +0,0 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model.RiderModels;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
{
|
||||
public class SingleModel : BaseCycling
|
||||
{
|
||||
|
||||
public SingleModel(Route route,RouteResultParam param)
|
||||
: base(route, CyclingModel.Single)
|
||||
{
|
||||
this.IsRecord = true;
|
||||
recorderData = new RecorderDataModel()
|
||||
{
|
||||
CurrentUser = App.CurrentUser,
|
||||
Competitionid = 0,
|
||||
ContinueIndex = 0,
|
||||
ContinueMark = Guid.NewGuid().ToString(),
|
||||
EndDistance = 0,
|
||||
IsCompleted = false,
|
||||
IsNeedRanking = true,
|
||||
CyclingState = CyclingStateEnum.Prepare,
|
||||
CurrentRoute = route,
|
||||
CurrentRouteStartDistance = 0,
|
||||
StartTime = UIManager.Now.GetDateTime(),//DateTime.Now
|
||||
};
|
||||
|
||||
if (param != null)
|
||||
{
|
||||
recorderData.EndDistance = param.EndDistance;
|
||||
recorderData.CurrentRouteStartDistance = param.EndDistance;
|
||||
if (!string.IsNullOrWhiteSpace(param.ContinueMark))
|
||||
{
|
||||
recorderData.ContinueMark = param.ContinueMark;
|
||||
}
|
||||
else
|
||||
{
|
||||
param.ContinueMark = recorderData.ContinueMark;
|
||||
}
|
||||
recorderData.ContinueIndex = param.ContinueIndex.GetValueOrDefault(0);
|
||||
}
|
||||
|
||||
recorderData.PreDistance = recorderData.EndDistance;
|
||||
|
||||
riders = new List<BaseRider>();
|
||||
//var rider = new OnlineRiderModel()
|
||||
//{
|
||||
// NickName = App.CurrentUser.Nickname,
|
||||
// UserId = App.CurrentUser.Id,
|
||||
// WxHeadImg = App.CurrentUser.WxHeadImg + "?t=1",
|
||||
// //Point = new GeoJSON.Net.Geometry.GeographicPosition(this.route.RouteInstance.Point[0], this.route.RouteInstance.Point[1]),
|
||||
// EndDistance = recorderData.EndDistance
|
||||
//};
|
||||
//rider.Point = _turfHelper.Along(rider.EndDistance);
|
||||
|
||||
//riders.Add(rider);
|
||||
|
||||
}
|
||||
|
||||
public override void Run(TargetData targetData)
|
||||
{
|
||||
#region 获取当前路线在线用户
|
||||
riders.RemoveAll(r => r.IsSelf == false);
|
||||
var onlineUsers = MapUDPService.GetOnlineUsers(recorderData.CurrentRoute.RouteInstance.Id).Where(d => d.IsSelf == false)
|
||||
.ToList();
|
||||
foreach (var item in onlineUsers)
|
||||
{
|
||||
riders.Add(new OnlineRiderModel()
|
||||
{
|
||||
NickName = item.Name,
|
||||
UserId = item.Id,
|
||||
WxHeadImg = item.HeadImage,
|
||||
Point = new GeoJSON.Net.Geometry.GeographicPosition(item.Point[0], item.Point[1]),
|
||||
EndDistance = item.EndDistance,
|
||||
PreDistance = item.PreDistance,
|
||||
WeightKg = item.WeightKg,
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
base.Run(targetData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1057f786065eded488dd73a935cc1b93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,106 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 骑行模式
|
||||
/// </summary>
|
||||
public enum CyclingModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 单人模式
|
||||
/// </summary>
|
||||
Single = 0,
|
||||
/// <summary>
|
||||
/// 在线模式
|
||||
/// </summary>
|
||||
Online = 1,
|
||||
/// <summary>
|
||||
/// 多人历史数据回顾模式
|
||||
/// </summary>
|
||||
Review = 2,
|
||||
/// <summary>
|
||||
/// 比赛模式
|
||||
/// </summary>
|
||||
Competition = 3,
|
||||
/// <summary>
|
||||
/// 环球骑行
|
||||
/// </summary>
|
||||
GlobalCycling = 4
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 骑手类型
|
||||
/// </summary>
|
||||
public enum RiderType
|
||||
{
|
||||
//Real,//真实的人
|
||||
Online,//在线人
|
||||
Review,//回顾人(历史数据中的人)
|
||||
Virtual
|
||||
}
|
||||
/// <summary>
|
||||
/// 骑行状态(状态变更示意图:Paush=>Cycling=>Stop=>Cycling=>Stop)
|
||||
/// </summary>
|
||||
public enum CyclingStateEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// 准备阶段
|
||||
/// </summary>
|
||||
Prepare,
|
||||
/// 骑行中
|
||||
/// </summary>
|
||||
Cycling,
|
||||
/// <summary>
|
||||
/// 暂停
|
||||
/// </summary>
|
||||
Stop
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送数据模式
|
||||
/// </summary>
|
||||
public enum SendDataMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 自由骑
|
||||
/// </summary>
|
||||
Freedom,
|
||||
/// <summary>
|
||||
/// 阻力模式
|
||||
/// </summary>
|
||||
Resistance,
|
||||
/// <summary>
|
||||
/// 轨道模式
|
||||
/// </summary>
|
||||
Track
|
||||
}
|
||||
/// <summary>
|
||||
/// 浏览器窗口
|
||||
/// </summary>
|
||||
public enum BrowserWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// 主页面窗口
|
||||
/// </summary>
|
||||
Main,
|
||||
/// <summary>
|
||||
/// 骑行页面窗口
|
||||
/// </summary>
|
||||
Cycling
|
||||
}
|
||||
|
||||
public enum CurrentPage
|
||||
{
|
||||
index,
|
||||
list,
|
||||
detial,
|
||||
review,
|
||||
competition,
|
||||
cycling
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3d3dd3c4d6e2694eb9d94bc819a12f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,559 +0,0 @@
|
||||
using GeoJSON.Net.Geometry;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 排名
|
||||
/// </summary>
|
||||
public class CompetitionRankingSortModel
|
||||
{
|
||||
public int Index { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Headimage { get; set; }
|
||||
|
||||
public double Near { get; set; }
|
||||
|
||||
public string KGWeight { get; set; }
|
||||
|
||||
public double Speed { get; set; }
|
||||
|
||||
public string CountryImg { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
public bool IsSelf { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 结果页模型
|
||||
/// </summary>
|
||||
public class CompetitionResultModel
|
||||
{
|
||||
public int Index { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
//public string Time { get; set; }
|
||||
|
||||
public double Power { get; set; }
|
||||
public double WeightKg { get; set; }
|
||||
public double Weight { get; set; }
|
||||
public double BicycleWeight { get; set; }
|
||||
|
||||
public double HeartRate { get; set; }
|
||||
|
||||
public string DeviceType { get; set; }
|
||||
|
||||
public string CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 骑行时长
|
||||
/// </summary>
|
||||
public string TripTime { get; set; }
|
||||
|
||||
public string CompleteTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 与冲线时间的差距
|
||||
/// </summary>
|
||||
public string Gap { get; set; }
|
||||
}
|
||||
public class RankingDataModel
|
||||
{
|
||||
public int UserId { get; set; }
|
||||
|
||||
public TargetData data { get; set; }
|
||||
}
|
||||
|
||||
public class RankingSortData
|
||||
{
|
||||
public int Index { get; set; }
|
||||
public int UserId { get; set; }
|
||||
|
||||
public string WxHeadImg { get; set; }
|
||||
|
||||
public string NickName { get; set; }
|
||||
/// <summary>
|
||||
/// 注意这里TotalTime不是时间是距离,为了重用前端组件,没改名称
|
||||
/// </summary>
|
||||
public double TotalTime { get; set; }
|
||||
|
||||
public int Ticks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 其他人和我的距离(m)
|
||||
/// </summary>
|
||||
public double Near { get; set; }
|
||||
}
|
||||
public class CyclingFrameRankingModel
|
||||
{
|
||||
public List<RankingDataModel> data { get; set; }
|
||||
|
||||
public List<RankingSortData> sort { get; set; }
|
||||
|
||||
public int myranking { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 比赛的排名
|
||||
/// </summary>
|
||||
public class CompetitionRankingModel
|
||||
{
|
||||
public List<CompetitionRankingSortModel> Sorts { get; set; }
|
||||
|
||||
public int Total { get; set; }
|
||||
|
||||
public int MyRanking { get; set; }
|
||||
|
||||
public List<CompetitionResultModel> Results { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 骑行中 输出的数据模型
|
||||
/// </summary>
|
||||
public class OutModel
|
||||
{
|
||||
public double progress { get; set; }
|
||||
|
||||
public double? Elevation { get; set; }
|
||||
|
||||
public string Seconds { get; set; }
|
||||
|
||||
public int? EleIndex { get; set; }
|
||||
|
||||
//public long ExcuteTime { get; set; }
|
||||
|
||||
//public double? Bearing { get; set; }
|
||||
/// <summary>
|
||||
/// 坡度
|
||||
/// </summary>
|
||||
public double SlopeGrade { get; set; }
|
||||
|
||||
public TargetData targetData { get; set; }
|
||||
|
||||
public List<OutUser> baseRiders { get; set; }
|
||||
|
||||
public CyclingFrameRankingModel Ranking { get; set; }
|
||||
|
||||
public CompetitionRankingModel CompetitionRanking { get; set; }
|
||||
|
||||
public bool CanStart { get; set; } = true;
|
||||
/// <summary>
|
||||
/// 开始倒计时
|
||||
/// </summary>
|
||||
public int StartCountDown { get; set; }
|
||||
/// <summary>
|
||||
/// 结束倒计时
|
||||
/// </summary>
|
||||
public int EndCountDown { get; set; }
|
||||
/// <summary>
|
||||
/// 标识比赛的倒计时是关门时间
|
||||
/// </summary>
|
||||
public bool IsClosed { get; set; }
|
||||
///// <summary>
|
||||
///// 是否已保存
|
||||
///// </summary>
|
||||
//public bool Saved { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 比赛模式下,第一名的坐标
|
||||
/// </summary>
|
||||
public GeographicPosition FirstPoint { get; set; }
|
||||
|
||||
|
||||
public ChartSymbol ChartSymbol { get; set; }
|
||||
}
|
||||
|
||||
public class OutUser
|
||||
{
|
||||
public int UserId { get; set; }
|
||||
|
||||
public string InMapId { get; set; }
|
||||
|
||||
public double NextDistance { get; set; }
|
||||
|
||||
public double PreDistance { get; set; }
|
||||
|
||||
//public TargetData targetData { get; set; }//暂时不需要此字段
|
||||
public List<double[]> NextFrameArray { get; set; }
|
||||
//private List<object> _nextFrameArray { get; set; }
|
||||
//public List<object> NextFrameArray
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// if (_nextFrameArray != null)
|
||||
// {
|
||||
// return _nextFrameArray;
|
||||
// }
|
||||
// _nextFrameArray = (List<object>)CefBrowserPool.GetFrame(BrowserWindow.Main).EvaluateScriptAsync($"getFrameArray({PreDistance},{NextDistance})").ConfigureAwait(false).GetAwaiter().GetResult().Result;
|
||||
// return _nextFrameArray;
|
||||
// }
|
||||
//}
|
||||
|
||||
public string NickName { get; set; }
|
||||
public string WxHeadImg { get; set; }
|
||||
|
||||
public bool IsSelf
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.UserId == App.CurrentUser.Id;
|
||||
}
|
||||
}
|
||||
|
||||
public GeographicPosition Point { get; set; }
|
||||
|
||||
public double Bearing { get; set; }
|
||||
}
|
||||
|
||||
public class ChartSymbol
|
||||
{
|
||||
private double _grade = 0;
|
||||
private double _nextGrade = 0;
|
||||
public string GradeSymbol
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_grade > 0)
|
||||
{
|
||||
return "+";
|
||||
}
|
||||
if (_grade < 0)
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
public string GradeDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_grade < 0)
|
||||
{
|
||||
return (_grade * -1).ToString("0.#");
|
||||
}
|
||||
if (_grade > 0)
|
||||
{
|
||||
return _grade.ToString("0.#");
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
public string NextGrade
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nextGrade > 0)
|
||||
{
|
||||
return "+" + _nextGrade.ToString("0.#");
|
||||
}
|
||||
return _nextGrade.ToString("0.#");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 单位m
|
||||
/// </summary>
|
||||
public double Distance { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="grade"></param>
|
||||
/// <param name="nextGrade"></param>
|
||||
/// <param name="distance">单位m</param>
|
||||
public ChartSymbol(double grade, double nextGrade, double distance)
|
||||
{
|
||||
this._grade = grade;
|
||||
this._nextGrade = nextGrade;
|
||||
this.Distance = Math.Round(distance, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public class NearRiderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Headimage { get; set; }
|
||||
|
||||
public double Near { get; set; }
|
||||
|
||||
public string KGWeight { get; set; }
|
||||
|
||||
public double Speed { get; set; }
|
||||
|
||||
public string CountryImg { get; set; }
|
||||
|
||||
public string Country { get; set; }
|
||||
|
||||
public bool IsSelf { get; set; }
|
||||
}
|
||||
|
||||
public class MsgModel
|
||||
{
|
||||
public int RouteId { get; set; }
|
||||
|
||||
public int MemberId { get; set; }
|
||||
|
||||
public double[] Point { get; set; }
|
||||
|
||||
//public bool exit { get; set; }
|
||||
|
||||
public double Speed { get; set; }
|
||||
|
||||
public bool IsCompleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 需要展示的属性
|
||||
/// </summary>
|
||||
//public string Prop { get; set; }
|
||||
|
||||
public double EndDistance { get; set; }
|
||||
///// <summary>
|
||||
///// 是否展示在线的人
|
||||
///// </summary>
|
||||
//public bool ShowVirtual { get; set; }
|
||||
/// <summary>
|
||||
/// 命令类型,0命令,1消息
|
||||
/// </summary>
|
||||
public byte CommandType { get; set; }
|
||||
|
||||
//public bool IsVirtual { get; set; }
|
||||
/// <summary>
|
||||
/// 功率体重比
|
||||
/// </summary>
|
||||
public double WeightKg { get; set; }
|
||||
|
||||
public double PreDistance { get; set; }
|
||||
|
||||
public int Competitionid { get; set; }
|
||||
/// <summary>
|
||||
/// 客户端通过是否有用户保存了数据,来拉取相应的已经被保存的数据。(主要用在比赛)
|
||||
/// </summary>
|
||||
public bool Saved { get; set; }
|
||||
|
||||
//public int V { get; set; }
|
||||
}
|
||||
|
||||
public class GzipMsgModel
|
||||
{
|
||||
public int CommandType { get; set; }
|
||||
public int V { get; set; }
|
||||
public string Encoding { get; set; }
|
||||
public string Client { get; set; }
|
||||
public int MemberId { get; set; }
|
||||
public int Competitionid { get; set; }
|
||||
public bool IsWatch { get; set; }
|
||||
}
|
||||
|
||||
public class ReceiveMsgModel
|
||||
{
|
||||
public int RouteId { get; set; }
|
||||
|
||||
public int MemberId { get; set; }
|
||||
|
||||
public double[] Point { get; set; }
|
||||
|
||||
//public bool exit { get; set; }
|
||||
|
||||
public double Speed { get; set; }
|
||||
|
||||
public bool IsCompleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 需要展示的属性
|
||||
/// </summary>
|
||||
//public string Prop { get; set; }
|
||||
|
||||
public double EndDistance { get; set; }
|
||||
/// <summary>
|
||||
/// 是否展示在线的人
|
||||
/// </summary>
|
||||
//public bool ShowVirtual { get; set; }
|
||||
/// <summary>
|
||||
/// 命令类型,0命令,1消息
|
||||
/// </summary>
|
||||
//public byte CommandType { get; set; }
|
||||
|
||||
//public bool IsVirtual { get; set; }
|
||||
|
||||
|
||||
public double PreDistance { get; set; }
|
||||
/// <summary>
|
||||
/// 功率体重比
|
||||
/// </summary>
|
||||
public double WeightKg { get; set; }
|
||||
public int Competitionid { get; set; }
|
||||
|
||||
public bool Saved { get; set; }
|
||||
|
||||
public string WatchIdList { get; set; }
|
||||
|
||||
|
||||
public static ReceiveMsgModel Parse(string str)
|
||||
{
|
||||
var list = str.Split(',');
|
||||
if (list.Length != 10)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return new ReceiveMsgModel
|
||||
{
|
||||
RouteId = Convert.ToInt32(list[0],CultureInfo.InvariantCulture),
|
||||
MemberId = Convert.ToInt32(list[1], CultureInfo.InvariantCulture),
|
||||
Point = new double[] { double.Parse(list[2].Split(':')[0], CultureInfo.InvariantCulture), double.Parse(list[2].Split(':')[1], CultureInfo.InvariantCulture) },
|
||||
IsCompleted = ToBoolean(list[3]),
|
||||
//exit = ToBoolean(list[4]),
|
||||
Speed = Convert.ToDouble(list[4], CultureInfo.InvariantCulture),
|
||||
PreDistance = Convert.ToDouble(list[5], CultureInfo.InvariantCulture),
|
||||
EndDistance = Convert.ToDouble(list[6], CultureInfo.InvariantCulture),
|
||||
WeightKg = Convert.ToDouble(list[7], CultureInfo.InvariantCulture),
|
||||
Competitionid = Convert.ToInt32(list[8], CultureInfo.InvariantCulture),
|
||||
Saved = ToBoolean(list[9])
|
||||
};
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ToBoolean(string str)
|
||||
{
|
||||
return Convert.ToBoolean(int.Parse(str));
|
||||
}
|
||||
}
|
||||
|
||||
public class OnlineUser
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户Id
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 在地图中的ID
|
||||
/// </summary>
|
||||
public string InMapId
|
||||
{
|
||||
get
|
||||
{
|
||||
//if (IsVirtual)
|
||||
//{
|
||||
// return "Online-Virtual-" + this.Id;
|
||||
//}
|
||||
return "Online-" + this.Id;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsVirtual { get; set; }
|
||||
/// <summary>
|
||||
/// 虚拟人物名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
public double Weight { get; set; }
|
||||
/// <summary>
|
||||
/// 头像地址
|
||||
/// </summary>
|
||||
public string HeadImage { get; set; }
|
||||
/// <summary>
|
||||
/// 路线Id
|
||||
/// </summary>
|
||||
public int RouteId { get; set; }
|
||||
/// <summary>
|
||||
/// FTP
|
||||
/// </summary>
|
||||
public int FTP { get; set; }
|
||||
/// <summary>
|
||||
/// 点位
|
||||
/// </summary>
|
||||
public double[] Point { get; set; }
|
||||
/// <summary>
|
||||
/// 需要展示的属性
|
||||
/// </summary>
|
||||
//public List<KeyPaire> Show { get; set; }
|
||||
/// <summary>
|
||||
/// 需要隐藏的属性
|
||||
/// </summary>
|
||||
public List<KeyPaire> Hide { get; set; }
|
||||
/// <summary>
|
||||
/// 是否骑行完毕
|
||||
/// </summary>
|
||||
public bool IsCompleted { get; set; }
|
||||
|
||||
public bool IsWatcher { get; set; }
|
||||
|
||||
public List<int> WatcherList { get; set; }
|
||||
|
||||
public double PreDistance { get; set; }
|
||||
/// <summary>
|
||||
/// 最后距离
|
||||
/// </summary>
|
||||
public double EndDistance { get; set; }
|
||||
///// <summary>
|
||||
///// 是否退出
|
||||
///// </summary>
|
||||
//public bool exit { get; set; }
|
||||
/// <summary>
|
||||
/// 速度(km/h)
|
||||
/// </summary>
|
||||
public double Speed { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 圆形头像
|
||||
///// </summary>
|
||||
//public string CircHeadImg
|
||||
//{
|
||||
// get; set;
|
||||
//}
|
||||
|
||||
public bool IsSelf
|
||||
{
|
||||
get
|
||||
{
|
||||
return Id == App.CurrentUser.Id;
|
||||
}
|
||||
}
|
||||
|
||||
public double WeightKg { get; set; }
|
||||
|
||||
public int CompetitionId { get; set; }
|
||||
/// <summary>
|
||||
/// 已保存的
|
||||
/// </summary>
|
||||
public bool Saved { get; set; }
|
||||
|
||||
public DateTime LastActiveTime { get; set; }
|
||||
|
||||
public bool IsLost
|
||||
{
|
||||
get
|
||||
{
|
||||
return (DateTime.Now - LastActiveTime).TotalSeconds > 3;
|
||||
}
|
||||
}
|
||||
|
||||
public string Country { get; set; }
|
||||
}
|
||||
|
||||
public class KeyPaire
|
||||
{
|
||||
public object Key { get; set; }
|
||||
|
||||
public object Value { get; set; }
|
||||
public KeyPaire(object key, object value)
|
||||
{
|
||||
this.Key = key;
|
||||
this.Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5741018b26c4d94dbd42daf26d87f3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,258 +0,0 @@
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
public class RecorderDataModel
|
||||
{
|
||||
//private readonly MapWorkoutService service = new MapWorkoutService();
|
||||
|
||||
public UserResultModel CurrentUser { get; set; }
|
||||
/// <summary>
|
||||
/// 所属人ID
|
||||
/// </summary>
|
||||
public int BelongUserId
|
||||
{
|
||||
get
|
||||
{
|
||||
return CurrentUser.Id;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 记录是否完毕
|
||||
/// </summary>
|
||||
public bool IsCompleted { get; set; }
|
||||
/// <summary>
|
||||
/// 是否需要计算排名
|
||||
/// </summary>
|
||||
public bool IsNeedRanking { get; set; }
|
||||
/// <summary>
|
||||
/// 骑行记录索引(用于中断骑行,继续骑行)
|
||||
/// </summary>
|
||||
public int ContinueIndex { get; set; }
|
||||
/// <summary>
|
||||
/// 骑行状态
|
||||
/// </summary>
|
||||
public CyclingStateEnum CyclingState { get; set; }
|
||||
/// <summary>
|
||||
/// 赛事Id
|
||||
/// </summary>
|
||||
public int Competitionid { get; set; }
|
||||
/// <summary>
|
||||
/// 当前已经骑行的距离(表示用户现在在的距离,并不是实际骑的距离)
|
||||
/// </summary>
|
||||
public double EndDistance { get; set; }
|
||||
/// <summary>
|
||||
/// 上次骑行的距离
|
||||
/// </summary>
|
||||
public double PreDistance { get; set; }
|
||||
/// <summary>
|
||||
/// 继续骑行记录标志
|
||||
/// </summary>
|
||||
public string ContinueMark { get; set; }
|
||||
/// <summary>
|
||||
/// 厂商Id
|
||||
/// </summary>
|
||||
public int? ManufacturerId { get; set; }
|
||||
|
||||
public string ManufacturerName { get; set; }
|
||||
|
||||
public int? AntModelId { get; set; }
|
||||
/// <summary>
|
||||
/// 骑行数据
|
||||
/// </summary>
|
||||
public List<TargetData> RiderDatas = new List<TargetData>();
|
||||
/// <summary>
|
||||
/// 当前路线
|
||||
/// </summary>
|
||||
public Route CurrentRoute { get; set; }
|
||||
/// <summary>
|
||||
/// 骑行记录Id
|
||||
/// </summary>
|
||||
//public string RecordId { get; private set; }
|
||||
/// <summary>
|
||||
/// 设备号
|
||||
/// </summary>
|
||||
public string DeviceNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前给骑行台发送数据的模式
|
||||
/// </summary>
|
||||
public SendDataMode SendDataMode { get; set; }
|
||||
/// <summary>
|
||||
/// 临时使用的坡度
|
||||
/// </summary>
|
||||
public double SlopeGrade { get; set; }
|
||||
/// <summary>
|
||||
/// 临时使用的海拔
|
||||
/// </summary>
|
||||
public double Elevation { get; set; }
|
||||
/// <summary>
|
||||
/// 当前路书开始的距离
|
||||
/// </summary>
|
||||
public double CurrentRouteStartDistance { get; set; }
|
||||
|
||||
public DateTime StartTime { get; set; }
|
||||
|
||||
public DateTime EndTime { get; set; }
|
||||
/// <summary>
|
||||
/// 是否已经保存成功
|
||||
/// </summary>
|
||||
public bool Saved { get; set; }
|
||||
|
||||
public int GlobalCyclingId { get; set; }
|
||||
|
||||
public double? TwentyMinutesMaxAP { get; set; }
|
||||
public double? FiveSecondsMaxAP { get; set; }
|
||||
public double? TenSecondsMaxAP { get; set; }
|
||||
public double? OneMinuteMaxAP { get; set; }
|
||||
public double? FiveMinutesMaxAp { get; set; }
|
||||
|
||||
public void SaveWithLocalRecordAysnc(CyclingModel cyclingModel, RouteResultParam selectParam, string imageName,string recordId,string path)
|
||||
{
|
||||
Dictionary<MapInterruptRecord, List<string>> recordData = new Dictionary<MapInterruptRecord, List<string>>();
|
||||
if (RiderDatas.Count <= 0)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
string newFileName = Guid.NewGuid().ToString();
|
||||
int FTP = Helper.GetFtp();
|
||||
double NP = Helper.GetNP(RiderDatas);
|
||||
//强度
|
||||
double IF = NP / FTP;
|
||||
//训练量
|
||||
double TSS = (RiderDatas.Count * NP * IF) / (FTP * 3600) * 100;
|
||||
var averagePower = Helper.AveragePower(RiderDatas);
|
||||
|
||||
// AntManufacturer manufacturer = service.GetAntManufacturer(ManufacturerId).data;
|
||||
//var recordId = Guid.NewGuid().ToString();
|
||||
var ticks = RiderDatas.Last().Ticks;
|
||||
var interruptRecord = new MapInterruptRecord
|
||||
{
|
||||
Id = recordId,
|
||||
RouteId = CurrentRoute.RouteInstance.Id,
|
||||
RouteName = CurrentRoute.RouteInstance.Name,
|
||||
TotalDistance = CurrentRoute.RouteInstance.Distance,
|
||||
UserId = BelongUserId,
|
||||
RecordFileName = newFileName + ".txt",
|
||||
Ftp = FTP,//FTP设置
|
||||
IF = Math.Round(IF, 2),
|
||||
Kj = RiderDatas.Sum(a => a._Power) / 1000,//消耗
|
||||
Tss = Math.Round(TSS, 2),
|
||||
EndDistance = EndDistance,
|
||||
IsCompleted = IsCompleted,
|
||||
|
||||
//TrainingTime = TimeHelper.FormatSeconds(RiderDatas.Last().Ticks),//训练时间
|
||||
NormalizedPower = Math.Floor(NP),//标准化功率
|
||||
AveragePower = averagePower,//平均功率
|
||||
MaxPower = RiderDatas.Max(a => a._Power),//最大功率
|
||||
WeightKg = Math.Round(averagePower / App.CurrentUser.Weight, 2),
|
||||
Weight = App.CurrentUser.Weight,
|
||||
BicycleWeight = App.CurrentUser.BicycleWeight,
|
||||
ContinueMark = ContinueMark,
|
||||
ContinueIndex = ContinueIndex,
|
||||
IsDelete = false,
|
||||
MapCompetitionId = Competitionid,
|
||||
ManufacturerName = ManufacturerName,//manufacturer == null ? "" : manufacturer.Name,
|
||||
DeviceNumber = DeviceNumber,
|
||||
IsRanking = IsNeedRanking,
|
||||
CurrentRouteStartDistance = CurrentRouteStartDistance,
|
||||
ManufacturerId = ManufacturerId,
|
||||
AntModelId = AntModelId,
|
||||
StartTime = StartTime,
|
||||
CreateTime = EndTime, //StartTime.AddSeconds(ticks),
|
||||
Ticks = ticks,
|
||||
Mode = cyclingModel.ToString(),
|
||||
Param = Newtonsoft.Json.JsonConvert.SerializeObject(selectParam),
|
||||
GlobalCyclingId = 0,
|
||||
Source = "",
|
||||
};
|
||||
//var range = new MapSpeedRange().GetSpeedRange(RiderDatas, CurrentRoute.RouteInstance.Distance);
|
||||
interruptRecord.SpeedRange = null; //JsonConvert.SerializeObject(range);
|
||||
|
||||
double process = Math.Round((EndDistance - interruptRecord.CurrentRouteStartDistance) / CurrentRoute.RouteInstance.Distance, 2);
|
||||
interruptRecord.Progress = process > 1 ? 1 : process;
|
||||
|
||||
var cadences = RiderDatas.Where(a => a._Cadence.HasValue && a._Cadence.Value > 0);
|
||||
if (cadences.Any())
|
||||
{
|
||||
interruptRecord.AverageCadence = Math.Round(cadences.Average(a => a._Cadence.GetValueOrDefault(0)));
|
||||
}
|
||||
interruptRecord.MaxCadence = Math.Round(RiderDatas.Max(a => a._Cadence.GetValueOrDefault(0)));
|
||||
interruptRecord.AverageHeartRate = Math.Round(RiderDatas.Average(a => a._HeartRate.GetValueOrDefault(0)));
|
||||
interruptRecord.MaxHeartRate = RiderDatas.Max(a => a._HeartRate.GetValueOrDefault(0));
|
||||
//service.CreateRecordCyclingData(interruptRecord);
|
||||
//保存骑行记录txt
|
||||
|
||||
//var path = Helper.GetDataDir("MapWorkoutRecords" + "/" + interruptRecord.Id);
|
||||
//var path = PFConstants.MapWorkoutRecordFolder + "/" + interruptRecord.Id;
|
||||
var fname = path + "/" + newFileName + ".txt";
|
||||
var files = new List<string>();
|
||||
using (var fs = new FileInfo(fname).OpenWrite())
|
||||
{
|
||||
var stream = new StreamWriter(fs);
|
||||
stream.BaseStream.Seek(0, SeekOrigin.End);
|
||||
foreach (var item in RiderDatas)
|
||||
{
|
||||
stream.Write(item.Write() + "\r\n");
|
||||
}
|
||||
stream.Flush();
|
||||
stream.Close();
|
||||
files.Add(fname);
|
||||
}
|
||||
//图片
|
||||
if (!string.IsNullOrEmpty(imageName))
|
||||
{
|
||||
files.Add(imageName);
|
||||
}
|
||||
//持久化序列化对象
|
||||
var recordString = JsonConvert.SerializeObject(interruptRecord);
|
||||
var recordFilePath = path + "/" + "record" + ".txt";
|
||||
System.IO.File.WriteAllText(recordFilePath, recordString);
|
||||
|
||||
recordData.Add(interruptRecord, files);
|
||||
Saved = true;
|
||||
SaveDataAysnc(recordData, path);
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存数据
|
||||
/// </summary>
|
||||
/// <param name="base64Image"></param>
|
||||
/// <returns></returns>
|
||||
public void SaveDataAysnc(Dictionary<MapInterruptRecord, List<string>> data,string path)
|
||||
{
|
||||
if (data != null && data.Count > 0)
|
||||
{
|
||||
//var path = Helper.GetDataDir("MapWorkoutRecords");
|
||||
Task.Run(() => {
|
||||
var record = data.FirstOrDefault();
|
||||
MapInterruptRecordApi service = new MapInterruptRecordApi();
|
||||
var result = service.Add(record.Key, record.Value);
|
||||
|
||||
//删除文件
|
||||
try
|
||||
{
|
||||
if (result.result && Directory.Exists(path))
|
||||
{
|
||||
Helper.DelectDir(path);
|
||||
Saved = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log(e.Message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11c5f863a5d0baa49b7b374090197f99
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,13 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
public class RideSetting
|
||||
{
|
||||
public double sensitivity { set; get; }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bdb001023de8f942b52de4e72bc45e6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7b3cc03af7b19e44b20d0b929a53d45
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
public abstract class BaseRider
|
||||
{
|
||||
//internal static MapWorkoutService service = new MapWorkoutService();
|
||||
|
||||
public abstract RiderType riderType { get; }
|
||||
/// <summary>
|
||||
/// 用户Id
|
||||
/// </summary>
|
||||
public int UserId { get; set; }
|
||||
|
||||
public string InMapId
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.riderType.ToString() + "-" + UserId;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 用户姓名
|
||||
/// </summary>
|
||||
public string NickName { get; set; }
|
||||
/// <summary>
|
||||
/// 微信头像
|
||||
/// </summary>
|
||||
public string WxHeadImg { get; set; }
|
||||
/// <summary>
|
||||
/// 最后骑行的距离
|
||||
/// </summary>
|
||||
public double EndDistance { get; set; }
|
||||
/// <summary>
|
||||
/// 是否是当前登陆人
|
||||
/// </summary>
|
||||
public bool IsSelf
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.UserId == App.CurrentUser.Id;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 圆形头像
|
||||
/// </summary>
|
||||
public string CircHeadImg
|
||||
{
|
||||
get
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a318f90ef1c36742a0ffa27baa04c98
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,61 +0,0 @@
|
||||
using GeoJSON.Net.Geometry;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model.RiderModels
|
||||
{
|
||||
public class OnlineRiderModel : BaseRider
|
||||
{
|
||||
public override RiderType riderType => RiderType.Online;
|
||||
|
||||
public double PreDistance { get; set; } = 0;
|
||||
public double WeightKg { get; set; } = 0;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public GeographicPosition Point { get; set; }
|
||||
|
||||
public OutUser GetOutUser(double preDistance, double currentDistance, TurfHelper turfHelper, CyclingStateEnum cyclingState)
|
||||
{
|
||||
if (this.IsSelf)
|
||||
{
|
||||
var newRealUser = new OutUser()
|
||||
{
|
||||
NickName = this.NickName,
|
||||
WxHeadImg = this.WxHeadImg,
|
||||
UserId = this.UserId,
|
||||
//targetData = targetData,
|
||||
InMapId = this.InMapId,
|
||||
PreDistance = preDistance,
|
||||
NextDistance = currentDistance,
|
||||
Point = turfHelper.Along(currentDistance),
|
||||
};
|
||||
if (cyclingState != CyclingStateEnum.Cycling)
|
||||
{
|
||||
newRealUser.NextDistance = preDistance;
|
||||
}
|
||||
return newRealUser;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newRealUser = new OutUser()
|
||||
{
|
||||
NickName = this.NickName,
|
||||
WxHeadImg = this.WxHeadImg,
|
||||
UserId = this.UserId,
|
||||
//targetData = targetData,
|
||||
InMapId = this.InMapId,
|
||||
PreDistance = this.PreDistance,
|
||||
NextDistance = this.EndDistance,
|
||||
Point = this.Point, //turfHelper.Along(this.EndDistance)
|
||||
};
|
||||
return newRealUser;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83879fd24afab69418f97cb56eaebda7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,55 +0,0 @@
|
||||
using GeoJSON.Net.Geometry;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model.RiderModels
|
||||
{
|
||||
/// <summary>
|
||||
/// 骑行伴侣
|
||||
/// </summary>
|
||||
public class ReviewRiderModel : BaseRider
|
||||
{
|
||||
public override RiderType riderType => RiderType.Review;
|
||||
|
||||
public GeographicPosition Point { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 骑行记录数据
|
||||
/// </summary>
|
||||
public string[] record { get; set; }
|
||||
|
||||
public OutUser GetOutUser(int ticks, TurfHelper turfHelper)
|
||||
{
|
||||
var reviewer = this;
|
||||
TargetData revierData = null;
|
||||
if (ticks >= reviewer.record.Length)
|
||||
{
|
||||
revierData = TargetData.Read(reviewer.record[reviewer.record.Length - 1]);
|
||||
}
|
||||
else if (ticks > 0)
|
||||
{
|
||||
revierData = TargetData.Read(reviewer.record[ticks - 1]);
|
||||
}
|
||||
//(Ticks >= reviewer.record.Length ? TargetData.Read(reviewer.record[reviewer.record.Length - 1]) :
|
||||
//TargetData.Read(reviewer.record[Ticks]));
|
||||
var reivewPreDistance = ticks == 1 || ticks == 0 ? 0 :
|
||||
(ticks >= reviewer.record.Length ? TargetData.Read(reviewer.record[reviewer.record.Length - 1])._Distance :
|
||||
TargetData.Read(reviewer.record[ticks - 2])._Distance);
|
||||
var result = new OutUser()
|
||||
{
|
||||
UserId = this.UserId,
|
||||
//targetData = revierData,
|
||||
InMapId = this.InMapId,
|
||||
PreDistance = reivewPreDistance,
|
||||
NextDistance = ticks == 0 ? 0 : revierData._Distance,
|
||||
NickName = this.NickName,
|
||||
WxHeadImg = this.WxHeadImg
|
||||
};
|
||||
result.Point = turfHelper.Along(result.NextDistance);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d265479686613e418a745e888533ec5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,369 +0,0 @@
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
public class Route
|
||||
{
|
||||
/// <summary>
|
||||
/// 路线实例
|
||||
/// </summary>
|
||||
public MapRoute RouteInstance { get; private set; }
|
||||
/// <summary>
|
||||
/// 从服务端获取的Json数据
|
||||
/// </summary>
|
||||
public MapDataModel JsonData { get; set; }
|
||||
/// <summary>
|
||||
/// 当前路书的排行榜信息
|
||||
/// </summary>
|
||||
public List<MapRecordRanking> RecordRankings { get; set; }
|
||||
|
||||
private List<double[]> _Point = null;
|
||||
/// <summary>
|
||||
/// 点位信息
|
||||
/// </summary>
|
||||
public List<double[]> Point
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Point == null)
|
||||
{
|
||||
_Point = JsonData.List.Select(n => n.Point.Reverse().ToArray()).ToList();
|
||||
}
|
||||
return _Point;
|
||||
}
|
||||
}
|
||||
private List<double> _Elevation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 海拔信息
|
||||
/// </summary>
|
||||
public List<double> Elevation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Elevation == null)
|
||||
{
|
||||
_Elevation = JsonData.List.Select(n => n.Elevation).ToList();
|
||||
}
|
||||
return _Elevation;
|
||||
}
|
||||
}
|
||||
|
||||
private List<double> _SlopeGrade { get; set; }
|
||||
/// <summary>
|
||||
/// 坡度信息
|
||||
/// </summary>
|
||||
public List<double> SlopeGrade
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_SlopeGrade == null)
|
||||
{
|
||||
//_SlopeGrade = CalPatch();
|
||||
_SlopeGrade = JsonData.List.Select(d => d.Grade).ToList();
|
||||
}
|
||||
return _SlopeGrade;
|
||||
}
|
||||
}
|
||||
private List<double> _StepDistance { get; set; }
|
||||
/// <summary>
|
||||
/// 每两点的距离
|
||||
/// </summary>
|
||||
public List<double> StepDistance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_StepDistance == null)
|
||||
{
|
||||
_StepDistance = JsonData.List.Select(n => n.Distance).ToList();
|
||||
}
|
||||
return _StepDistance;
|
||||
}
|
||||
}
|
||||
|
||||
public double? _TotalDistance { get; set; }
|
||||
|
||||
public double TotalDistance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_TotalDistance == null)
|
||||
{
|
||||
_TotalDistance = GetTotalDistance();
|
||||
}
|
||||
return (double)_TotalDistance;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每一小步到起点的距离
|
||||
/// </summary>
|
||||
private List<double> _StepToStartDistance;
|
||||
|
||||
public List<double> StepToStartDistance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_StepToStartDistance == null)
|
||||
{
|
||||
_StepToStartDistance = GetStepToStartDistance();
|
||||
}
|
||||
return _StepToStartDistance;
|
||||
}
|
||||
}
|
||||
|
||||
public Route(MapDataModel data)
|
||||
{
|
||||
JsonData = data;
|
||||
}
|
||||
|
||||
public Route(MapDataModel data, MapRoute mapRoute)
|
||||
{
|
||||
RouteInstance = mapRoute;
|
||||
JsonData = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// km
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public double GetTotalDistance()
|
||||
{
|
||||
var total = 0d;
|
||||
for (int i = 0; i < JsonData.List.Count - 1; i++)
|
||||
{
|
||||
var current = JsonData.List[i];
|
||||
var next = JsonData.List[i + 1];
|
||||
total += TurfHelper.GetDistances(new double[] { current.Point[1], current.Point[0] }, new double[] { next.Point[1], next.Point[0] });
|
||||
}
|
||||
return total / 1000;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据下标获取海拔
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public double GetElevationByIndex(int index)
|
||||
{
|
||||
if (index > this.Elevation.Count)
|
||||
{
|
||||
return this.Elevation.Last();
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Elevation[index];
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据下标获取距离的小段
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public double GetDistanceStepByIndex(int index)
|
||||
{
|
||||
if (index > this.StepDistance.Count)
|
||||
{
|
||||
return this.StepDistance.Last();
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.StepDistance[index];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据索引获取坡度
|
||||
/// </summary>
|
||||
/// <param name="index">索引</param>
|
||||
/// <param name="average">是否需要平均坡度</param>
|
||||
/// <returns></returns>
|
||||
public double GetPatchByIndex(int index, bool average, double endDistance = 0, double cacheDistance = 5)
|
||||
{
|
||||
double slop = 0;
|
||||
if (average)
|
||||
{
|
||||
//每一小段的距离
|
||||
double step = GetDistanceStepByIndex(index);
|
||||
//每一段到起点的距离
|
||||
double stepToStart = GetStepToStartDistanceByIndex(index);
|
||||
//当前骑行距离与前一段的绝对值之差
|
||||
double absoluteValue = step - (stepToStart - endDistance);
|
||||
//绝对值之差是否大于多少米,如果大于则返回原始坡度,如果小于则返回平均坡度
|
||||
if (absoluteValue < cacheDistance && cacheDistance < step)
|
||||
{
|
||||
if (index >= this.SlopeGrade.Count - 1)
|
||||
{
|
||||
double slope = this.SlopeGrade.Last();
|
||||
//if (slope > 10)
|
||||
//{
|
||||
// slop = 10;
|
||||
//}
|
||||
//else if (slope < -10)
|
||||
//{
|
||||
// slop = -10;
|
||||
//}
|
||||
//else
|
||||
{
|
||||
slop = slope / 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
double slope = this.SlopeGrade[index];
|
||||
//if (slope > 10)
|
||||
//{
|
||||
// slop = 10;
|
||||
//}
|
||||
//else if (slope < -10)
|
||||
//{
|
||||
// slop = -10;
|
||||
//}
|
||||
//else
|
||||
{
|
||||
slop = slope / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (index >= this.SlopeGrade.Count - 1)
|
||||
{
|
||||
slop = this.SlopeGrade.Last();
|
||||
}
|
||||
else
|
||||
{
|
||||
slop = this.SlopeGrade[index];
|
||||
}
|
||||
}
|
||||
//if (slop > 10)
|
||||
//{
|
||||
// return 10;
|
||||
//}
|
||||
//if (slop < -10)
|
||||
//{
|
||||
// return -10;
|
||||
//}
|
||||
return slop;
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据距离获取点位下标
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetStepIndex(double distance)
|
||||
{
|
||||
distance *= 1000;//将距离转化为米
|
||||
var totalDistance = 0D;
|
||||
var index = 0;
|
||||
foreach (var item in this.StepDistance)
|
||||
{
|
||||
totalDistance += item;
|
||||
if (totalDistance > distance)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
if (distance > this.StepDistance[this.StepDistance.Count - 1])
|
||||
{
|
||||
return this.StepDistance.Count - 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 通过索引获取当前到起点的距离(单位m)
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public double GetStepToStartDistanceByIndex(int index)
|
||||
{
|
||||
if (index >= this.StepToStartDistance.Count - 1)
|
||||
{
|
||||
return this.StepToStartDistance.Last();
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.StepToStartDistance[index];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算每一段路程的斜率
|
||||
/// </summary>
|
||||
private List<double> CalPatch()
|
||||
{
|
||||
if (this.Elevation != null)
|
||||
{
|
||||
List<double> grade = new List<double>();
|
||||
for (int i = 0; i < this.Point.Count - 1; i++)
|
||||
{
|
||||
var a = this.Elevation[i + 1] - this.Elevation[i];
|
||||
if (a == 0)
|
||||
{
|
||||
grade.Add(0);
|
||||
continue;
|
||||
}
|
||||
//勾股定理
|
||||
var c = this.StepDistance[i];//如果车停了下来,c为0
|
||||
if (c == 0 && i > 0)
|
||||
{
|
||||
grade.Add(grade[grade.Count - 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
var b = Math.Sqrt(c * c - a * a);
|
||||
if (b == 0)//如果b等于,这就是垂直的墙壁
|
||||
{
|
||||
grade.Add(grade[grade.Count - 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
grade.Add(a / b * 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
//检是否有NaN的值
|
||||
for (int i = 0; i < grade.Count; i++)
|
||||
{
|
||||
if (double.IsNaN(grade[i]) && i != 0)
|
||||
{
|
||||
grade[i] = grade[i - 1];
|
||||
}
|
||||
else if (double.IsNaN(grade[i]) && i == 0)
|
||||
{
|
||||
grade[i] = 0;
|
||||
}
|
||||
}
|
||||
return grade;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取每一段到起点的距离
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private List<double> GetStepToStartDistance()
|
||||
{
|
||||
if (StepDistance != null)
|
||||
{
|
||||
List<double> stepToStartDis = new List<double>();
|
||||
double start = 0;
|
||||
for (int i = 0; i < StepDistance.Count; i++)
|
||||
{
|
||||
start += StepDistance[i];
|
||||
stepToStartDis.Add(start);
|
||||
}
|
||||
return stepToStartDis;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b4a6fa5405752242a577299e27df510
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
public class SelectParamModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 在线用户ID,跟骑选的用户
|
||||
/// </summary>
|
||||
public int OnlineUserId { get; set; }
|
||||
/// <summary>
|
||||
/// 继续骑行的标志
|
||||
/// </summary>
|
||||
public string ContinueMark { get; set; }
|
||||
/// <summary>
|
||||
/// 当前第几次骑行
|
||||
/// </summary>
|
||||
public int? ContinueIndex { get; set; }
|
||||
/// <summary>
|
||||
/// 路线Id
|
||||
/// </summary>
|
||||
public int RouteId { get; set; }
|
||||
/// <summary>
|
||||
/// 赛事Id
|
||||
/// </summary>
|
||||
public int CompetitionId { get; set; }
|
||||
/// <summary>
|
||||
/// 最后一次骑行的距离
|
||||
/// </summary>
|
||||
public double EndDistance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排名信息Id,用于骑行回顾,多人
|
||||
/// </summary>
|
||||
public List<string> RankingsId { get; set; }
|
||||
///// <summary>
|
||||
///// 是否为全球骑行的继续骑行
|
||||
///// </summary>
|
||||
//public bool GlobalContinue { get; set; }
|
||||
|
||||
public int GlobalCyclingId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fab2eae6e723baa46ad8c972556f38c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,74 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 指标数据
|
||||
/// </summary>
|
||||
public class TargetData
|
||||
{
|
||||
public double _Power = 0d;
|
||||
public double _Speed = 0;
|
||||
/// <summary>
|
||||
/// km
|
||||
/// </summary>
|
||||
public double _Distance { get; set; } = 0D;
|
||||
public double? _Cadence = 0;
|
||||
public int? _HeartRate = 0;
|
||||
public int Ticks = 0;
|
||||
/// <summary>
|
||||
/// 纬度
|
||||
/// </summary>
|
||||
public double _Lat { get; set; } = 0d;
|
||||
/// <summary>
|
||||
/// 经度
|
||||
/// </summary>
|
||||
public double _Lon { get; set; } = 0d;
|
||||
|
||||
public double _TotalClimb { get; set; } = 0d;
|
||||
|
||||
//public double _Bearing = 0d;
|
||||
|
||||
public TargetData Clone()
|
||||
{
|
||||
return (TargetData)MemberwiseClone();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format($"Ticks:{Ticks} Power:{_Power} Speed:{_Speed} Distance:{_Distance} Cadence:{_Cadence} HeartRate:{_HeartRate} Lat:{_Lat} Lon:{_Lon}");
|
||||
}
|
||||
|
||||
public string Write()
|
||||
{
|
||||
return string.Format($"{ Ticks },{ _Power.ToString(CultureInfo.InvariantCulture) },{ _Speed.ToString(CultureInfo.InvariantCulture) },{ Math.Round(_Distance, 6).ToString(CultureInfo.InvariantCulture) },{ (_Cadence == null ? "" : _Cadence.Value.ToString(CultureInfo.InvariantCulture)) },{ (_HeartRate == null ? "null" : _HeartRate.Value.ToString(CultureInfo.InvariantCulture)) },{ Math.Round(_Lat, 6).ToString(CultureInfo.InvariantCulture) },{ Math.Round(_Lon, 6).ToString(CultureInfo.InvariantCulture) }");//,{_Bearing}
|
||||
}
|
||||
|
||||
public static TargetData Read(string data)
|
||||
{
|
||||
string[] split = data.Split(',');
|
||||
var target = new TargetData();
|
||||
target.Ticks = Convert.ToInt32(split[0], CultureInfo.InvariantCulture); //int.Parse(split[0]);
|
||||
target._Power = Convert.ToDouble(split[1], CultureInfo.InvariantCulture);
|
||||
target._Speed = Convert.ToDouble(split[2], CultureInfo.InvariantCulture);// double.Parse(split[2]);
|
||||
target._Distance = Convert.ToDouble(split[3], CultureInfo.InvariantCulture); //double.Parse(split[3]);
|
||||
target._Cadence = Convert.ToDouble(split[4], CultureInfo.InvariantCulture); //double.Parse(split[4]);
|
||||
if (!string.IsNullOrWhiteSpace(split[5]) && split[5] != "null")
|
||||
{
|
||||
target._HeartRate = Convert.ToInt32(split[5], CultureInfo.InvariantCulture); //int.Parse(split[5]);
|
||||
}
|
||||
if (split.Length > 6)
|
||||
{
|
||||
target._Lat = Convert.ToDouble(split[6], CultureInfo.InvariantCulture); //double.Parse(split[6]);
|
||||
target._Lon = Convert.ToDouble(split[7], CultureInfo.InvariantCulture); //double.Parse(split[7]);
|
||||
//target._Bearing = double.Parse(split[8]);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79850d6cccee69445927e491750a500b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,56 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
public class t_user
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Nickname { get; set; }
|
||||
/// <summary>
|
||||
/// 用户的性别,值为1时是男性,值为2时是女性,值为0时是未知
|
||||
/// </summary>
|
||||
public int Sex { get; set; }
|
||||
public int Unit { get; set; }
|
||||
public double Weight { get; set; }
|
||||
public int FTP { get; set; }
|
||||
public int WheelDiameter { get; set; }
|
||||
public string Phone { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Pass { get; set; }
|
||||
public string OtherPlatforms { get; set; }
|
||||
public string Country { get; set; }
|
||||
public string Province { get; set; }
|
||||
public string City { get; set; }
|
||||
public string Area { get; set; }
|
||||
public string WxHeadImg { get; set; }
|
||||
public DateTime LastLoginTime { get; set; }
|
||||
/// <summary>
|
||||
/// 自动暂停
|
||||
/// </summary>
|
||||
public bool AutoPause { get; set; }
|
||||
/// <summary>
|
||||
/// 最大心率
|
||||
/// </summary>
|
||||
public int MaxHeartRate { get; set; }
|
||||
|
||||
public bool CanEditRoom { get; set; }
|
||||
/// <summary>
|
||||
/// 自行车重
|
||||
/// </summary>
|
||||
public double BicycleWeight { get; set; }
|
||||
|
||||
public string Contact { get; set; }
|
||||
|
||||
public string ContactPhone { get; set; }
|
||||
|
||||
public string ContactAddress { get; set; }
|
||||
/// <summary>
|
||||
/// 阻力灵敏度
|
||||
/// </summary>
|
||||
public int Sensitivity { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d977fd7941debf4b90f950a8fd3c0a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0b6448d57a2ab249a67f66c160c8293
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,18 +0,0 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Network
|
||||
{
|
||||
interface IService
|
||||
{
|
||||
void Start(Action<List<ReceiveMsgModel>> action);
|
||||
|
||||
void Send(byte[] dgram, int bytes);
|
||||
|
||||
void Close();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04b976b21b69ff640956ca0574491797
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,472 +0,0 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scenes.Ride.Scripts.Network;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class MapUDPService
|
||||
{
|
||||
private static IService _udpService;
|
||||
//private static UdpClient udpClient;
|
||||
//private static IPEndPoint iPEndPoint;
|
||||
private static bool isExit = false;
|
||||
//private static Task task = null;
|
||||
//private static CancellationTokenSource cts { get; set; }
|
||||
private static CancellationToken ct { get; set; }
|
||||
//private static List<OnlineUser> onlineUsers { get; set; } = new List<OnlineUser>();
|
||||
private static System.Timers.Timer heartbeat { get; set; }
|
||||
public static bool Pause { get; set; } = false;
|
||||
|
||||
private static OnlineUserHelper _onlineUserHelper;
|
||||
private static OnlineUserHelper onlineUserHelper
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_onlineUserHelper == null)
|
||||
{
|
||||
_onlineUserHelper = new OnlineUserHelper();
|
||||
}
|
||||
return _onlineUserHelper;
|
||||
}
|
||||
}
|
||||
private static DateTime LastActiveTime = DateTime.Now;
|
||||
private static List<ReceiveMsgModel> msgs = new List<ReceiveMsgModel>();
|
||||
/// <summary>
|
||||
/// 初始化(如果UDP服务未启动,则会已没5秒一次不断尝试,直到连接上为止,前端不需要考虑任何UDP连接的事情)
|
||||
/// </summary>
|
||||
public static void Init(int competitionid = 0, bool isWatch = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
Competitionid = competitionid;
|
||||
IsWatch = isWatch;
|
||||
//var ddd = new MapWorkoutService().GetRealOnlineUserInfo(new List<int> { 6 });
|
||||
isExit = false;
|
||||
Pause = false;
|
||||
|
||||
if (_udpService == null)
|
||||
{
|
||||
_udpService = new TcpService1();
|
||||
|
||||
_udpService.Start(list =>
|
||||
{
|
||||
LastActiveTime = DateTime.Now;
|
||||
//onlineUserHelper.RemoveExceptionData(list);
|
||||
msgs = list;
|
||||
onlineUserHelper.SetOnlineUser(msgs);
|
||||
});
|
||||
|
||||
heartbeat = new System.Timers.Timer();
|
||||
heartbeat.Interval = 1000;
|
||||
heartbeat.AutoReset = true;
|
||||
heartbeat.Enabled = true;
|
||||
heartbeat.Elapsed += Heartbeat_Elapsed;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Trace.WriteLine("UDP:" + e.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
//发送一条心跳包
|
||||
//SendHeartbeat();
|
||||
//告诉tcp服务器gzip
|
||||
}
|
||||
}
|
||||
|
||||
private static void Heartbeat_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
//超过一秒没有收到消息
|
||||
if ((now - LastActiveTime).TotalSeconds > 1)
|
||||
{
|
||||
onlineUserHelper.SetOnlineUser(new List<ReceiveMsgModel>());
|
||||
}
|
||||
if (now.Second % 20 == 0)
|
||||
{
|
||||
//LastActiveTime = now;
|
||||
SendHeartbeat();
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] Compress(string text)
|
||||
{
|
||||
var bytes = Encoding.Unicode.GetBytes(text);
|
||||
using (var mso = new MemoryStream())
|
||||
{
|
||||
using (var gs = new GZipStream(mso, CompressionMode.Compress))
|
||||
{
|
||||
gs.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
return mso.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static string Decompress(byte[] data)
|
||||
{
|
||||
// Read the last 4 bytes to get the length
|
||||
byte[] lengthBuffer = new byte[4];
|
||||
Array.Copy(data, data.Length - 4, lengthBuffer, 0, 4);
|
||||
int uncompressedSize = BitConverter.ToInt32(lengthBuffer, 0);
|
||||
|
||||
var buffer = new byte[uncompressedSize];
|
||||
using (var ms = new MemoryStream(data))
|
||||
{
|
||||
using (var gzip = new GZipStream(ms, CompressionMode.Decompress))
|
||||
{
|
||||
gzip.Read(buffer, 0, uncompressedSize);
|
||||
}
|
||||
}
|
||||
return Encoding.Unicode.GetString(buffer);
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送心跳包
|
||||
/// </summary>
|
||||
private static void SendHeartbeat()
|
||||
{
|
||||
try
|
||||
{
|
||||
var model = new
|
||||
{
|
||||
CommandType = 0,
|
||||
};
|
||||
var sendBytes = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
_udpService.Send(sendBytes, sendBytes.Length);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("发送心跳失败:" + e);
|
||||
}
|
||||
}
|
||||
public static int Competitionid { get; set; }
|
||||
|
||||
public static bool IsWatch { get; set; }
|
||||
/// <summary>
|
||||
/// 告诉TCP服务器给我Gzip的格式
|
||||
/// </summary>
|
||||
public static void SendGizpModel()
|
||||
{
|
||||
try
|
||||
{
|
||||
var model = new GzipMsgModel
|
||||
{
|
||||
CommandType = 2,
|
||||
V = 2,
|
||||
Encoding = "gzip",
|
||||
Client = App.AppVersion,
|
||||
MemberId = App.CurrentUser.Id,
|
||||
Competitionid = Competitionid,
|
||||
IsWatch = IsWatch
|
||||
};
|
||||
var sendBytes = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
_udpService.Send(sendBytes, sendBytes.Length);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("发送失败:" + e);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送数据
|
||||
/// </summary>
|
||||
/// <param name="RouteId">路书Id</param>
|
||||
/// <param name="MemberId">用户id</param>
|
||||
/// <param name="Point">当前点位</param>
|
||||
/// <param name="prop">属性</param>
|
||||
/// <param name="IsCompleted">是否完成</param>
|
||||
/// <param name="exit">是否退出</param>
|
||||
public static void Send(int RouteId, int MemberId, double[] Point, bool IsCompleted = false, bool exit = false,
|
||||
double endDistance = 0, bool showVirtual = false, byte commandType = 1, double speed = 0, bool isVirtual = false, double preDistance = 0,
|
||||
double weightKg = 0, int competitionId = 0, bool saved = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
Point[0] = Math.Round(Point[0], 6, MidpointRounding.AwayFromZero);
|
||||
Point[1] = Math.Round(Point[1], 6, MidpointRounding.AwayFromZero);
|
||||
var model = new MsgModel
|
||||
{
|
||||
RouteId = RouteId,
|
||||
MemberId = MemberId,
|
||||
Point = Point,
|
||||
IsCompleted = IsCompleted,
|
||||
//exit = exit,
|
||||
EndDistance = endDistance,
|
||||
//ShowVirtual = showVirtual,
|
||||
CommandType = commandType,
|
||||
Speed = speed,
|
||||
//IsVirtual = isVirtual,
|
||||
PreDistance = preDistance,
|
||||
WeightKg = weightKg,
|
||||
Competitionid = competitionId,
|
||||
Saved = saved,
|
||||
//V = 1
|
||||
};
|
||||
var sendBytes = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(model));
|
||||
_udpService.Send(sendBytes, sendBytes.Length);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("发送失败:" + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
isExit = true;
|
||||
if (MapUDPService._udpService == null) return;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
Send(0, App.CurrentUser.Id, new double[] { 1, 1 }, true, isExit);
|
||||
}
|
||||
_udpService.Close();
|
||||
|
||||
//task.Dispose();
|
||||
_udpService = null;
|
||||
_onlineUserHelper = null;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
//停止计时
|
||||
if (heartbeat != null)
|
||||
{
|
||||
heartbeat.Stop();
|
||||
heartbeat.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static OnlineUser GetOnlineUserLastDataById(int userId)
|
||||
{
|
||||
//return _onlineUserHelper.GetOnlineUserLastDataById(userId);
|
||||
//var msg = msgs.Where(m => m.MemberId == userId);
|
||||
//if (msg == null) return null;
|
||||
return onlineUserHelper.OnlineUsers.FirstOrDefault(u => u.Id == userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据路书获取在线用户(非比赛用户不能看到比赛中的用户)
|
||||
/// </summary>
|
||||
/// <param name="routeId"></param>
|
||||
/// <returns></returns>
|
||||
public static List<OnlineUser> GetOnlineUsers(params int[] routeId)
|
||||
{
|
||||
var result = onlineUserHelper.OnlineUsers.Where(u => routeId.Contains(u.RouteId) && u.CompetitionId == 0).ToList();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//比赛中的人只能看到当前比赛的人
|
||||
public static List<OnlineUser> GetCompetitionOnlineUsers(int competitionId)
|
||||
{
|
||||
//var result = onlineUserHelper.OnlineUsers.Where(u => u.CompetitionId == competitionId && !u.IsWatcher).ToList();
|
||||
var result = onlineUserHelper.OnlineUsers.Where(u =>!u.IsWatcher).ToList();
|
||||
return result;
|
||||
}
|
||||
//当前比赛观察者
|
||||
public static List<OnlineUser> GetCompetitionWatchers(int competitionId,int size = 5)
|
||||
{
|
||||
//var result = onlineUserHelper.OnlineUsers.Where(u => u.CompetitionId == competitionId && u.IsWatcher).Take(size).ToList();
|
||||
var result = onlineUserHelper.OnlineUsers.Where(u =>u.IsWatcher).Take(size).ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int GetNearRiderCount()
|
||||
{
|
||||
return onlineUserHelper.OnlineUsers.Count();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取附近的人(当前在线的所有人)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IList<NearRiderModel> GetNearRiderData(int pageIndex, int pageSize = 5, double[] point = null)
|
||||
{
|
||||
if (point == null) return null;
|
||||
|
||||
var dict = new List<System.Tuple<double, OnlineUser>>();
|
||||
var allOnlineUsers = onlineUserHelper.OnlineUsers;
|
||||
foreach (var item in allOnlineUsers)
|
||||
{
|
||||
if (item.Id == App.CurrentUser.Id)
|
||||
{
|
||||
dict.Add(new Tuple<double, OnlineUser>(0, item));
|
||||
continue;
|
||||
}
|
||||
if (item.Point[0] != 0 && item.Point[1] != 0)
|
||||
{
|
||||
var distance = Math.Round(TurfHelper.GetDistances(point, item.Point) / 1000, 2);
|
||||
dict.Add(new Tuple<double, OnlineUser>(distance, item));
|
||||
}
|
||||
}
|
||||
var allList = dict.OrderBy(d => d.Item1);//.Select(d=>d.Item2);
|
||||
var list = allList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
||||
|
||||
var nearData = list.Select(n => new NearRiderModel()
|
||||
{
|
||||
Headimage = n.Item2.HeadImage,
|
||||
Name = n.Item2.Name,
|
||||
Near = n.Item1, //Math.Round(TurfHelper.GetDistances(point, n.Point) / 1000, 2),
|
||||
KGWeight = n.Item2.WeightKg.ToString(),
|
||||
Speed = Math.Round(n.Item2.Speed, 1),
|
||||
CountryImg = App.Host + $"User/GetCountryImg?userid={n.Item2.Id}",
|
||||
IsSelf = n.Item2.IsSelf,
|
||||
Id = n.Item2.Id,
|
||||
Country = n.Item2.Country,
|
||||
}).ToList();
|
||||
return nearData;
|
||||
//return new
|
||||
//{
|
||||
// NearData = nearData,
|
||||
// PageCount = (int)Math.Ceiling((double)allList.Count() / pageSize)
|
||||
//};
|
||||
}
|
||||
|
||||
|
||||
private class OnlineUserHelper
|
||||
{
|
||||
//public static List<OnlineUser> users { get; private set; }
|
||||
private static readonly object locker = new object();
|
||||
|
||||
|
||||
private readonly List<OnlineUser> onlineUsers = new List<OnlineUser>();
|
||||
public List<OnlineUser> OnlineUsers
|
||||
{
|
||||
get
|
||||
{
|
||||
//if((DateTime.Now - LastActiveTime).TotalSeconds > 1)
|
||||
//{
|
||||
// SetOnlineUser(new List<ReceiveMsgModel>());
|
||||
//}
|
||||
return onlineUsers.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置在线的人员
|
||||
/// </summary>
|
||||
public void SetOnlineUser(List<ReceiveMsgModel> mes)
|
||||
{
|
||||
try
|
||||
{
|
||||
var msgs = RemoveExceptionData(mes);
|
||||
//LastActiveTime = DateTime.Now;
|
||||
var ids = msgs.Where(m => onlineUsers.All(u => u.Id != m.MemberId)).Select(m => m.MemberId);
|
||||
if (ids.Any())
|
||||
{
|
||||
MapApi api = new MapApi();
|
||||
var rangeUser = api.GetOnlineUserInfo(ids).data;
|
||||
onlineUsers.AddRange(rangeUser);
|
||||
}
|
||||
foreach (var user in onlineUsers)
|
||||
{
|
||||
var item = msgs.FirstOrDefault(u => u.MemberId == user.Id);
|
||||
if (item != null)
|
||||
{
|
||||
user.LastActiveTime = DateTime.Now;
|
||||
user.RouteId = item.RouteId;
|
||||
user.Point = item.Point;
|
||||
user.IsCompleted = item.IsCompleted;
|
||||
//user.exit = item.exit;
|
||||
user.EndDistance = item.EndDistance;
|
||||
user.IsVirtual = item.MemberId < 0;
|
||||
user.Speed = item.Speed;
|
||||
user.WeightKg = item.WeightKg;
|
||||
user.PreDistance = item.PreDistance;
|
||||
user.CompetitionId = item.Competitionid;
|
||||
user.Saved = item.Saved;
|
||||
user.WatcherList = new List<int>();
|
||||
foreach (var o in item.WatchIdList.Split('|'))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(o))
|
||||
{
|
||||
user.WatcherList.Add(Convert.ToInt32(o));
|
||||
}
|
||||
}
|
||||
user.IsWatcher = user.WatcherList.Contains(item.MemberId);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.PreDistance = user.EndDistance;
|
||||
}
|
||||
}
|
||||
onlineUsers.RemoveAll(u => u.IsLost);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
#if DEBUG
|
||||
throw;
|
||||
#endif
|
||||
//return new List<OnlineUser>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 去除重复数据,去除坐标为0的数据
|
||||
/// </summary>
|
||||
/// <param name="mes"></param>
|
||||
private List<ReceiveMsgModel> RemoveExceptionData(List<ReceiveMsgModel> mes)
|
||||
{
|
||||
var list = mes.ToList();
|
||||
//去除自己的数据和命令包
|
||||
//mes.RemoveAll(item => item.MemberId == App.CurrentUser.Id || item.Point[0] == 0);
|
||||
list.RemoveAll(item => item.Point[0] == 0 && item.Point[1] == 0);
|
||||
//去除重复数据
|
||||
list = list.Distinct(new OlineUserComparer()).ToList();
|
||||
|
||||
return list;
|
||||
}
|
||||
public class NearUserComparer : IEqualityComparer<NearRiderModel>
|
||||
{
|
||||
public bool Equals(NearRiderModel x, NearRiderModel y)
|
||||
{
|
||||
if (x == null)
|
||||
return y == null;
|
||||
return x.Name == y.Name;
|
||||
}
|
||||
|
||||
public int GetHashCode(NearRiderModel obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return 0;
|
||||
return obj.Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public class OlineUserComparer : IEqualityComparer<ReceiveMsgModel>
|
||||
{
|
||||
public bool Equals(ReceiveMsgModel x, ReceiveMsgModel y)
|
||||
{
|
||||
if (x == null)
|
||||
return y == null;
|
||||
return x.MemberId == y.MemberId;
|
||||
}
|
||||
|
||||
public int GetHashCode(ReceiveMsgModel obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return 0;
|
||||
return obj.MemberId.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f01b9ae72517c36488f04fdbbb889f71
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,183 +0,0 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scripts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Network
|
||||
{
|
||||
public class TcpService1 : IService
|
||||
{
|
||||
private bool isExit = false;
|
||||
private PfTcpClient _tcpClient;
|
||||
private IPEndPoint iPEndPoint;
|
||||
//private Action<List<ReceiveMsgModel>> _action;
|
||||
|
||||
public void Start(Action<List<ReceiveMsgModel>> action)
|
||||
{
|
||||
if (_tcpClient == null)
|
||||
{
|
||||
//if (!IPAddress.TryParse(ConfigHelper.ServerIpAdress, out var ipString))
|
||||
//{
|
||||
// throw new ArgumentException("IP地址不正确");
|
||||
//}
|
||||
|
||||
//服务端端口
|
||||
iPEndPoint = App.TcpAddress;
|
||||
_tcpClient = new PfTcpClient(iPEndPoint.Address.ToString(), iPEndPoint.Port, action);
|
||||
_tcpClient.OptionNoDelay = true;
|
||||
//_action = action;
|
||||
|
||||
_tcpClient.ConnectAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public void Send(byte[] dgram, int bytes)
|
||||
{
|
||||
if (_tcpClient == null) return;
|
||||
if (_tcpClient.IsConnected == false) return;
|
||||
//_tcpClient.WriteLine(System.Text.Encoding.ASCII.GetString(dgram));
|
||||
var txt = System.Text.Encoding.ASCII.GetString(dgram);
|
||||
//Debug.WriteLine("发送:"+txt);
|
||||
_tcpClient.Send(txt);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
isExit = true;
|
||||
_tcpClient.DisconnectAndStop();
|
||||
|
||||
_tcpClient = null;
|
||||
}
|
||||
|
||||
|
||||
class PfTcpClient : NetCoreServer.TcpClient
|
||||
{
|
||||
private bool _stop;
|
||||
Action<List<ReceiveMsgModel>> _action;
|
||||
public PfTcpClient(string address, int port, Action<List<ReceiveMsgModel>> action) : base(address, port)
|
||||
{
|
||||
_action = action;
|
||||
}
|
||||
|
||||
public void DisconnectAndStop()
|
||||
{
|
||||
_stop = true;
|
||||
DisconnectAsync();
|
||||
while (IsConnected)
|
||||
{
|
||||
Thread.Yield();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnConnected()
|
||||
{
|
||||
base.OnConnected();
|
||||
MapUDPService.SendGizpModel();
|
||||
}
|
||||
|
||||
protected override void OnDisconnected()
|
||||
{
|
||||
//base.OnDisconnected();
|
||||
Debug.WriteLine("tcp断线,3秒后重连");
|
||||
Thread.Sleep(3000);
|
||||
|
||||
if (!_stop)
|
||||
{
|
||||
ConnectAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public string Decompress(byte[] data)
|
||||
{
|
||||
// Read the last 4 bytes to get the length
|
||||
byte[] lengthBuffer = new byte[4];
|
||||
Array.Copy(data, data.Length - 4, lengthBuffer, 0, 4);
|
||||
int uncompressedSize = BitConverter.ToInt32(lengthBuffer, 0);
|
||||
|
||||
var buffer = new byte[uncompressedSize];
|
||||
using (var ms = new MemoryStream(data))
|
||||
{
|
||||
using (var gzip = new GZipStream(ms, CompressionMode.Decompress))
|
||||
{
|
||||
gzip.Read(buffer, 0, uncompressedSize);
|
||||
}
|
||||
}
|
||||
return Encoding.UTF8.GetString(buffer);
|
||||
}
|
||||
|
||||
private string temp = "";
|
||||
protected override void OnReceived(byte[] buffer, long offset, long size)
|
||||
{
|
||||
//base.OnReceived(buffer, offset, size);
|
||||
var returnData = Encoding.UTF8.GetString(buffer, (int)offset, (int)size);
|
||||
//*sdfsd#*sdfsd#*sdfsd#*sdfsd#
|
||||
foreach (var item in returnData)
|
||||
{
|
||||
if (item != '*' && item != '#')
|
||||
{
|
||||
temp += item;
|
||||
}
|
||||
|
||||
if (item == '#')
|
||||
{
|
||||
//解压 temp
|
||||
var uncompressStr = Decompress(Convert.FromBase64String(temp));
|
||||
#if UNITY_EDITOR
|
||||
Console.WriteLine(uncompressStr);
|
||||
#endif
|
||||
var list = new List<ReceiveMsgModel>();
|
||||
//数据解析 l{},w{1|2|3|4} l:列表 w:观察者模式
|
||||
var arr = uncompressStr.Split(';');
|
||||
foreach (var t in arr)
|
||||
{
|
||||
//列表
|
||||
if (t.IndexOf('l') == 0)
|
||||
{
|
||||
var l = t.Replace("l{", "").Replace("}", "");
|
||||
var itemList = l.Split('|');
|
||||
temp = "";
|
||||
|
||||
foreach (var obj in itemList)
|
||||
{
|
||||
var info = ReceiveMsgModel.Parse(obj);
|
||||
if (info != null)
|
||||
{
|
||||
list.Add(info);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//观察者
|
||||
if (t.IndexOf('w') == 0)
|
||||
{
|
||||
var w = t.Replace("w{", "").Replace("}", "");
|
||||
foreach (var o in list)
|
||||
{
|
||||
o.WatchIdList = w;
|
||||
}
|
||||
}
|
||||
}
|
||||
_action(list);
|
||||
}
|
||||
}
|
||||
//Debug.WriteLine("收到:" + returnData+"\r\n");
|
||||
//System.IO.File.AppendAllText(System.Environment.CurrentDirectory + "接收到的数据.txt", returnData.Trim().Replace("\0", "")+"\r\n", Encoding.UTF8);
|
||||
}
|
||||
|
||||
protected override void OnError(SocketError error)
|
||||
{
|
||||
//base.OnError(error);
|
||||
Debug.WriteLine(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d27070ad7cfef3418e8f764a42c08a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,94 +0,0 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scripts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts.Network
|
||||
{
|
||||
public class UdpService : IService
|
||||
{
|
||||
private bool isExit = false;
|
||||
private UdpClient udpClient;
|
||||
private IPEndPoint iPEndPoint;
|
||||
|
||||
public void Start(Action<List<ReceiveMsgModel>> action)
|
||||
{
|
||||
if (udpClient == null)
|
||||
{
|
||||
//if (!IPAddress.TryParse(ConfigHelper.ServerIpAdress, out var ipString))
|
||||
//{
|
||||
// throw new ArgumentException("IP地址不正确");
|
||||
//}
|
||||
|
||||
//服务端端口
|
||||
iPEndPoint = App.UdpAddress;
|
||||
udpClient = new UdpClient();
|
||||
uint IOC_IN = 0x80000000;
|
||||
uint IOC_VENDOR = 0x18000000;
|
||||
uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
|
||||
udpClient.Client.IOControl((int)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null);
|
||||
udpClient.Client.ReceiveTimeout = 5000;//这里如果不设置超时,会导致整个应用程序阻塞。
|
||||
udpClient.Client.SendTimeout = 5000;
|
||||
udpClient.Connect(iPEndPoint);
|
||||
//heartbeat = new System.Timers.Timer();
|
||||
//heartbeat.Interval = 1000;//20秒一次心跳包
|
||||
//heartbeat.AutoReset = true;
|
||||
//heartbeat.Enabled = true;
|
||||
//heartbeat.Elapsed += Heartbeat_Elapsed;
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
while (isExit == false)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] receiveBytes = udpClient.Receive(ref iPEndPoint);
|
||||
var returnData = Encoding.ASCII.GetString(receiveBytes);
|
||||
var list = new List<ReceiveMsgModel>();
|
||||
var itemList = returnData.Split('|');
|
||||
|
||||
foreach (var item in itemList)
|
||||
{
|
||||
var info = ReceiveMsgModel.Parse(item);
|
||||
if (info != null)
|
||||
{
|
||||
list.Add(info);
|
||||
}
|
||||
}
|
||||
action(list);
|
||||
}
|
||||
catch (SocketException ex)
|
||||
{
|
||||
await Task.Delay(6000);
|
||||
if (isExit == false && udpClient != null)
|
||||
{
|
||||
udpClient.Connect(iPEndPoint);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void Send(byte[] dgram, int bytes)
|
||||
{
|
||||
udpClient?.Send(dgram, bytes);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
isExit = true;
|
||||
udpClient?.Close();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 170d4696cbfb82743a9189608d3a162a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -28,7 +28,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
currentlatlong = mainController.GetCenterCoordinate();
|
||||
_playerController = FindObjectOfType<PlayerController>();
|
||||
//创建UI
|
||||
uiObject = transform.parent.Find("SingleUI/Panel/ArrowList");
|
||||
uiObject = transform.parent.Find("UI/Panel/ArrowList");
|
||||
if (mainController.cyclingController.Mode == CyclingModel.Competition)
|
||||
{
|
||||
arrowImage = Instantiate(Resources.Load<Image>("UI/Prefab/Match/CompetitionArrow"), uiObject);
|
||||
@@ -93,6 +93,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
var infoPos = playerScreenPos + new Vector3(150f, 60f, 0f);
|
||||
((RectTransform)infoPanel.transform).position = infoPos;
|
||||
CreateInfoLine(playerScreenPos, headPos);
|
||||
//头像
|
||||
var infoHead = infoPanel.transform.Find("Head").GetComponent<RawImage>();
|
||||
if (head != null)
|
||||
{
|
||||
@@ -100,15 +101,16 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
var infoName = infoPanel.transform.Find("Name").GetComponent<Text>();
|
||||
infoName.text = nickName;
|
||||
|
||||
//距离
|
||||
var infoDistance = infoPanel.transform.Find("Distance").GetComponent<Text>();
|
||||
if (_playerController != null)
|
||||
{
|
||||
infoDistance.text = diff > 0? $"+{diff}M" : $"{diff}M";
|
||||
}
|
||||
//功体比
|
||||
var infoWKG = infoPanel.transform.Find("WKG").GetComponent<Text>();
|
||||
infoWKG.text = weightKgStr;
|
||||
|
||||
//速度
|
||||
var speedText = infoPanel.transform.Find("Speed").GetComponent<Text>();
|
||||
speedText.text = speed.ToString("f1")+"KM/H";
|
||||
}
|
||||
@@ -218,6 +220,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
}
|
||||
|
||||
private double horizontalScrolling { get; set; }
|
||||
private void MoveHead()
|
||||
{
|
||||
var itemIndex = chartDataSourceScript.GetViewIndex(CurrentIndex);
|
||||
@@ -236,11 +239,11 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
else
|
||||
{
|
||||
if (UserId != mainController.currentPlayer.UserId)
|
||||
{
|
||||
headPanel.transform.position = new Vector3(itemPosition.x, itemPosition.y, 0);
|
||||
}
|
||||
else
|
||||
//if (UserId != mainController.currentPlayer.UserId)
|
||||
//{
|
||||
// headPanel.transform.position = new Vector3(itemPosition.x, itemPosition.y, 0);
|
||||
//}
|
||||
//else
|
||||
{
|
||||
int nextIndex = CurrentIndex;
|
||||
var viewIndex = chartDataSourceScript.GetViewIndex(nextIndex);
|
||||
@@ -250,7 +253,11 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
var currentDistance = CurrentDistance;
|
||||
var distance = Distance;
|
||||
var offset = currentDistance > 0 ? distance * 1000 / currentDistance : 1;
|
||||
graph.HorizontalScrolling += offset;
|
||||
horizontalScrolling += offset;
|
||||
if (UserId == mainController.currentPlayer.UserId)
|
||||
{
|
||||
graph.HorizontalScrolling = horizontalScrolling;
|
||||
}
|
||||
headPanel.transform.position = new Vector3(headPanel.transform.position.x, itemPosition.y, 0);
|
||||
}
|
||||
else
|
||||
@@ -284,12 +291,6 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
headPanel.SetActive(true);
|
||||
rect.DOScale(new Vector3(1.5f, 1.5f, 1.5f), 0.5f);
|
||||
//移动海拔图
|
||||
var currentDistance = CurrentDistance;
|
||||
var distance = Distance;
|
||||
var offset = currentDistance > 0 ? distance * 1000 / currentDistance : 1;
|
||||
graph.HorizontalScrolling += offset;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
_playerController = FindObjectOfType<PlayerController>();
|
||||
tickOffset = mainController.preticks;
|
||||
//创建UI
|
||||
uiObject = transform.parent.Find("SingleUI/Panel/ArrowList");
|
||||
uiObject = transform.parent.Find("UI/Panel/ArrowList");
|
||||
arrowImage = Instantiate(Resources.Load<Image>("UI/Prefab/Ride/ReviewArrow"), uiObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
trail.receiveShadows = false;
|
||||
trail.rayTracingMode = UnityEngine.Experimental.Rendering.RayTracingMode.Off;
|
||||
|
||||
headPanel = transform.parent.Find("SingleUI/Panel/GraphChart/HeadPanel").gameObject;
|
||||
headPanel = transform.parent.Find("UI/Panel/GraphChart/HeadPanel").gameObject;
|
||||
}
|
||||
TargetData targetData;
|
||||
/// <summary>
|
||||
@@ -59,7 +59,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
System.Random rd = new System.Random();
|
||||
power = 2000; //rd.Next(150, 300);//测试功率
|
||||
//#endif
|
||||
mainController.TrackResistance(currentSlope * App.rideSetting.sensitivity / 100);
|
||||
mainController.TrackResistance(currentSlope * App.RideSetting.Sensitivity / 100);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
saveButton = transform.Find("SaveButton").GetComponent<Button>();
|
||||
slider = transform.Find("Sensitivity").GetComponent<Slider>();
|
||||
text = transform.Find("Sensitivity/Text").GetComponent<Text>();
|
||||
text.text = App.rideSetting.sensitivity.ToString("#0")+ "%";
|
||||
slider.value =(float)App.rideSetting.sensitivity;
|
||||
text.text = App.RideSetting.Sensitivity.ToString("#0")+ "%";
|
||||
slider.value =(float)App.RideSetting.Sensitivity;
|
||||
slider.onValueChanged.AddListener((f) =>
|
||||
{
|
||||
text.text = $"{(f).ToString("#0")}%";
|
||||
@@ -37,7 +37,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
private void Save(BaseEventData baseEventData)
|
||||
{
|
||||
App.rideSetting.sensitivity = Math.Round(slider.value,0);
|
||||
App.RideSetting.Sensitivity = Math.Round(slider.value,0);
|
||||
transform.parent.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user