From 2524e3a004c74d25298aadd3b0f53c57d23490e6 Mon Sep 17 00:00:00 2001 From: lishuo Date: Tue, 31 May 2022 16:47:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=92=E8=88=B9=E6=9C=BA=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/Prefab/Panel/RowerHomeScript.cs | 75 ++++++++++++++++++- .../UI/Prefab/Rower/RowerMultiModeScript.cs | 9 +-- 2 files changed, 75 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs b/Assets/Scripts/UI/Prefab/Panel/RowerHomeScript.cs index 95609cc7..680ffb81 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(); spriteDict = new Dictionary() { @@ -335,6 +336,7 @@ public class RowerHomeScript : PFUIPanel //Debug.Log("140,开始扫描"); //App.MainDeviceAdapter.StartScan(); Init(); + CheckLocalData(); //transform.Find("Left/Rower").GetComponent().StartAnimation(); } void Disconnect() @@ -387,11 +389,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; @@ -436,6 +439,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 { @@ -465,7 +479,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; @@ -833,7 +847,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) { @@ -940,6 +1007,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 @@ -958,6 +1026,7 @@ public class RowerHomeScript : PFUIPanel if (openTimer && timer <= 0) { TimerTicks(); + ticks++; timer = 1f + timer; } } diff --git a/Assets/Scripts/UI/Prefab/Rower/RowerMultiModeScript.cs b/Assets/Scripts/UI/Prefab/Rower/RowerMultiModeScript.cs index d368d8c7..610222bb 100644 --- a/Assets/Scripts/UI/Prefab/Rower/RowerMultiModeScript.cs +++ b/Assets/Scripts/UI/Prefab/Rower/RowerMultiModeScript.cs @@ -271,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) @@ -1175,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;