diff --git a/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs b/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs index e9e6c840..6c43fb04 100644 --- a/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs +++ b/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs @@ -117,6 +117,7 @@ public class RowerHomeScript : PFUIPanel } protected override void Awake() { + Id = Guid.NewGuid().ToString(); rowerType = new RowerType() { type=1,value=500}; spriteDict = new Dictionary() { @@ -342,6 +343,7 @@ public class RowerHomeScript : PFUIPanel //Debug.Log("140,开始扫描"); //App.MainDeviceAdapter.StartScan(); Init(); + CheckLocalData(); //transform.Find("Left/Rower").GetComponent().StartAnimation(); } void Disconnect() @@ -394,11 +396,12 @@ public class RowerHomeScript : PFUIPanel f.Invoke(); } } - + private string Id { get; set; } int truelyTime = 0; private void StartFunc(object sender, EventArgs e) { if (openTimer) return; + Id = Guid.NewGuid().ToString(); if (transform.parent.parent.Find("ModalPanel/RowerWelldone(Clone)") && transform.parent.parent.Find("ModalPanel/RowerWelldone(Clone)").gameObject.activeInHierarchy) { return; @@ -443,6 +446,17 @@ public class RowerHomeScript : PFUIPanel if (res.result) { UIManager.ShowRowerWelldone(model.Id, Init); + try + { + if (File.Exists(files[0])) + { + File.Delete(files[0]); + } + } + catch (Exception ex) + { + Debug.LogError(ex); + } } else { @@ -472,7 +486,7 @@ public class RowerHomeScript : PFUIPanel model.ManufacturerName = bleDevice.Name + " " + bleDevice.Network + " " + bleDevice.Sensor; model.DeviceNumber = $"{ bleDevice.Address },{ bleDevice.Sensor }"; } - model.Id = Guid.NewGuid().ToString(); + model.Id = Id;//Guid.NewGuid().ToString(); model.Weight = App.CurrentUser.Weight; model.Kj = RowerData.TotalEnergy; model.StartTime = startTime; @@ -838,7 +852,60 @@ public class RowerHomeScript : PFUIPanel { HandleSaveDirect(); } - //Debug.Log(1); + if (ticks % 5 == 0) + { + SaveRealTimes();//实时保存数据 + } + } + //检查本地数据 + private void CheckLocalData() + { + try + { + var files = Directory.GetFiles(PFConstants.RowerRecordFolder); + if (files.Length > 0) + { + UIManager.ShowConfirm(App.GetLocalString("Warn"), App.GetLocalString("continue a game?"), () => + { + var str = File.ReadAllText(files[0]); + var list = str.Replace("\r\n", " ").Split(' '); + records.Clear(); + foreach (var item in list) + { + if (!string.IsNullOrEmpty(item)) + { + records.Add(item); + } + } + UIManager.CloseConfirm(); + }, 2, + () => + { + if (files.Length > 0) + { + File.Delete(files[0]); + } + UIManager.CloseConfirm(); + }); + } + } + catch (Exception e) + { + Debug.LogError(e); + } + } + //5s钟保存 + private void SaveRealTimes() + { + try + { + var path = $"{PFConstants.RowerRecordFolder}/{Id}.txt"; + File.WriteAllText(path, string.Join("\r\n", records)); + } + catch (Exception e) + { + Debug.LogError(e); + } } void SendDataToRace(TempRowerCalc tmpdata) { @@ -945,6 +1012,7 @@ public class RowerHomeScript : PFUIPanel transform.Find("Rower/Modes/Scroll/M2/MyData/GraphChart").GetComponent().SetData(v1); } float staticTimer = 1f,shortTimer = 0.25f; + int ticks { get; set; } = 0; void Update() { #if UNITY_EDITOR @@ -963,6 +1031,7 @@ public class RowerHomeScript : PFUIPanel if (openTimer && timer <= 0) { TimerTicks(); + ticks++; timer = 1f + timer; } } diff --git a/Assets/Scripts/UI/Prefab/Rower/RowerGraphChartFeed.cs b/Assets/Scripts/UI/Prefab/Rower/RowerGraphChartFeed.cs index 19995ef1..6498c1da 100644 --- a/Assets/Scripts/UI/Prefab/Rower/RowerGraphChartFeed.cs +++ b/Assets/Scripts/UI/Prefab/Rower/RowerGraphChartFeed.cs @@ -6,8 +6,11 @@ using System.Collections.Generic; public class RowerGraphChartFeed : MonoBehaviour { - void Start () + GraphChartBase graph { get; set; } + + void Start () { + graph = GetComponent(); //GraphChartBase graph = GetComponent(); //if (graph != null) //{ @@ -16,7 +19,7 @@ public class RowerGraphChartFeed : MonoBehaviour // graph.DataSource.StartBatch(); // graph.DataSource.ClearCategory("Player 1"); // graph.DataSource.ClearAndMakeBezierCurve("Player 2"); - + // for (int i = 0; i <10000; i++) // { // graph.DataSource.AddPointToCategory("Player 1",i*5,Random.value*10f + 20f); @@ -29,23 +32,22 @@ public class RowerGraphChartFeed : MonoBehaviour // graph.DataSource.MakeCurveCategorySmooth("Player 2"); // graph.DataSource.EndBatch(); //} - // StartCoroutine(ClearAll()); + // StartCoroutine(ClearAll()); } public void SetData(List list,List list2 = null) { - GraphChartBase graph = GetComponent(); if (graph != null) { graph.Scrollable = false; //graph.HorizontalValueToStringMap[0.0] = "Zero"; // example of how to set custom axis strings - graph.DataSource.StartBatch(); + //graph.DataSource.StartBatch(); graph.DataSource.ClearCategory("Player 1"); graph.DataSource.ClearCategory("Player 2"); for (int i = 0; i < list.Count; i++) { var item = list[i]; - graph.DataSource.AddPointToCategory("Player 2", item.x, item.y); + graph.DataSource.AddPointToCategoryRealtime("Player 2", item.x, item.y); //if (i == 0) // graph.DataSource.SetCurveInitialPoint("Player 1", item.x, item.y); //else @@ -56,11 +58,11 @@ public class RowerGraphChartFeed : MonoBehaviour for (int i = 0; i < list2.Count; i++) { var item = list2[i]; - graph.DataSource.AddPointToCategory("Player 1", item.x, item.y); + graph.DataSource.AddPointToCategoryRealtime("Player 1", item.x, item.y); } } //graph.DataSource.MakeCurveCategorySmooth("Player 1"); - graph.DataSource.EndBatch(); + //graph.DataSource.EndBatch(); } } IEnumerator ClearAll() diff --git a/Assets/Scripts/UI/Prefab/Rower/RowerMultiModeScript.cs b/Assets/Scripts/UI/Prefab/Rower/RowerMultiModeScript.cs index cf796131..610222bb 100644 --- a/Assets/Scripts/UI/Prefab/Rower/RowerMultiModeScript.cs +++ b/Assets/Scripts/UI/Prefab/Rower/RowerMultiModeScript.cs @@ -43,9 +43,14 @@ public class RowerMultiModeScript : MonoBehaviour } List traceList; List initialPosYList; + + Sprite bg_myself { get; set; } + Sprite bg_other { get; set; } + Sprite img_overline_myself { get; set; } + Sprite img_overline_others { get; set; } void Awake() { - scroll = transform.Find("Rower/Modes/Scroll"); + scroll = transform.Find("Rower/Modes/Scroll"); startPosition = scroll.localPosition; @@ -100,8 +105,13 @@ public class RowerMultiModeScript : MonoBehaviour // m2.Find("Track/T5").localPosition.y, //}; scrollRank = transform.Find("Rower/Modes/Scroll/M1/Rank/Scroll View").GetComponent(); - var countryJson = Resources.Load("UI/flags-mini").text; - countryList = JsonConvert.DeserializeObject>(countryJson); + //var countryJson = Resources.Load("UI/flags-mini").text; + //countryList = JsonConvert.DeserializeObject>(countryJson); + //UIManager.Instance.loginRegOptions.GetCountryIndexByCode(); + bg_myself = Resources.Load("Images/RowerNew/动画用/bg_myself"); + bg_other = Resources.Load("Images/RowerNew/动画用/bg_other"); + img_overline_myself = Resources.Load("Images/RowerNew/动画用/img_overline_myself"); + img_overline_others = Resources.Load("Images/RowerNew/动画用/img_overline_others"); } public void HandleTimeTick(RowerChartModel data) @@ -246,8 +256,8 @@ public class RowerMultiModeScript : MonoBehaviour private void DisplayTrace(Transform t,TraceData data,TraceData mineData,bool isAni = false) { //增加新设计稿逻辑 - t.Find("Left").GetComponent().sprite = data.isMine ? Resources.Load("Images/RowerNew/动画用/bg_myself") : Resources.Load("Images/RowerNew/动画用/bg_other"); - t.Find("Main/Boat/Head").GetComponent().sprite = data.isMine ? Resources.Load("Images/RowerNew/动画用/img_overline_myself") : Resources.Load("Images/RowerNew/动画用/img_overline_others"); + t.Find("Left").GetComponent().sprite = data.isMine ? bg_myself : bg_other; + t.Find("Main/Boat/Head").GetComponent().sprite = data.isMine ? img_overline_myself : img_overline_others; t.Find("Main/Boat/Head").gameObject.SetActive(data.currentDistance > 0); t.Find("Main/Rowed").GetComponent().color = data.isMine ? Utils.HexToColorHtml("#f9308699") : Utils.HexToColorHtml("#27dfe399"); t.GetComponent().color = data.isMine ? Utils.HexToColorHtml("#f930861a") : Utils.HexToColorHtml("#27dfe31a"); @@ -261,11 +271,8 @@ public class RowerMultiModeScript : MonoBehaviour { Utils.DisplayImageTempDict(t.Find("Left/Avatar").GetComponent(), data.Avatar, caches); } - var _c = countryList.SingleOrDefault(x => x.country == data.Country); - if (_c != null) - { - t.Find("Left/Avatar/Country").GetComponent().sprite = Resources.Load(_c.source); - } + t.Find("Left/Avatar/Country").GetComponent().ShowImageWithTexture(UIManager.Instance.loginRegOptions.GetCountryImage(data.Country)); + t.Find("Left/NickName").GetComponent().text = data.NickName; if (data.list.Count == 0 || !GetComponent().openTimer) @@ -1165,7 +1172,7 @@ public class RowerMultiModeScript : MonoBehaviour //} float timer = 1f; int currentSecond = -1; - private List countryList; + //private List countryList; public RowerTaskPanel.RowerType rowerType { get; set; } int _testdis = 0;