811 lines
30 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Assets.Scenes.Ride.Scripts;
using Assets.Scripts;
using Assets.Scripts.Apis.Models;
using Assets.Scripts.Ble.Service;
using Assets.Scripts.Devices;
using Assets.Scripts.Devices.Ant;
using Assets.Scripts.Devices.Ant.Interfaces;
using Assets.Scripts.Devices.Ble;
using Assets.Scripts.Devices.Ble.Characteristic;
using Assets.Scripts.Devices.Ble.Devices;
using Assets.Scripts.Devices.Ble.Interfaces;
using ChartAndGraph;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using static RowerTaskPanel;
public class RowerHomeScript : PFUIPanel
{
private class TempRowerCalc
{
public int power { get; set; }
public ushort pace { get; set; }
public uint rate { get; set; }
public int heartRate { get; set; }
public int energy { get; set; }
public int distance { get; set; }
public int strokeCount { get; set; }
}
/// <summary>
/// 划船机数据
/// </summary>
private FtmsRowerData RowerData
{
get
{
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
if (device != null)
{
return ((IRowerDevice)device).rowerData;
}
return null;
}
}
protected override void OnDestroy()
{
Debug.Log("銷毀");
}
private IRowerDevice Rower
{
get
{
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.Rower);
if (device != null)
{
return (IRowerDevice)device;
}
return null;
}
}
/// <summary>
/// 心率数据
/// </summary>
private int? HeartRate
{
get
{
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.HeartRate);
if (device != null)
{
return ((IHeartRateDevice)device).HeartRate;
}
return null;
}
}
GameObject btnStart;
Transform left, bottom, mid;
float timer = 1.0f;
List<DoubleVector2> pullList = new List<DoubleVector2>();
public Dictionary<object, Sprite> spriteDict;
List<string> records;
List<TempRowerCalc> values;
DateTime startTime,createTime;
double Kj = 0;
int seconds = 0;
bool isPause = false;
public RowerType rowerType = null;
/// <summary>
/// 计算停止的秒数如果超过5秒除了累加值都变成--这些值记录为0提示用户如果超过90秒将直接保存数据
/// 如果5-90秒有拉力则继续滑行
/// 如果超过90秒都没有拉力则直接保存
/// </summary>
int stopSeconds = 0;
uint totalDistance = 0;
Transform slider;
protected override void Start()
{
var rect = transform.GetComponent<RectTransform>();
rect.offsetMax = Vector2.zero;
rect.offsetMin = Vector2.zero;
}
protected override void Awake()
{
rowerType = new RowerType();
spriteDict = new Dictionary<object, Sprite>()
{
{"Start",Resources.Load<Sprite>("Images/RowerNew/ICON_continue_44") },
{"Untagged",Resources.Load<Sprite>("Images/RowerNew/ICON_pause_44")},
{0,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0001") },
{1,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0002") },
{2,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0003") },
{3,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0004") },
{4,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0005") },
{5,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0006") },
{6,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0007") },
{7,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0008") },
{8,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0009") },
{9,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0010") },
{10,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0011") },
{11,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0012") },
{12,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0013") },
{13,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0014") },
{14,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0015") },
};
GetComponent<RectTransform>().localScale = Vector3.one;
GetComponent<RectTransform>().localPosition = Vector3.zero;
//mainNav.ShowExit();
left = transform.Find("Rower/Modes/Scroll/M1/Left");
bottom = transform.Find("Rower/Bottom");
mid = transform.Find("Rower/Modes/Scroll/M1/Mid");
slider = transform.Find("ResBar/PFUISlider");
UIManager.AddEvent(transform.Find("ResBar/BtnAdd").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
if (RowerData != null)
{
slider.GetComponent<PFUISlider>().SetValue((RowerData.ResistanceLevel + 1 - 50) / 300f);
}
});
UIManager.AddEvent(transform.Find("ResBar/BtnSub").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
if (RowerData != null)
{
slider.GetComponent<PFUISlider>().SetValue((RowerData.ResistanceLevel - 1 - 50) / 300f);
}
});
slider.GetComponent<PFUISlider>().valueHandler = (a) => 50 + a * 300;
slider.GetComponent<PFUISlider>().SetValueChanged(r =>
{
var v = (ushort)Math.Round((r * 300));
print("设置阻力" + v);
if (Rower != null)
{
Rower.SetResistanceLevel(v);
//RowerData.
}
});
//transform.Find("Ready/DeviceStatus").gameObject.SetActive(!flag);
//transform.Find("Ready/DeviceStatusConnect").gameObject.SetActive(flag);
UIManager.AddEvent(transform.Find("Ready/DeviceStatus").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
if (checkRowing()) return;
UIManager.ShowRowerDevicePanel();
});
UIManager.AddEvent(transform.Find("Ready/DeviceStatusConnect").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
if (checkRowing()) return;
UIManager.ShowRowerDevicePanel();
});
//手机版tab
#if UNITY_ANDROID || UNITY_IOS
var nav = transform.Find("MainNav-mobile").GetComponent<NewMainNav>();
var c1 = new NewMainNav.CustomButton(Resources.Load<Sprite>("Images/RowerNew/ICON_create_44"), () =>
{
//UIManager.ShowRowerWelldone("81A85D49-ACAA-C764-101A-02555E6AC81A");
//return;
if (checkRowing()) return;
UIManager.ShowRowerTaskPanel(type=>
{
rowerType = type;
HandleSelectType();
});
}, false);
//var c2 = new NewMainNav.CustomButton(Resources.Load<Sprite>("Images/RowerNew/ICON_continue_44"), () =>
//{
// HandleStartOrPause();
//});
btnStart = transform.Find("MainNav-mobile/Custom2").gameObject;
var c3 = new NewMainNav.CustomButton(Resources.Load<Sprite>("Images/RowerNew/ICON_mode_44"), () =>
{
ReturnHome();
}, false);
nav.SetButtonActive(new List<int> { 3, 7 }, null, c1, null, c3);
newNav = nav;
#endif
UIManager.AddEvent(transform.Find("Stopped/Confirm/BtnSave").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
transform.Find("Stopped").gameObject.SetActive(false);
HandleSaveDirect();
});
UIManager.AddEvent(transform.Find("Stopped/Confirm/BtnDrop").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
transform.Find("Stopped").gameObject.SetActive(false);
Init();
});
Init();
}
private void HandleSelectType()
{
if (Rower != null)
{
Rower.Reset();
}
//RowerPanel/Rower/Bottom/Expected/Title
var dw = rowerType.type == 1 ? $"{rowerType.value}M" : $"{(rowerType.value / 60).ToString("#0.00")}Min";
bottom.Find("Expected/Title").GetComponent<Text>().text = $"EST\n/ {dw}";
Init();
//Utils.showToast(null, "请滑动划船机并开始", isLowest: true, type: 1);
}
public override void Show()
{
base.Show();
//var mainNav = this.transform.Find("MainNav").GetComponent<MainNav>();
//mainNav.ShowRowerTab();
transform.MyDOFade();
Debug.Log("140,开始扫描");
App.MainDeviceAdapter.StartScan();
Init();
//transform.Find("Left/Rower").GetComponent<RowerAnimation>().StartAnimation();
}
void Disconnect()
{
foreach(var d in App.MainDeviceAdapter.GetDevices())
{
if ((d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && (d.Sensor == SensorType.Rower || d.Sensor == SensorType.HeartRate))
{
d.Disconnect();
}
}
App.MainDeviceAdapter.StopScan();
}
void HandleDiscardDirect()
{
openTimer = false;
isPause = true;
Debug.Log(RowerData);
btnStart.GetComponent<Image>().sprite = spriteDict["Start"];
btnStart.tag = "Start";
Init();
}
void HandleSaveDirect()
{
openTimer = false;
isPause = true;
btnStart.GetComponent<Image>().sprite = spriteDict["Start"];
btnStart.tag = "Start";
Save();
Init();
}
private IRowerCommonData RowerCommonDataInstance => Rower != null ? (C2RowerData.IsEnabled == true ? (IRowerCommonData)Rower.c2RowerData : (IRowerCommonData)Rower.rowerData) : null;
private void HandleStartOrPause()
{
//UIManager.ShowRowerResult();
//return;
if (rowerType == null)
{
Utils.showToast(null, "Please select the course!", isLowest: true);
return;
}
if (btnStart.CompareTag("Start"))
{
#if !UNITY_EDITOR
if (RowerData == null)
{
Utils.showToast(null, "Please connect the device!", isLowest: true);
return;
}
#endif
UIManager.ShowCountDownAnimation(() =>
{
#if !UNITY_EDITOR
if (RowerCommonDataInstance != null)
{
RowerCommonDataInstance.PullChanged -= PaintPullCurve;
RowerCommonDataInstance.PullChanged += PaintPullCurve;
}
#endif
StartFunc();
},
()=>
{
Debug.Log(222);
if (Rower != null && !isPause)
{
Rower.Reset();
}
});
}
else
{
openTimer = false;
isPause = true;
btnStart.GetComponent<Image>().sprite = spriteDict["Start"];
btnStart.tag = "Start";
UIManager.ShowConfirm3("Quit", "Do you want to keep the record?",
() =>
{
UIManager.CloseConfirm3();
Save();
Init();
},
()=>
{
Init();
},
()=>
{
});
}
Debug.Log(RowerData);
//StartCoroutine();
}
private void StartFunc()
{
if (!isPause)
{
startTime = UIManager.Now.GetDateTime();
}
if (!openTimer)
{
TimerTicks();
openTimer = true;
timer = 1.0f;
}
transform.Find("Ready").gameObject.SetActive(false);
btnStart.GetComponent<Image>().sprite = spriteDict["Untagged"];
btnStart.tag = "Untagged";
}
private void Save()
{
createTime = UIManager.Now.GetDateTime();
var bleDevice = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.Rower) as BleDevice;
RowerRecordModel model = new RowerRecordModel();
model.Ticks = records.Count;
if (bleDevice != null)
{
model.ManufacturerName = bleDevice.Name + " " + bleDevice.Network + " " + bleDevice.Sensor;
model.DeviceNumber = $"{ bleDevice.Address },{ bleDevice.Sensor }";
}
model.Id = Guid.NewGuid().ToString();
model.Weight = App.CurrentUser.Weight;
model.Kj = RowerData.TotalEnergy;
model.StartTime = startTime;
model.CreateTime = createTime;
Debug.Log(values.Count);
if (values.Count > 0)
{
model.MaxPower = values.Max(x => x.power);
if (values.Count(x => x.pace > 0) > 0)
{
model.MaxPace = values.Where(x => x.pace > 0).Min(x => x.pace);
model.AvgPace = values.Where(x => x.pace > 0).Average(x => x.pace);
}
model.MaxRate = values.Max(x => x.rate);
model.MaxHeartRate = values.Max(x => x.heartRate);
model.AvgPower = values.Average(x => x.power);
model.AvgRate = values.Average(x => x.rate);
model.AvgHeartRate = (int)values.Average(x => x.heartRate);
}
model.StrokeCount = RowerData.StrokeCount;
model.TotalTime = RowerData.ElapsedTime;
model.TotalDistance = RowerData.TotalDistance;
model.Type = rowerType.type == 0 ? (int?)null : rowerType.type;
model.TypeValue = rowerType.value == 0 ? (float?)null : rowerType.value;
var path = PFConstants.RowerRecordFolder + "/" + model.Id;
Helper.CreateDirectoryIfNotExsit(path);
var files = new List<string>();
try
{
var fname = path + "/" + model.Id + ".txt";
using (var fs = new FileInfo(fname).OpenWrite())
{
var stream = new StreamWriter(fs);
stream.BaseStream.Seek(0, SeekOrigin.End);
print("结果数" + records.Count);
stream.Write(string.Join("\r\n", records));
//foreach (var item in records)
//{
// stream.Write(item + "\r\n");
//}
stream.Flush();
stream.Close();
files.Add(fname);
}
}
catch (Exception ex)
{
Helper.DelectDir(path);
Debug.Log(ex.Message);
}
var res = ConfigHelper.rowerApi.Add(model, files);
UIManager.ShowRowerWelldone(model.Id);
//Disconnect();
}
private void Init()
{
if (RowerData != null)
{
RowerData.Reset();
}
if (Rower != null)
{
Rower.Reset();
}
GetComponent<RowerMultiModeScript>().GetShadowList(rowerType);
btnStart.tag = "Start";
btnStart.GetComponent<Image>().sprite = spriteDict["Start"];
left.Find("Rower").GetComponent<Image>().sprite = spriteDict[0];
left.Find("LeftImage/Value").GetComponent<Image>().fillAmount = 0;
left.Find("RightImage/Value").GetComponent<Image>().fillAmount = 0;
left.Find("Times/Value").GetComponent<Text>().text = "---";
left.Find("Calories/Value").GetComponent<Text>().text = "---";
pullList = new List<DoubleVector2>();
mid.Find("GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
openTimer = false;
bottom.Find("Time/Value").GetComponent<Text>().text = "---";
//bottom.Find("TrueTime/Value").GetComponent<Text>().text = "---";
bottom.Find("KM/Value").GetComponent<Text>().text = "---";
mid.Find("W/Value").GetComponent<Text>().text = "---";
//bottom.Find("W/AvgValue").GetComponent<Text>().text = "---";
bottom.Find("500/Value").GetComponent<Text>().text = "---";
//bottom.Find("500/AvgValue").GetComponent<Text>().text = "---";
bottom.Find("MS/Value").GetComponent<Text>().text = "---";
//bottom.Find("MS/AvgValue").GetComponent<Text>().text = "---";
bottom.Find("BPM/Value").GetComponent<Text>().text = "---";
bottom.Find("Expected/Value").GetComponent<Text>().text = "---";
mid.Find("AvgForce/Value").GetComponent<Text>().text = "---";
mid.Find("PeakForce/Value").GetComponent<Text>().text = "---";
records = new List<string>();
values = new List<TempRowerCalc>();
Kj = 0;
x = 0;
seconds = 0;
totalDistance = 0;
stopSeconds = 0;
isPause = false;
#if !UNITY_EDITOR
transform.Find("Ready").gameObject.SetActive(true);
#endif
C2RowerData.EnableChanged -= ModeChanged;
C2RowerData.EnableChanged += ModeChanged;
FtmsRowerData.RowerResChanged -= ResChanged;
FtmsRowerData.RowerResChanged += ResChanged;
}
private void ModeChanged(object sender, EventArgs e)
{
print("增加服务"+RowerData.ResistanceLevel);
RowerCommonDataInstance.PullChanged -= PaintPullCurve;
RowerCommonDataInstance.PullChanged += PaintPullCurve;
slider.GetComponent<Slider>().interactable = !(bool)sender;
transform.Find("ResBar/BtnSub").GetComponent<Button>().interactable = !(bool)sender;
transform.Find("ResBar/BtnAdd").GetComponent<Button>().interactable = !(bool)sender;
}
private void ResChanged(object sender, EventArgs e)
{
print("收到阻力" + sender);
slider.GetComponent<PFUISlider>().SetValue((Convert.ToSingle(sender) - 50) / 300f);
}
public bool checkRowing()
{
if (seconds > 0)
{
Utils.showToast(null, "Please end this training.", isLowest: true);
return true;
}
return false;
}
private void ReturnHome()
{
if (checkRowing()) return;
Disconnect();
UIManager.ShowHomePanel();
UIManager.ShowRowerSelector();
}
// Update is called once per frame
bool openTimer = false;
double x = 0f;
#if UNITY_EDITOR
List<ushort> tempList = new List<ushort>()
{
0,1230,4,500,12,13,16,0,0,0,20,30,40,50,60,500
};
int tempx = 0;
#endif
void TimerTicks()
{
#if UNITY_EDITOR
PaintPullCurve(tempList[(tempx++) % tempList.Count]);
#endif
#if !UNITY_EDITOR
if (Rower == null)
{
HandleDiscardDirect();
return;
}
if (RowerData == null) return;
#endif
var heartRate = HeartRate ?? 0;
bottom.Find("BPM/Value").GetComponent<Text>().text = heartRate.ToString();
var distance = (int)RowerData.TotalDistance;
var energy = RowerData.TotalEnergy;
var strokeCount = RowerData.StrokeCount;
TempRowerCalc tmpdata = null;
if (totalDistance == RowerData.TotalDistance)
{
//判定一次停止
stopSeconds++;
}
else
{
stopSeconds = 0;
transform.Find("Stopped").gameObject.SetActive(false);
}
//if (stopSeconds >= 91)
//{
// Debug.Log("保存");
// HandleSaveDirect();
// return;
//}
//else if (stopSeconds == 81)
//{
// Utils.showToast(null, "Record will be saved", duration: 10, stopFunc: () => stopSeconds < 6, isLowest: true,showSeconds:true);
// return;
//}
if (stopSeconds >= 2)
{
transform.Find("Stopped").gameObject.SetActive(true);
//if (stopSeconds == 6)
//{
// Utils.showToast(null, "Please keep rowing...", duration: 60, stopFunc: () => stopSeconds < 6, isLowest: true);
//}
if (rowerType.type == 2)
{
var remainTime = rowerType.value - (seconds++);
if (remainTime == 0)
{
HandleSaveDirect();
return;
}
bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(remainTime).ToString();
}
else
{
bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(seconds++).ToString();
}
mid.Find("W/Value").GetComponent<Text>().text = "---";
//bottom.Find("W/AvgValue").GetComponent<Text>().text = "---";
bottom.Find("500/Value").GetComponent<Text>().text = "---";
//bottom.Find("500/AvgValue").GetComponent<Text>().text = "---";
bottom.Find("MS/Value").GetComponent<Text>().text = "---";
//bottom.Find("MS/AvgValue").GetComponent<Text>().text = "---";
bottom.Find("Expected/Value").GetComponent<Text>().text = "---";
records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},0,0,0,{RowerData.ResistanceLevel},{heartRate},{energy}");
tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = 0, power = 0, rate = 0, heartRate = heartRate, distance = distance, energy = energy };
values.Add(tmpdata);
SendDataToRace(tmpdata);
return;
}
totalDistance = (uint)distance;
var pace = RowerData.InstantaneousPace;
if (rowerType.type == 2)
{
var remainTime = rowerType.value - (seconds++);
if (remainTime == 0)
{
HandleSaveDirect();
return;
}
bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(remainTime).ToString();
}
else
{
bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(seconds++).ToString();
}
//bottom.Find("TrueTime/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(RowerData.ElapsedTime).ToString();
if (rowerType.type == 1)
{
var remainDistance = rowerType.value - totalDistance;
if (remainDistance < 0)
{
HandleSaveDirect();
return;
}
bottom.Find("KM/Value").GetComponent<Text>().text = remainDistance.ToString();
}
else
{
bottom.Find("KM/Value").GetComponent<Text>().text = totalDistance.ToString();
}
if (pace != 0)
{
if (rowerType.type == 1)
{
//设置里程时 显示预估时间 当前时间+剩余里程/配速(转换)
var remainDistance = rowerType.value - totalDistance;
var time = values.Count + (remainDistance / (500f / pace));
bottom.Find("Expected/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(time).ToString(@"hh\:mm\:ss");
}
else if (rowerType.type == 2)
{
var remainTime = rowerType.value - values.Count;
var dis = totalDistance + (remainTime * (500f / pace));
//设置时间时 显示预估里程 当前里程+剩余时间*配速
bottom.Find("Expected/Value").GetComponent<Text>().text = $"{dis.ToString("#0")}M";
}
else
{
//自由滑 显示30min里程 当前里程+剩余时间*配速
var remainTime = 30 * 60 - values.Count;
var dis = totalDistance + (remainTime * (500f / pace));
//设置时间时 显示预估里程 当前里程+剩余时间*配速
bottom.Find("Expected/Value").GetComponent<Text>().text = $"{dis.ToString("#0")}M";
}
}
//RowerPanel/Rower/Bottom/Expected/Value
var power = RowerData.InstantaneousPower;
mid.Find("W/Value").GetComponent<Text>().text = power.ToString();
//bottom.Find("W/AvgValue").GetComponent<Text>().text = RowerData.AveragePower.ToString();
bottom.Find("500/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(pace).ToString(@"mm\:ss");
//bottom.Find("500/AvgValue").GetComponent<Text>().text = TimeSpan.FromSeconds(RowerData.AveragePace).ToString(@"mm\:ss");
var rate = RowerData.StrokeRate;
bottom.Find("MS/Value").GetComponent<Text>().text = rate.ToString();
//bottom.Find("MS/AvgValue").GetComponent<Text>().text = RowerData.AverageStrokeRate.ToString();
//if (ushort.TryParse(left.Find("Times/Value").GetComponent<Text>().text, out ushort originStroke))
//{
// if (strokeCount != originStroke)
// {
// left.Find("Rower").GetComponent<RowerAnimation>().StartAnimation();
// }
//}
left.Find("Times/Value").GetComponent<Text>().text = strokeCount.ToString();
left.Find("Calories/Value").GetComponent<Text>().text = energy.ToString();
mid.Find("AvgForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.AverageDriveForce.ToString("#0");
mid.Find("PeakForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.PeakDriveForce.ToString("#0");
records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy}");
print(records.Count);
tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy };
values.Add(tmpdata);
SendDataToRace(tmpdata);
//Debug.Log(1);
}
void SendDataToRace(TempRowerCalc tmpdata)
{
GetComponent<RowerMultiModeScript>().HandleTimeTick(new RowerChartModel
{
Pace = tmpdata.pace,
Power = tmpdata.power,
HeartRate = tmpdata.heartRate,
Rate = tmpdata.rate,
Distance = tmpdata.distance,
StrokeCount = tmpdata.strokeCount
});
}
void PaintPullCurve(object sender, EventArgs e)
{
var ftms = (IRowerCommonData)sender;
//Debug.Log(ftms.PullValue);
PaintPullCurve(ftms.PullValue);
}
bool isPlay = false;
void PaintPullCurve(ushort y)
{
Debug.Log("收到拉力" + y + ","+ DateTime.Now.Ticks);
#if !UNITY_EDITOR
if (!openTimer)
{
if (y > 0)
{
//RowerCommonDataInstance.PullChanged -= PaintPullCurve;
//RowerCommonDataInstance.PullChanged += PaintPullCurve;
StartFunc();
}
else
{
return;
}
}
#endif
//if (y > 1200) y = 1200;
//拉力条
var rate = ((float)y) * 2 / 1200;
if (rate > 1) rate = 1f;
left.Find("LeftImage/Value").GetComponent<Image>().fillAmount = rate;
left.Find("RightImage/Value").GetComponent<Image>().fillAmount = rate;
//动画
//left.Find("Rower").GetComponent<Image>().sprite = spriteDict[y / 67];
//曲线
if (y == 0)
{
if (pullList.Count == 0)
{
isPlay = true;
x = 0;
pullList.Add(new DoubleVector2(x, y));
mid.Find("GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
}
else if (pullList.Count > 1)
{
x += 0.1;
pullList.Add(new DoubleVector2(x, y));
mid.Find("GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
pullList.Clear();
x = 0;
isPlay = true;
pullList.Add(new DoubleVector2(x, y));
}
else
{
//只有0并且两秒没拉曲线消失
if (stopSeconds == 1)
{
mid.Find("GraphChart").GetComponent<RowerGraphChartFeed>().SetData(new List<DoubleVector2>());
}
}
}
else
{
x += 0.1;
pullList.Add(new DoubleVector2(x, y));
if (pullList.Count > 5 && isPlay)
{
Debug.Log("开始动画");
isPlay = false;
left.Find("Rower").GetComponent<RowerAnimation>().StartAnimation();
}
mid.Find("GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
}
//Debug.Log($"{x},{y}");
//transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
//pullList.Add(new DoubleVector2(x, y));
//if (pullList.Count >= 75)
//{
// pullList.RemoveAt(0);
// pullList = pullList.Select(val => new DoubleVector2(val.x - 0.1, val.y)).ToList();
//}
//else
//{
// x += 0.1f;
//}
}
float staticTimer = 1f;
void Update()
{
if (openTimer)
{
timer -= Time.deltaTime;
if (timer <= 0)
{
TimerTicks();
timer = 1f + timer;
}
}
staticTimer -= Time.deltaTime;
if (staticTimer <= 0)
{
HandleStatic();
staticTimer += 1f;
}
}
void HandleStatic()
{
if (transform.Find("Ready").gameObject.activeInHierarchy)
{
var flag = Rower != null && RowerData != null;
transform.Find("Ready/DeviceStatus").gameObject.SetActive(!flag);
transform.Find("Ready/Img").gameObject.SetActive(!flag);
transform.Find("Ready/Text").gameObject.SetActive(!flag);
transform.Find("Ready/DeviceStatusConnect").gameObject.SetActive(flag);
}
}
}