路线产生逻辑微调
This commit is contained in:
1 parent
62938ec6ae
commit
92e43c2cd8
21 files changed
+3375
-1829
No files matched your search
@@ -33,8 +33,8 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
|
||||
#region 选手骑行数据
|
||||
protected Vector2d nextlatlong; //下一个点的坐标
|
||||
protected bool isStart;//开始或者暂停
|
||||
protected bool isQuit;//true 中途退出 或者到达终点
|
||||
//protected bool isStart;//开始或者暂停
|
||||
public bool isQuit;//true 中途退出 或者到达终点
|
||||
protected bool isMajor;//是否是主人公
|
||||
protected MapDataModel mapData;
|
||||
protected int userId;
|
||||
@@ -59,7 +59,6 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
|
||||
public double TotalClimb { get => totalClimb; }
|
||||
public int UserId { get => userId; }
|
||||
public bool IsStart { get => isStart; }
|
||||
public double Speed { get => speed; }
|
||||
public double Power { get => power; }
|
||||
public double Cadance { get => cadance; }
|
||||
@@ -79,20 +78,17 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//开始骑行
|
||||
public void SetStart()
|
||||
{
|
||||
isStart = true;
|
||||
mainController.isStart = true;
|
||||
startTime = DateTime.Now;
|
||||
}
|
||||
//继续骑行
|
||||
public void SetContinue()
|
||||
{
|
||||
isStart = true;
|
||||
mainController.isStart = true;
|
||||
}
|
||||
//暂停骑行
|
||||
public void SetPause()
|
||||
{
|
||||
isStart = false;
|
||||
mainController.isStart = false;
|
||||
//characterAnimator.SetBool("IsRide", false);
|
||||
}
|
||||
@@ -126,7 +122,6 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
mapData = mainController.GetMapData();//获取路书信息
|
||||
nextlatlong = new Vector2d(mapData.List[0].Point[0], mapData.List[0].Point[1]);//初始化人物位置 TODO加上之前骑行距离
|
||||
cyclingExcutor = mainController.cyclingController;
|
||||
isStart = mainController.isStart;
|
||||
}
|
||||
|
||||
protected virtual void Excute()
|
||||
@@ -135,6 +130,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0)//定时器 一秒执行一次
|
||||
{
|
||||
SendTcp();
|
||||
Run();
|
||||
timer = 1.0f;
|
||||
}
|
||||
@@ -143,16 +139,23 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
protected virtual void Run()
|
||||
{
|
||||
ComputeNextSlope();//计算下一个坡度相关数据
|
||||
SendTcp();
|
||||
|
||||
if (mainController.isStart)
|
||||
{
|
||||
ticks++;
|
||||
//计算累计爬升
|
||||
var diff = mapData.List[CurrentIndex].Elevation - elevation;
|
||||
if (diff > 0)
|
||||
if (index > 0)
|
||||
{
|
||||
totalClimb += diff;
|
||||
totalClimb = 0;
|
||||
//计算累计爬升
|
||||
for (int i = 1; i <= index; i++)
|
||||
{
|
||||
var diff = mapData.List[i].Elevation - mapData.List[i - 1].Elevation;
|
||||
if (diff > 0)
|
||||
{
|
||||
totalClimb += diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
ticks++;
|
||||
Compute();//接受蓝牙设备数据计算
|
||||
//characterAnimator.SetBool("IsRide", false);//初始化动画状态
|
||||
if (totalDistance <= mapData.TotalDistance)
|
||||
@@ -178,7 +181,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//characterAnimator.SetBool("ReachEnd", true);//到达终点
|
||||
//Task.Run(() => { });//异步上传数据
|
||||
Upload();
|
||||
isStart = false;
|
||||
//mainController.isStart = false;
|
||||
isQuit = true;
|
||||
}
|
||||
}
|
||||
@@ -241,6 +244,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
double sumDistance = 0;
|
||||
var pointList = mapData.List;
|
||||
int preIndex = 0;
|
||||
for (int i = 0; i < pointList.Count; i++)
|
||||
{
|
||||
sumDistance += pointList[i].Distance;
|
||||
@@ -250,6 +254,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
break;
|
||||
}
|
||||
}
|
||||
preIndex = index > 0 ? index - 1:0;
|
||||
//计算当前海拔和坡度
|
||||
elevation = pointList[index].Elevation;
|
||||
currentSlope = pointList[index].Grade;
|
||||
|
||||
@@ -43,9 +43,9 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
//var result = GetTestData();
|
||||
MapDataModel result = mapApi.GetData(RouteId);
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
|
||||
var antConnected = CheckAnt();//初始化ant+设备
|
||||
#endif
|
||||
|
||||
//if (!antConnected)
|
||||
//{
|
||||
// throw new Exception("请先连接设备");
|
||||
@@ -98,6 +98,11 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
throw new System.Exception("fail to get route data");
|
||||
}
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
UIManager.Instance.MainPanel = this.transform.Find("SingleUI/Panel").GetComponent<PFUIPanel>();
|
||||
UIManager.Instance.ModalsPanel = this.transform.Find("SingleUI/ModalPanel").GetComponent<PFUIPanel>();
|
||||
}
|
||||
|
||||
private void InitParam()
|
||||
{
|
||||
|
||||
@@ -8,24 +8,48 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//[ExecuteInEditMode]
|
||||
public class LoadingPanelController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
GameObject _content;
|
||||
|
||||
[SerializeField]
|
||||
Text _text;
|
||||
[SerializeField]
|
||||
AnimationCurve _curve;
|
||||
|
||||
Text mapName;
|
||||
AbstractMap _map;
|
||||
void Awake()
|
||||
{
|
||||
_map = FindObjectOfType<AbstractMap>();
|
||||
_map.OnInitialized += _map_OnInitialized;
|
||||
_map.OnTileFinished += _map_OnTileFinished;
|
||||
_map.OnEditorPreviewEnabled += OnEditorPreviewEnabled;
|
||||
_map.OnEditorPreviewDisabled += OnEditorPreviewDisabled;
|
||||
_map.OnUpdated += _map_OnUpdated;
|
||||
Text level;
|
||||
Text distance;
|
||||
Text elevaction;
|
||||
Text slope;
|
||||
Text rideNum;
|
||||
Text uploadByUserName;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var root = transform.parent.parent.parent;
|
||||
_map = root.Find("Map").GetComponent<AbstractMap>();
|
||||
var cyclingController = root.GetComponent<CyclingController>();
|
||||
|
||||
mapName = transform.Find("MapName").GetComponent<Text>();
|
||||
level = transform.Find("level/Text").GetComponent<Text>();
|
||||
elevaction = transform.Find("Elevaction").GetComponent<Text>();
|
||||
slope = transform.Find("Slope").GetComponent<Text>();
|
||||
rideNum = transform.Find("RideNum").GetComponent<Text>();
|
||||
uploadByUserName = transform.Find("UploadByUserName").GetComponent<Text>();
|
||||
|
||||
|
||||
var mapdata = cyclingController.GetMapData();
|
||||
var route = cyclingController.GetRoute();
|
||||
mapName.text = route.RouteInstance.Name;
|
||||
level.text = route.RouteInstance.Hard;
|
||||
elevaction.text = route.RouteInstance.EleDifference.ToString("g0");
|
||||
slope.text = route.RouteInstance.AverageGrade.ToString() + "%";
|
||||
rideNum.text = route.RouteInstance.TheHeat.ToString();
|
||||
uploadByUserName.text = route.RouteInstance.UserId.ToString();
|
||||
|
||||
_map.OnInitialized += _map_OnInitialized;
|
||||
_map.OnTileFinished += _map_OnTileFinished;
|
||||
_map.OnEditorPreviewEnabled += OnEditorPreviewEnabled;
|
||||
_map.OnEditorPreviewDisabled += OnEditorPreviewDisabled;
|
||||
_map.OnUpdated += _map_OnUpdated;
|
||||
}
|
||||
|
||||
private void _map_OnUpdated()
|
||||
@@ -35,7 +59,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
|
||||
private void _map_OnTileFinished(global::Mapbox.Unity.MeshGeneration.Data.UnityTile obj)
|
||||
{
|
||||
transform.gameObject.SetActive(false);
|
||||
//transform.gameObject.SetActive(false);
|
||||
Debug.Log("_map_OnTileFinished");
|
||||
}
|
||||
|
||||
@@ -51,32 +75,24 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
return;
|
||||
if (s == ModuleState.Finished)
|
||||
{
|
||||
//transform.gameObject.SetActive(false);
|
||||
}
|
||||
transform.gameObject.SetActive(false);
|
||||
}
|
||||
else if (s == ModuleState.Working)
|
||||
{
|
||||
|
||||
// Uncommment me if you want the loading screen to show again
|
||||
// when loading new tiles.
|
||||
//_content.SetActive(true);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
void OnEditorPreviewEnabled()
|
||||
{
|
||||
//transform.gameObject.SetActive(false);
|
||||
Debug.Log("OnEditorPreviewEnabled");
|
||||
transform.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void OnEditorPreviewDisabled()
|
||||
{
|
||||
//transform.gameObject.SetActive(true);
|
||||
Debug.Log("OnEditorPreviewDisabled");
|
||||
transform.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
var t = _curve.Evaluate(Time.time);
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
get
|
||||
{
|
||||
return 10688;//CurrentUser.Id;
|
||||
return CurrentUser.Id;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
||||
@@ -62,7 +62,8 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
if (scrollrect.verticalNormalizedPosition >= 1)
|
||||
{
|
||||
pageIndex--;
|
||||
if(pageIndex > 0)
|
||||
pageIndex--;
|
||||
//RefreshList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
private string _speed = string.Empty;
|
||||
private string _distance = string.Empty;
|
||||
private string _ratio = string.Empty;
|
||||
|
||||
private Texture countryTexture;
|
||||
private void Awake()
|
||||
{
|
||||
Head = transform.Find("Head").GetComponent<RawImage>();
|
||||
@@ -37,6 +37,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
Speed = transform.Find("Speed").GetComponent<Text>();
|
||||
Distance = transform.Find("Distance").GetComponent<Text>();
|
||||
Ratio = transform.Find("Ratio").GetComponent<Text>();
|
||||
countryTexture = Resources.Load<Sprite>("Images/flag_China_Person").texture;
|
||||
}
|
||||
|
||||
public void setRatio(string ratio)
|
||||
@@ -51,7 +52,9 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
if (!_headUrl.Equals(url))
|
||||
{
|
||||
StartCoroutine(DownloadImage(Head, url));
|
||||
Head.texture = App.CurrentUserHeadTexture;
|
||||
//Utils.DisplayImage(StartCoroutine, Head, url);
|
||||
//StartCoroutine(DownloadImage(Head, url));
|
||||
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));
|
||||
@@ -82,7 +85,9 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
if (!_countryUrl.Equals(url))
|
||||
{
|
||||
StartCoroutine(DownloadImage(Country, url));
|
||||
Country.texture = countryTexture;
|
||||
//Utils.DisplayImage(StartCoroutine, Country, url);
|
||||
//StartCoroutine(DownloadImage(Country, url));
|
||||
var rect = ((RectTransform)Country.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));
|
||||
|
||||
@@ -31,9 +31,10 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
cadance = mainController.UpdateCadence();
|
||||
weight = App.CurrentUser.Weight;
|
||||
bicycleWeight = App.CurrentUser.BicycleWeight;
|
||||
|
||||
power = 2000;//测试功率
|
||||
|
||||
Debug.Log(power);
|
||||
//#if UNITY_EDITOR
|
||||
// power = 2000;//测试功率
|
||||
//#endif
|
||||
speed = Helper.CalculateSpeed(elevation, currentSlope, power, weight, bicycleWeight);
|
||||
distance = mainController.UpdateDistance(speed);
|
||||
totalDistance += distance;
|
||||
@@ -61,7 +62,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//上传数据
|
||||
public override void Upload()
|
||||
{
|
||||
|
||||
mainController.isStart = false;
|
||||
string imageFileName = base.CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.5f, Screen.height * 0.5f));
|
||||
cyclingExcutor.recorderData.IsCompleted = totalDistance == mapData.TotalDistance;
|
||||
cyclingExcutor.recorderData.EndDistance = totalDistance;
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
Vector3 viewPos = Camera.main.WorldToViewportPoint(position);
|
||||
Vector3 dir = (position - camreatra.localPosition).normalized;
|
||||
float dot = Vector3.Dot(camreatra.forward, dir);
|
||||
if (dot > -1 && viewPos.x >= -1 && viewPos.x <= 2 && viewPos.y >= -1 && viewPos.y <= 2)
|
||||
if (dot > -0.1 && viewPos.x >= -0.1 && viewPos.x <= 1.1 && viewPos.y >= -0.1 && viewPos.y <= 1.1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -236,9 +236,13 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
private void SaveRide()
|
||||
{
|
||||
playerController.Upload();
|
||||
//SceneManager.LoadScene("MainScene");
|
||||
quitPanel.SetActive(false);
|
||||
playerController.SetPause();
|
||||
if (playerController.TotalTicks > 0 && !playerController.isQuit )
|
||||
{
|
||||
playerController.Upload();
|
||||
quitPanel.SetActive(false);
|
||||
}
|
||||
SceneManager.LoadScene("MainScene");
|
||||
}
|
||||
private void CancelQuit()
|
||||
{
|
||||
@@ -253,12 +257,19 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//结束游戏
|
||||
private void StopRide()
|
||||
{
|
||||
quitPanel.SetActive(true);
|
||||
if (playerController.TotalTicks > 0)
|
||||
{
|
||||
quitPanel.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SceneManager.LoadScene("MainScene");
|
||||
}
|
||||
}
|
||||
//显示设备连接
|
||||
private void ShowDevicePanel()
|
||||
{
|
||||
UIManager.ShowCustom(UIManager.Instance.DevicePanel, transform.Find("Panel").gameObject);
|
||||
UIManager.Show(UIManager.Instance.DevicePanel, transform.Find("Panel").GetComponent<PFUIPanel>());
|
||||
}
|
||||
//显示设置
|
||||
private void ShowSettingPanel()
|
||||
@@ -342,6 +353,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
var v = (endIndex - chartAddNum) % maxCacheDataNumber;
|
||||
MoveChartMarkPoint(v);
|
||||
App.CurrentUserHeadTexture = img.texture;
|
||||
}
|
||||
}
|
||||
void AddOneData(int index)
|
||||
|
||||
Reference in new issue
Block a user