拉力曲线性能优化&解决划船时间误差问题
This commit is contained in:
1 parent
6c9b3f825a
commit
573b96d86c
7 files changed
+122
-77
No files matched your search
@@ -92,7 +92,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
Transform left, bottom, mid, rmydata;
|
||||
Image leftImage;
|
||||
Image rightImage;
|
||||
float timer = 1.0f;
|
||||
float timer = 0f;
|
||||
List<DoubleVector2> pullList, historyPullList;
|
||||
public Dictionary<object, Sprite> spriteDict, spriteDict2;
|
||||
List<string> records;
|
||||
@@ -513,7 +513,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
truelyTime = historyTime;
|
||||
//TimerTicks();
|
||||
openTimer = true;
|
||||
timer = 1.0f;
|
||||
timer = 0f;
|
||||
}
|
||||
transform.Find("Ready").gameObject.SetActive(false);
|
||||
//if (UIManager.Instance.RowerWelldone)
|
||||
@@ -657,6 +657,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
|
||||
private void Init()
|
||||
{
|
||||
ResetChart();
|
||||
deviceName = "";
|
||||
deviceNetwork = "";
|
||||
deviceAddress = "";
|
||||
@@ -833,7 +834,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
var heartRate = HeartRate ?? 0;
|
||||
#if UNITY_EDITOR
|
||||
var a = tempList[(tempx++) % tempList.Count];
|
||||
Debug.Log(a);
|
||||
//Debug.Log(a);
|
||||
PaintPullCurve((ushort)(a / 10));
|
||||
if (RowerData == null) return;
|
||||
#endif
|
||||
@@ -859,8 +860,9 @@ public class RowerHomeScript : PFUIPanel
|
||||
return;
|
||||
}
|
||||
if (RowerData == null) return;
|
||||
//#endif
|
||||
//断线重连继续
|
||||
transform.Find("Text").GetComponent<Text>().text = $"{RowerData.ElapsedTime}:{RowerData.TotalDistance}";
|
||||
//#endif
|
||||
//断线重连继续()
|
||||
var distance = (int)RowerData.TotalDistance + historyDistance;
|
||||
var energy = RowerData.TotalEnergy + historyEnergy;
|
||||
var strokeCount = RowerData.StrokeCount + historyStrokeCount;
|
||||
@@ -868,10 +870,24 @@ public class RowerHomeScript : PFUIPanel
|
||||
var power = RowerData.InstantaneousPower;
|
||||
var rate = RowerData.StrokeRate;
|
||||
truelyTime++;
|
||||
Debug.Log($"ElapsedTime :{RowerData.ElapsedTime} : {truelyTime}-{RowerData.TotalDistance}");
|
||||
TempRowerCalc tmpdata = null;
|
||||
|
||||
//解决里程训练无法结束的问题
|
||||
var c2notStop = rowerType.type == 1 && (rowerType.value-totalDistance) <= 5;
|
||||
if (c2notStop)
|
||||
{
|
||||
distance = (int)rowerType.value;
|
||||
KMText.text = "0";
|
||||
records.Add($"{strokeCount},{RowerData.ElapsedTime},{rowerType.value},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy},{RowerData.AveragePower},{truelyTime}");
|
||||
tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = RowerData.InstantaneousPace, power = power, rate = rate, heartRate = heartRate, distance = (int)rowerType.value, energy = energy };
|
||||
values.Add(tmpdata);
|
||||
SendDataToRace(tmpdata);
|
||||
HandleSaveDirect();
|
||||
return;
|
||||
}
|
||||
//里程停止逻辑
|
||||
if (totalDistance == RowerData.TotalDistance + historyDistance)
|
||||
if (totalDistance == RowerData.TotalDistance && !c2notStop)
|
||||
{
|
||||
//判定一次停止
|
||||
stopSeconds++;
|
||||
@@ -884,6 +900,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
if (stopSeconds >= 2)
|
||||
{
|
||||
if (UIManager.Instance.confirm != null && UIManager.Instance.confirm.IsActive()) {
|
||||
Debug.Log("stopSeconds >= 2");
|
||||
transform.Find("Stopped").gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
@@ -1012,10 +1029,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy };
|
||||
values.Add(tmpdata);
|
||||
SendDataToRace(tmpdata);
|
||||
if (C2RowerData.IsEnabled == true && C2RowerData.isReadyStatus && values.Count()>10)
|
||||
{
|
||||
HandleSaveDirect();
|
||||
}
|
||||
|
||||
if (ticks % 5 == 0)
|
||||
{
|
||||
SaveRealTimes();//实时保存数据
|
||||
@@ -1036,6 +1050,10 @@ public class RowerHomeScript : PFUIPanel
|
||||
if (files.Length == 0)
|
||||
return;
|
||||
var historyRowerTime = PlayerPrefs.GetString("historyRowerTime");
|
||||
deviceName = PlayerPrefs.GetString("deviceName");
|
||||
deviceNetwork = PlayerPrefs.GetString("deviceNetwork");
|
||||
deviceAddress = PlayerPrefs.GetString("deviceAddress");
|
||||
deviceSensor = PlayerPrefs.GetString("deviceSensor");
|
||||
if (!string.IsNullOrEmpty(historyRowerTime))
|
||||
{
|
||||
UIManager.ShowConfirm(App.GetLocalString("Warning"), App.GetLocalString("Save the game?"), () =>
|
||||
@@ -1102,7 +1120,12 @@ public class RowerHomeScript : PFUIPanel
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
File.WriteAllText(path, string.Join("\r\n", records));
|
||||
File.WriteAllText($"{PFConstants.RowerRecordCacheFolder}/cache.txt", string.Join("\r\n", App.cacheList));
|
||||
//File.WriteAllText($"{PFConstants.RowerRecordCacheFolder}/cache.txt", string.Join("\r\n", App.cacheList));
|
||||
PlayerPrefs.SetString("deviceName", deviceName);
|
||||
PlayerPrefs.SetString("deviceNetwork", deviceNetwork);
|
||||
PlayerPrefs.SetString("deviceAddress", deviceAddress);
|
||||
PlayerPrefs.SetString("deviceSensor", deviceSensor);
|
||||
|
||||
PlayerPrefs.SetString("historyRowerType", $"{rowerType.type},{rowerType.value}");
|
||||
PlayerPrefs.SetString("historyRowerTime", UIManager.Now.GetDateTime().ToString());
|
||||
PlayerPrefs.SetString("historyRowerShadowIds", string.Join(",", GetComponent<RowerMultiModeScript>().shadowList.Select(x => x.Nid)));
|
||||
@@ -1141,7 +1164,7 @@ public class RowerHomeScript : PFUIPanel
|
||||
int pointCount = 0;
|
||||
void PaintPullCurve(ushort y)
|
||||
{
|
||||
Debug.Log($"收到拉力 x={x} , y={y}");
|
||||
//Debug.Log($"收到拉力 x={x} , y={y}");
|
||||
//#if !UNITY_EDITOR
|
||||
// if (!openTimer)
|
||||
// {
|
||||
@@ -1162,7 +1185,6 @@ public class RowerHomeScript : PFUIPanel
|
||||
if (rate > 1) rate = 1f;
|
||||
leftImage.fillAmount = rate;
|
||||
rightImage.fillAmount = rate;
|
||||
|
||||
//动画
|
||||
//left.Find("Rower").GetComponent<Image>().sprite = spriteDict[y / 67];
|
||||
//曲线
|
||||
@@ -1171,9 +1193,9 @@ public class RowerHomeScript : PFUIPanel
|
||||
//if (pullList.Count == 0)
|
||||
if(pointCount == 0)
|
||||
{
|
||||
ClearChart("Player 2");
|
||||
ClearChart();
|
||||
isPlay = true;
|
||||
x = 0.1;
|
||||
x = 0;
|
||||
pointCount++;
|
||||
pullList.Add(new DoubleVector2(x, y));
|
||||
SetChartData(x, y);
|
||||
@@ -1188,19 +1210,18 @@ public class RowerHomeScript : PFUIPanel
|
||||
historyPullList = pullList.Select(x => x).ToList();
|
||||
pullList.Clear();
|
||||
pointCount = 0;
|
||||
x = 0.1;
|
||||
//x = 0.1;
|
||||
//SetChartData(x, y);
|
||||
pointCount = 1;
|
||||
//isPlay = true;
|
||||
pullList.Add(new DoubleVector2(x, y));
|
||||
//pullList.Add(new DoubleVector2(x, y));
|
||||
}
|
||||
else
|
||||
{
|
||||
//只有0并且两秒没拉,曲线消失
|
||||
if (stopSeconds == 1)
|
||||
{
|
||||
ClearChart("Player 1");
|
||||
ClearChart("Player 2");
|
||||
ClearChart();
|
||||
//SetChartData(new List<DoubleVector2>(), new List<DoubleVector2>());
|
||||
}
|
||||
}
|
||||
@@ -1209,9 +1230,9 @@ public class RowerHomeScript : PFUIPanel
|
||||
{
|
||||
if (pullList.Count(x => x.y == 0) == pullList.Count)
|
||||
{
|
||||
ClearChart("Player 2");
|
||||
ClearChart();
|
||||
pointCount = 0;
|
||||
SetChartData(0.1, 0);
|
||||
//SetChartData(0.1, 0);
|
||||
}
|
||||
x += 0.1;
|
||||
pointCount++;
|
||||
@@ -1239,18 +1260,25 @@ public class RowerHomeScript : PFUIPanel
|
||||
// x += 0.1f;
|
||||
//}
|
||||
}
|
||||
void ClearChart(string cateName)
|
||||
void ClearChart()
|
||||
{
|
||||
rowerGraphChartFeed.ClearChart(cateName);
|
||||
graphChartFeed.ClearChart(cateName);
|
||||
if (x > 0)
|
||||
{
|
||||
rowerGraphChartFeed.ClearChart();
|
||||
graphChartFeed.ClearChart();
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
void ResetChart() {
|
||||
rowerGraphChartFeed?.ResetChart();
|
||||
graphChartFeed?.ResetChart();
|
||||
}
|
||||
double preX, preY;
|
||||
void SetChartData(double x, double y)
|
||||
{
|
||||
if (M1.localPosition.x == 0)
|
||||
{
|
||||
rowerGraphChartFeed.SetCurrentPoint(x, y);
|
||||
rowerGraphChartFeed.SetHistoryData(historyPullList);
|
||||
rowerGraphChartFeed.SetHistoryData(x, historyPullList);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1275,48 +1303,36 @@ public class RowerHomeScript : PFUIPanel
|
||||
int ticks { get; set; } = 0;
|
||||
void Update()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (openTimer || true)
|
||||
#else
|
||||
if (openTimer)
|
||||
#endif
|
||||
shortTimer -= Time.deltaTime;
|
||||
if (shortTimer <= 0)
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
shortTimer -= Time.deltaTime;
|
||||
if (shortTimer <= 0)
|
||||
{
|
||||
ShortUpdateData();
|
||||
shortTimer += 0.25f;
|
||||
}
|
||||
if (timer <= 0)
|
||||
ShortUpdateData();
|
||||
shortTimer += 0.25f;
|
||||
}
|
||||
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (openTimer || true)
|
||||
#else
|
||||
if (openTimer)
|
||||
#endif
|
||||
{
|
||||
TimerTicks();
|
||||
ticks++;
|
||||
timer = 1f + timer;
|
||||
}
|
||||
}
|
||||
|
||||
staticTimer -= Time.deltaTime;
|
||||
if (staticTimer <= 0)
|
||||
{
|
||||
var heartRate = HeartRate ?? 0;
|
||||
BPMText.text = heartRate == 0 ? "---": heartRate.ToString();
|
||||
BPMText.text = heartRate == 0 ? "---" : heartRate.ToString();
|
||||
HandleStatic();
|
||||
staticTimer += 1f;
|
||||
}
|
||||
|
||||
//shortTimer -= Time.deltaTime;
|
||||
//if (shortTimer <= 0)
|
||||
//{
|
||||
// if (openTimer)
|
||||
// {
|
||||
// ShortUpdateData();
|
||||
// }
|
||||
// shortTimer += 0.5f;
|
||||
//}
|
||||
timer += 1f ;
|
||||
}
|
||||
}
|
||||
void ShortUpdateData()
|
||||
{
|
||||
if (!openTimer) return;
|
||||
if (RowerData == null) return;
|
||||
var power = RowerData.InstantaneousPower;
|
||||
var rate = RowerData.StrokeRate;
|
||||
@@ -1325,12 +1341,12 @@ public class RowerHomeScript : PFUIPanel
|
||||
var distance = (int)RowerData.TotalDistance + historyDistance;
|
||||
var energy = RowerData.TotalEnergy + historyEnergy;
|
||||
var heartRate = HeartRate ?? 0;
|
||||
if (rowerType.type == 1 && totalDistance >=rowerType.value && !createTime.HasValue)
|
||||
if (rowerType.type == 1 && (rowerType.value - totalDistance) <= 5 && !createTime.HasValue)
|
||||
{
|
||||
openTimer = false;
|
||||
KMText.text = "0";
|
||||
records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{power},{pace},{rate},{RowerData.ResistanceLevel},{heartRate},{energy},{RowerData.AveragePower},{truelyTime}");
|
||||
var tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy };
|
||||
records.Add($"{strokeCount},{RowerData.ElapsedTime},{rowerType.value},{power},{pace},{rate},{RowerData.ResistanceLevel},{heartRate},{energy},{RowerData.AveragePower},{truelyTime}");
|
||||
var tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = (int)rowerType.value, energy = energy };
|
||||
values.Add(tmpdata);
|
||||
SendDataToRace(tmpdata);
|
||||
HandleSaveDirect();
|
||||
|
||||
Reference in new issue
Block a user