骑行结束时间误差问题解决

This commit is contained in:
lishuo committed 2021-07-30 09:53:49 +08:00
1 parent 1919370a23
commit 12838266ba
7 files changed
+80 -53

No files matched your search

@@ -90,9 +90,10 @@ namespace Assets.Scenes.Ride.Scripts
void Start()
{
Init();
//StartCoroutine("TestExcute");
}
void Update()
void Update()
{
Excute();
AfterExcute();
@@ -120,6 +121,21 @@ namespace Assets.Scenes.Ride.Scripts
chartDataSourceScript = mainController.chartDataSourceScript;
graph = mainController.graph;
}
IEnumerator TestExcute()
{
while (true)
{
yield return new WaitForSeconds(1);
//CamControl();
timer -= Time.deltaTime;
if (timer <= 0)//定时器 一秒执行一次
{
BeforeRun();
Run();
timer = 1.0f;
}
}
}
protected virtual void Excute()
{
@@ -129,7 +145,7 @@ namespace Assets.Scenes.Ride.Scripts
{
BeforeRun();
Run();
timer = 1.0f;
timer = 1.0f + timer;
}
}
public bool stopRecord = false;
@@ -616,9 +616,9 @@ public class CyclingController : DeviceServiceMonoBase
{
isStart = true;
startTime = UIManager.Now.GetDateTime();
//骑行累计毫秒
sw = new Stopwatch();
sw.Start();
////骑行累计毫秒
//sw = new Stopwatch();
//sw.Start();
}
else
{
@@ -640,16 +640,17 @@ public class CyclingController : DeviceServiceMonoBase
//退出或者完成骑行
public void SetQuit()
{
//耗时巨大的代码
if (sw != null)
{
sw.Stop();
TimeSpan ts2 = (TimeSpan)(sw.Elapsed);
UnityEngine.Debug.Log(string.Format("Stopwatch总共花费{0}ms.", ts2.TotalMilliseconds));
//TODO后算接口需要增加累计毫秒字段
}
////耗时巨大的代码
//if (sw != null)
//{
// sw.Stop();
// TimeSpan ts2 = (TimeSpan)(sw.Elapsed);
// UnityEngine.Debug.Log(string.Format("Stopwatch总共花费{0}ms.", ts2.TotalMilliseconds));
// //TODO后算接口需要增加累计毫秒字段
//}
isStart = false;
isQuit = true;
recorderData.EndTime = UIManager.Now.GetDateTime();
}
#endregion
@@ -676,6 +677,7 @@ public class CyclingController : DeviceServiceMonoBase
public void Save(double totalDistance)
{
//cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime();
isQuit = true;
isStart = false;
string recordId = Guid.NewGuid().ToString();
@@ -686,7 +688,6 @@ public class CyclingController : DeviceServiceMonoBase
string imageFileName = path +"/"+ Guid.NewGuid().ToString() + ".png";
CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.5f, Screen.height * 0.5f), imageFileName);
cyclingController.recorderData.StartTime = startTime;
cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime();
cyclingController.recorderData.IsCompleted = totalDistance == mapData.TotalDistance;
cyclingController.recorderData.EndDistance = totalDistance;
cyclingController.recorderData.AntModelId = AntModelId;