场景加载处理一些卡顿的情况
This commit is contained in:
1 parent
e7a3214cb5
commit
65fc5b5c50
35 files changed
+8668
-2075
No files matched your search
@@ -4,15 +4,22 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using XCharts;
|
||||
using UnityEngine.Networking;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using Assets.Scenes.Ride.Scripts.Interface;
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using Mapbox.Unity.Map;
|
||||
using UnityEngine;
|
||||
|
||||
public class CyclingController : MonoBehaviour
|
||||
public class CyclingController : DeviceServiceMonoBase
|
||||
{
|
||||
|
||||
public AbstractMap map;
|
||||
public GameObject player;
|
||||
public GameObject UIObject;
|
||||
public GameObject target;
|
||||
|
||||
|
||||
#region 参数
|
||||
private MapDataModel mapData;//当前路书数据
|
||||
private double[] coordiantes;//当前地图中心
|
||||
@@ -20,195 +27,100 @@ public class CyclingController : MonoBehaviour
|
||||
private bool isStart;//当前游戏是否开始
|
||||
private DateTime startTime;//开始时间
|
||||
private bool initComplete;
|
||||
public CyclingModel cyclingModel;//当前骑行模式
|
||||
private CyclingModel cyclingModel;//当前骑行模式
|
||||
public BaseCycling cyclingController { get; set; }
|
||||
public int RouteId;
|
||||
private int RouteId;
|
||||
private MapApi mapApi;
|
||||
#endregion
|
||||
|
||||
#region 设备服务
|
||||
//设备列表
|
||||
///速率设备
|
||||
ISpeedDevice SpeedDevice
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//get
|
||||
//{
|
||||
// //速度和踏频一体的传感器,里面的速度是不可以读的,只允许读 踏频,切记
|
||||
// if (_antConnector == null)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// var device = _antConnector.discoveredDevices.Where(d => d.State == DeviceState.Connected && d is ISpeedDevice).FirstOrDefault();
|
||||
// if (device != null)
|
||||
// {
|
||||
// return (ISpeedDevice)device;
|
||||
// }
|
||||
// return null;
|
||||
//}
|
||||
}
|
||||
/// <summary>
|
||||
/// 心率设备
|
||||
/// </summary>
|
||||
IHeartRateDevice HeartDevice
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//get
|
||||
//{
|
||||
// if (_antConnector == null)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// var device = _antConnector.discoveredDevices.Where(d => d.State == DeviceState.Connected && d is IHeartRateDevice).FirstOrDefault();
|
||||
// if (device != null)
|
||||
// {
|
||||
// return (IHeartRateDevice)device;
|
||||
// }
|
||||
// return null;
|
||||
//}
|
||||
}
|
||||
/// <summary>
|
||||
/// 功率设备
|
||||
/// </summary>
|
||||
IPowerDevice PowerDevice
|
||||
{
|
||||
get {
|
||||
return null;
|
||||
}
|
||||
//get
|
||||
//{
|
||||
// if (_antConnector == null)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// var powerDevices = _antConnector.discoveredDevices.Where(d => d.State == DeviceState.Connected && d is IPowerDevice).ToList();
|
||||
// var power = powerDevices.FirstOrDefault(d => d.Sensor == SensorType.Power);
|
||||
// if (power != null)
|
||||
// {
|
||||
// return (IPowerDevice)power;
|
||||
// }
|
||||
|
||||
// if (powerDevices.Any())
|
||||
// {
|
||||
// return (IPowerDevice)powerDevices.FirstOrDefault();
|
||||
// }
|
||||
|
||||
// return null;
|
||||
//}
|
||||
}
|
||||
/// <summary>
|
||||
/// 踏频设备
|
||||
/// </summary>
|
||||
private ICadenceDevice CadenceDevice
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//get
|
||||
//{
|
||||
// if (_antConnector == null)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// var cadences = _antConnector.discoveredDevices.Where(d => d.State == DeviceState.Connected && d is ICadenceDevice).ToList();
|
||||
// var cadence = cadences.FirstOrDefault(d => d.Sensor == SensorType.Cadence);
|
||||
// if (cadence != null)
|
||||
// {
|
||||
// return (ICadenceDevice)cadence;
|
||||
// }
|
||||
// var spdCad = cadences.FirstOrDefault(d => d.Sensor == SensorType.SpeedCadence);
|
||||
// if (spdCad != null)
|
||||
// {
|
||||
// return (ICadenceDevice)spdCad;
|
||||
// }
|
||||
|
||||
// if (cadences.Any())
|
||||
// {
|
||||
// return (ICadenceDevice)cadences.FirstOrDefault();
|
||||
// }
|
||||
// return null;
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
private Route mapRoute;
|
||||
#endregion
|
||||
|
||||
void Awake()
|
||||
{
|
||||
initComplete = false;
|
||||
cyclingModel = CyclingModel.Single;
|
||||
//获取当前用户信息 TODO
|
||||
|
||||
//获取路书信息
|
||||
//MapApi mapApi = new MapApi();
|
||||
mapApi = new MapApi();
|
||||
RouteId = App.RouteIdParam;
|
||||
//var result = GetTestData();
|
||||
var result = mapApi.GetData(RouteId);
|
||||
//StartCoroutine(requset());
|
||||
//获取UDP信息 TODO
|
||||
|
||||
//var param = mapApi.GetById(RouteId);
|
||||
//Route mapRoute = GetNewInstace(RouteId);//获取一个路书所有的数据
|
||||
|
||||
|
||||
//switch (cyclingModel)
|
||||
MapDataModel result;
|
||||
if (RouteId > 0)
|
||||
{
|
||||
result = mapApi.GetData(RouteId);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = GetTestData();
|
||||
}
|
||||
var antConnected = CheckAnt();//初始化ant+设备
|
||||
//if (!antConnected)
|
||||
//{
|
||||
// case CyclingModel.Single:
|
||||
// cyclingController = new SingleModel(mapRoute, null);
|
||||
// //cyclingModel.OpenCyclingWindow();
|
||||
// break;
|
||||
// //case CyclingModel.Online:
|
||||
// // CyclingModel = new OnlineModel(Route, param);
|
||||
// // //cyclingModel.OpenCyclingWindow();
|
||||
// // break;
|
||||
// //case CyclingModel.Review:
|
||||
// // if (param.RankingsId.Count == 0)
|
||||
// // {
|
||||
// // UIHelper.ShowError(View.GetLang("MapboxController.PSelectARider"));//请选择骑行人
|
||||
// // return;
|
||||
// // }
|
||||
// // CyclingModel = new ReviewModel(Route, param);
|
||||
// // //cyclingModel.OpenCyclingWindow();
|
||||
// // break;
|
||||
// //case Model.CyclingModel.Competition:
|
||||
// // CyclingModel = new CompetitionModel(Route, param);
|
||||
// // //cyclingModel.OpenCyclingWindow();
|
||||
// // break;
|
||||
// //case Model.CyclingModel.GlobalCycling:
|
||||
// // CyclingModel = new GlobalCyclingModel(Route, param);
|
||||
|
||||
// // break;
|
||||
// //default:
|
||||
// // break;
|
||||
// throw new Exception("请先连接设备");
|
||||
//}
|
||||
//获取蓝牙设备信息 TODO
|
||||
//StartCoroutine(requset());
|
||||
|
||||
if (result != null && result.List.Count > 0)
|
||||
|
||||
var param = mapApi.GetById(RouteId);
|
||||
mapRoute = GetNewInstace(RouteId);//获取一个路书所有的数据
|
||||
|
||||
switch (cyclingModel)
|
||||
{
|
||||
case CyclingModel.Single:
|
||||
cyclingController = new SingleModel(mapRoute);
|
||||
//cyclingModel.OpenCyclingWindow();
|
||||
break;
|
||||
//case CyclingModel.Online:
|
||||
// CyclingModel = new OnlineModel(Route, param);
|
||||
// //cyclingModel.OpenCyclingWindow();
|
||||
// break;
|
||||
//case CyclingModel.Review:
|
||||
// if (param.RankingsId.Count == 0)
|
||||
// {
|
||||
// UIHelper.ShowError(View.GetLang("MapboxController.PSelectARider"));//请选择骑行人
|
||||
// return;
|
||||
// }
|
||||
// CyclingModel = new ReviewModel(Route, param);
|
||||
// //cyclingModel.OpenCyclingWindow();
|
||||
// break;
|
||||
//case Model.CyclingModel.Competition:
|
||||
// CyclingModel = new CompetitionModel(Route, param);
|
||||
// //cyclingModel.OpenCyclingWindow();
|
||||
// break;
|
||||
//case Model.CyclingModel.GlobalCycling:
|
||||
// CyclingModel = new GlobalCyclingModel(Route, param);
|
||||
|
||||
// break;
|
||||
//default:
|
||||
// break;
|
||||
}
|
||||
|
||||
if (result != null && mapRoute != null)
|
||||
{
|
||||
mapData = result;
|
||||
coordiantes = result.List[0].Point;//TODO计算当前用户所处的位置
|
||||
initComplete = true;
|
||||
Init();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.Exception("fail to get route data");
|
||||
}
|
||||
}
|
||||
private void Init()
|
||||
{
|
||||
//加载人物和地图以及UI界面
|
||||
map.gameObject.SetActive(true);
|
||||
player.SetActive(true);
|
||||
UIObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
//发送UDP
|
||||
target.transform.position = player.transform.position;
|
||||
target.transform.rotation = player.transform.rotation; //player.transform.rotation.y;
|
||||
}
|
||||
|
||||
#region 方法
|
||||
#region 数据处理
|
||||
/// <summary>
|
||||
/// 当前骑行数据的记录器
|
||||
/// </summary>
|
||||
@@ -219,6 +131,10 @@ public class CyclingController : MonoBehaviour
|
||||
return cyclingController?.recorderData;
|
||||
}
|
||||
}
|
||||
public Route GetRoute()
|
||||
{
|
||||
return mapRoute;
|
||||
}
|
||||
|
||||
public MapDataModel GetMapData()
|
||||
{
|
||||
@@ -238,54 +154,6 @@ public class CyclingController : MonoBehaviour
|
||||
var jsonData = mapApi.GetData(RouteId);
|
||||
return new Route(jsonData, routeInstance.data);
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新速度(KM/H)
|
||||
///
|
||||
/// </summary>
|
||||
private double UpDateSpeed()
|
||||
{
|
||||
return SpeedDevice == null ? 0 : SpeedDevice.Speed;
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新心率
|
||||
/// </summary>
|
||||
/// <param name="heart"></param>
|
||||
private int? UpDataHeart()
|
||||
{
|
||||
if (HeartDevice != null)
|
||||
{
|
||||
return HeartDevice.HeartRate;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新功率
|
||||
/// </summary>
|
||||
private double UpdatePower()
|
||||
{
|
||||
return PowerDevice == null ? 0 : PowerDevice.Power;
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新踏频
|
||||
/// </summary>
|
||||
/// <param name="cadence"></param>
|
||||
private int UpdateCadence()
|
||||
{
|
||||
return CadenceDevice == null ? 0 : CadenceDevice.Cadence;
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新距离(KM)
|
||||
/// </summary>
|
||||
/// <param name="distance"></param>
|
||||
private double UpdateDistance(double speed)
|
||||
{
|
||||
return Math.Round(speed / 3600, 4);
|
||||
}
|
||||
|
||||
|
||||
IEnumerator requset() {
|
||||
string url = @"http://192.168.0.97:5081/Map/GetData?routeid=5492&m=20";
|
||||
UnityWebRequest request = UnityWebRequest.Get(url);
|
||||
@@ -332,4 +200,6 @@ public class CyclingController : MonoBehaviour
|
||||
return dist.ToArray();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user