diff --git a/Assets/Chart And Graph/Script/Common/DoubleVector2.cs b/Assets/Chart And Graph/Script/Common/DoubleVector2.cs index f28e7b1e..47a0f871 100644 --- a/Assets/Chart And Graph/Script/Common/DoubleVector2.cs +++ b/Assets/Chart And Graph/Script/Common/DoubleVector2.cs @@ -7,7 +7,7 @@ using UnityEngine; namespace ChartAndGraph { - [Serializable ] + [Serializable] public struct DoubleVector2 { public double x, y; diff --git a/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs b/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs index db7fc99b..1147719f 100644 --- a/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs +++ b/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs @@ -89,6 +89,8 @@ public class RowerHomeScript : PFUIPanel } GameObject btnStart; Transform left, bottom, mid,rmydata; + Image leftImage; + Image rightImage; float timer = 1.0f; List pullList, historyPullList; public Dictionary spriteDict,spriteDict2; @@ -617,8 +619,10 @@ public class RowerHomeScript : PFUIPanel btnStart.tag = "Start"; btnStart.GetComponent().sprite = spriteDict["Start"]; left.Find("Rower").GetComponent().sprite = spriteDict[0]; - left.Find("LeftImage/Value").GetComponent().fillAmount = 0; - left.Find("RightImage/Value").GetComponent().fillAmount = 0; + leftImage = left.Find("LeftImage/Value").GetComponent(); + rightImage = left.Find("RightImage/Value").GetComponent(); + leftImage.fillAmount = 0; + rightImage.fillAmount = 0; TimesText.text = "---"; Caloriestext.text = "---"; rmyCaloriestext.text = "---"; @@ -1114,15 +1118,10 @@ public class RowerHomeScript : PFUIPanel PaintPullCurve(ftms.PullValue); } bool isPlay = false; - float preTime = 0f; - float curTime = 0f; + int pointCount = 0; void PaintPullCurve(ushort y) { - //if (y!=0 && curTime-preTime < 0.1f) - //{ - // return; - //} - preTime = curTime; + Debug.Log("收到拉力" + y + ","+ DateTime.Now.Ticks); //#if !UNITY_EDITOR // if (!openTimer) @@ -1139,30 +1138,43 @@ public class RowerHomeScript : PFUIPanel //#endif //if (y > 1200) y = 1200; //拉力条 + var rate = ((float)y) * 2 / 120; if (rate > 1) rate = 1f; - left.Find("LeftImage/Value").GetComponent().fillAmount = rate; - left.Find("RightImage/Value").GetComponent().fillAmount = rate; + leftImage.fillAmount = rate; + rightImage.fillAmount = rate; + //动画 //left.Find("Rower").GetComponent().sprite = spriteDict[y / 67]; //曲线 if (y == 0) { - if (pullList.Count == 0) + //if (pullList.Count == 0) + if(pointCount == 0) { isPlay = true; x = 0.1; + pointCount++; pullList.Add(new DoubleVector2(x, y)); - SetChartData(pullList, historyPullList); + //SetChartData(pullList, historyPullList); + ClearChart(); + SetChartData(x, y); } - else if (pullList.Count > 1) + //else if (pullList.Count > 1) + else if(pointCount > 1) { x += 0.1; + pointCount++; pullList.Add(new DoubleVector2(x, y)); - SetChartData(pullList, historyPullList); + SetChartData(x, y); + //SetChartData(pullList, historyPullList); historyPullList = pullList.Select(x => x).ToList(); pullList.Clear(); + pointCount = 0; + //ClearChart(); x = 0.1; + SetChartData(x, y); + pointCount = 1; isPlay = true; pullList.Add(new DoubleVector2(x, y)); } @@ -1171,21 +1183,25 @@ public class RowerHomeScript : PFUIPanel //只有0并且两秒没拉,曲线消失 if (stopSeconds == 1) { - SetChartData(new List(), new List()); + ClearChart(); + //SetChartData(new List(), new List()); } } } else { x += 0.1; + pointCount++; pullList.Add(new DoubleVector2(x, y)); - if (pullList.Count > 5 && isPlay) + //if (pullList.Count > 5 && isPlay) + if (pointCount > 5 && isPlay) { Debug.Log("开始动画"); isPlay = false; //left.Find("Rower").GetComponent().StartAnimation(); } - SetChartData(pullList, historyPullList); + //SetChartData(pullList, historyPullList); + SetChartData(x, y); } //Debug.Log($"{x},{y}"); //transform.Find("Mid/GraphChart").GetComponent().SetData(pullList); @@ -1200,8 +1216,28 @@ public class RowerHomeScript : PFUIPanel // x += 0.1f; //} } + void ClearChart() + { + rowerGraphChartFeed.ClearChart(); + graphChartFeed.ClearChart(); + } + double preX, preY; + void SetChartData(double x, double y) + { + if (M1.localPosition.x == 0) + { + rowerGraphChartFeed.SetCurrentPoint(x, y); + rowerGraphChartFeed.SetHistoryData(historyPullList); + } + else + { + graphChartFeed.SetCurrentPoint(x, y); + } + + } void SetChartData(List v1, List v2) { + //graph.DataSource.AddPointToCategoryRealtime("Player 2", item.x, item.y); if (M1.localPosition.x == 0) { rowerGraphChartFeed.SetData(v1, v2); @@ -1216,7 +1252,6 @@ public class RowerHomeScript : PFUIPanel int ticks { get; set; } = 0; void Update() { - curTime += Time.deltaTime; #if UNITY_EDITOR if (openTimer || true) #else diff --git a/Assets/Scripts/UI/Prefab/Rower/RowerGraphChartFeed.cs b/Assets/Scripts/UI/Prefab/Rower/RowerGraphChartFeed.cs index 790cabbb..d17b3a29 100644 --- a/Assets/Scripts/UI/Prefab/Rower/RowerGraphChartFeed.cs +++ b/Assets/Scripts/UI/Prefab/Rower/RowerGraphChartFeed.cs @@ -7,10 +7,12 @@ using System.Collections.Generic; public class RowerGraphChartFeed : MonoBehaviour { GraphChartBase graph { get; set; } + GraphData dataSource { get; set; } void Start () { graph = GetComponent(); + dataSource = graph.DataSource; //GraphChartBase graph = GetComponent(); //if (graph != null) //{ @@ -34,6 +36,31 @@ public class RowerGraphChartFeed : MonoBehaviour //} // StartCoroutine(ClearAll()); } + public void SetPrePoint(double x, double y) + { + dataSource?.AddPointToCategoryRealtime("Player 1", x, y); + } + public void SetCurrentPoint(double x,double y) + { + dataSource?.AddPointToCategoryRealtime("Player 2", x, y); + } + public void ClearChart(string cat = "Player 2") + { + dataSource?.ClearCategory(cat); + } + public void SetHistoryData(List list2 = null) + { + if (list2 != null) + { + dataSource?.ClearCategory("Player 1"); + for (int i = 0; i < list2.Count; i++) + { + var item = list2[i]; + graph.DataSource.AddPointToCategoryRealtime("Player 1", item.x, item.y); + } + } + } + public void SetData(List list,List list2 = null) { @@ -42,10 +69,9 @@ public class RowerGraphChartFeed : MonoBehaviour graph.Scrollable = false; //graph.HorizontalValueToStringMap[0.0] = "Zero"; // example of how to set custom axis strings //graph.DataSource.StartBatch(); - graph.DataSource.ClearCategory("Player 1"); - graph.DataSource.ClearCategory("Player 2"); - graph.ClearCache(); - + //graph.DataSource.ClearCategory("Player 1"); + //graph.DataSource.ClearCategory("Player 2"); + //graph.ClearCache(); for (int i = 0; i < list.Count; i++) { var item = list[i];