骑行结束时间误差问题解决
This commit is contained in:
parent
1919370a23
commit
12838266ba
@ -2436,7 +2436,7 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
mType: 0
|
||||
Tooltips:
|
||||
Tooltips: Back
|
||||
--- !u!1 &6558498177234723988
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -36,7 +36,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//比赛开始前倒计时
|
||||
if (count > 0 && !competitionModel.recorderData.Saved)
|
||||
{
|
||||
ShowCountDown(count, "Get ready!");//显示倒计时面板信息
|
||||
ShowCountDown(count, "Get Ready!");//显示倒计时面板信息
|
||||
Timer.gameObject.SetActive(false);
|
||||
TimerTitle.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
List<CompetitionTopModel> CompetitionTopList = new List<CompetitionTopModel>();
|
||||
|
||||
var resultList = results.Take(6);
|
||||
var count = 6 - resultList.Count();
|
||||
//var count = 6 - resultList.Count();
|
||||
//先取比赛结果
|
||||
foreach (var item in resultList)
|
||||
{
|
||||
@ -228,22 +228,22 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
});
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
var ss = sort.Where(c => !resultList.Select(p => p.UserId).Contains(c.UserId)).Take(count);
|
||||
foreach (var item in ss)
|
||||
{
|
||||
CompetitionTopList.Add(new CompetitionTopModel
|
||||
{
|
||||
Index = item.Index,
|
||||
TripTime = "———",
|
||||
Country = item.CountryImg,
|
||||
Name = item.Name,
|
||||
UserId = item.UserId,
|
||||
Head = item.Headimage,
|
||||
});
|
||||
}
|
||||
}
|
||||
//if (count > 0)
|
||||
//{
|
||||
// var ss = sort.Where(c => !resultList.Select(p => p.UserId).Contains(c.UserId)).Take(count);
|
||||
// foreach (var item in ss)
|
||||
// {
|
||||
// CompetitionTopList.Add(new CompetitionTopModel
|
||||
// {
|
||||
// Index = item.Index,
|
||||
// TripTime = "———",
|
||||
// Country = item.CountryImg,
|
||||
// Name = item.Name,
|
||||
// UserId = item.UserId,
|
||||
// Head = item.Headimage,
|
||||
// });
|
||||
// }
|
||||
//}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -193,35 +193,40 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
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())
|
||||
try
|
||||
{
|
||||
var stream = new StreamWriter(fs);
|
||||
stream.BaseStream.Seek(0, SeekOrigin.End);
|
||||
foreach (var item in RiderDatas)
|
||||
var fname = path + "/" + newFileName + ".txt";
|
||||
using (var fs = new FileInfo(fname).OpenWrite())
|
||||
{
|
||||
stream.Write(item.Write() + "\r\n");
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
//图片
|
||||
if (!string.IsNullOrEmpty(imageName))
|
||||
catch (Exception ex)
|
||||
{
|
||||
files.Add(imageName);
|
||||
Debug.Log(ex.Message);
|
||||
}
|
||||
//持久化序列化对象
|
||||
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>
|
||||
@ -245,7 +250,6 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
if (result.result && Directory.Exists(path))
|
||||
{
|
||||
Helper.DelectDir(path);
|
||||
Saved = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -69,6 +69,12 @@ public class LocalRouteItem : MonoBehaviour, IPointerExitHandler, IPointerEnterH
|
||||
{
|
||||
var recordStr = File.ReadAllText(item);
|
||||
record = Newtonsoft.Json.JsonConvert.DeserializeObject<MapInterruptRecord>(recordStr);
|
||||
//不是自己的记录不显示
|
||||
var isself = record.UserId == App.CurrentUser.Id;
|
||||
if (!isself)
|
||||
{
|
||||
this.gameObject.SetActive(false);
|
||||
}
|
||||
Name.text = record.RouteName;
|
||||
Time.text = record.StartTime.ToString();
|
||||
RidingTime.text = $"<color={titleColor}>Riding time:</color>{record.Ticks}";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user