From 11854f7fd627859e1b0fde92e238d77c07774900 Mon Sep 17 00:00:00 2001 From: liuyu <272912176@qq.com> Date: Wed, 4 Sep 2024 14:20:35 +0800 Subject: [PATCH] =?UTF-8?q?scene=E4=B8=AD=E6=8C=82=E8=BD=BDReconnectMgr?= =?UTF-8?q?=EF=BC=9B=E8=87=AA=E5=8A=A8=E4=BF=9D=E5=AD=98=E7=A7=BB=E5=87=BA?= =?UTF-8?q?ProcessManager;=E5=B7=A5=E5=85=B7=E9=97=B4=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=81=A2=E5=A4=8D=E6=97=B6=E7=A9=BF=E6=88=B4=E8=A3=85=E5=A4=87?= =?UTF-8?q?;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scenes/01_InitScene.unity | 19 +++++ Assets/Scripts/CXX/Score/ScoreBase.cs | 8 +++ .../Scripts/Project/Manager/ProcessManager.cs | 33 +-------- .../Scripts/Project/Manager/ReconnectMgr.cs | 71 ++++++++++++++++--- 4 files changed, 90 insertions(+), 41 deletions(-) diff --git a/Assets/Scenes/01_InitScene.unity b/Assets/Scenes/01_InitScene.unity index d402283..37dd17d 100644 --- a/Assets/Scenes/01_InitScene.unity +++ b/Assets/Scenes/01_InitScene.unity @@ -298,6 +298,25 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 049bfb1489c99ca49bfbcdcdca9d9cbf, type: 3} +--- !u!1 &275758848 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 1817104531314915916, guid: 049bfb1489c99ca49bfbcdcdca9d9cbf, type: 3} + m_PrefabInstance: {fileID: 275758847} + m_PrefabAsset: {fileID: 0} +--- !u!114 &275758849 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 275758848} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2b0607653b5fed643b96912f73248d7e, type: 3} + m_Name: + m_EditorClassIdentifier: + localStatFileName: realtimeStat.json + countDown_AutoSave: 120 --- !u!1 &744736104 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/CXX/Score/ScoreBase.cs b/Assets/Scripts/CXX/Score/ScoreBase.cs index 09fcd2b..d31fe1f 100644 --- a/Assets/Scripts/CXX/Score/ScoreBase.cs +++ b/Assets/Scripts/CXX/Score/ScoreBase.cs @@ -70,4 +70,12 @@ public abstract class ScoreBase : MonoBehaviour Debug.LogError(JsonConvert.SerializeObject(steps)); return steps; } + + /// + /// 设置科目得分,用于断线重连恢复 + /// + public void setCurrentScore(float _score) + { + this.currentScore = _score; + } } diff --git a/Assets/Scripts/Project/Manager/ProcessManager.cs b/Assets/Scripts/Project/Manager/ProcessManager.cs index af29268..af87b1a 100644 --- a/Assets/Scripts/Project/Manager/ProcessManager.cs +++ b/Assets/Scripts/Project/Manager/ProcessManager.cs @@ -56,11 +56,6 @@ public class ProcessManager : BaseManager /// public int countDown = 0; - /// - /// 鏂嚎閲嶈繛鎺ヨ嚜鍔ㄤ繚瀛樺掕鏃 - /// - public int countDown_AutoSave = 0; - /// /// 瀹炶/鑰冭瘯鏃堕暱 /// @@ -76,12 +71,11 @@ public class ProcessManager : BaseManager /// 鏍规嵁鏂规id 鐢熸垚娴佺▼鏁版嵁 /// /// 鏂规id - public void Init(int id, E_ModeType mode, int countDown = 600) //TODO 鑰冭瘯鏂嚎閲嶈繛搴旇鑰冭檻鍒濆鍖栭棶棰 + public void Init(int id, E_ModeType mode, int countDown = 600) //TODO 鑰冭瘯鏂嚎閲嶈繛搴旇鑰冭檻鍒濆鍖栭棶棰(榛樿鏃堕棿600) { this.schemeID = id; this.mode = mode; - //coroutine = GameManager.MonoMgr.StartCoroutine(CountDown(countDown)); - coroutine = GameManager.MonoMgr.StartCoroutine(AutoSaveStat(countDown));//鑷姩淇濆瓨鐢ㄦ埛鐘舵佷俊鎭 + coroutine = GameManager.MonoMgr.StartCoroutine(CountDown(countDown)); d_Scheme = DataManager.Instance.GetSchemeData(id); ReportManager.Instance.creport = DataManager.Instance.GetSchemeReport(id); GameManager.ToolAndmaterialMgr.Init(d_Scheme.ToolOrMaterilOrDevice); @@ -312,29 +306,6 @@ public class ProcessManager : BaseManager } } - /// - /// 鑷姩淇濆瓨鐢ㄦ埛鐘舵, - /// - /// - private IEnumerator AutoSaveStat(int time) - { - countDown_AutoSave = time; - WaitForSeconds waitForSeconds = new WaitForSeconds(1); - while (countDown_AutoSave > 0) - { - yield return waitForSeconds; - countDown_AutoSave--; - Debug.Log("鑷姩淇濆瓨鍊掕鏃:" + countDown_AutoSave); - if (countDown_AutoSave <= 0) - { - ReconnectMgr.Instance.RealtimeStatWriter();//闇瑕佸湪GameManager閲岄潰鍒濆鍖 - Debug.Log("瀹屾垚鐘舵佽嚜鍔ㄤ繚瀛"); - countDown_AutoSave = time; - } - } - } - - /// /// 缁撴潫 /// diff --git a/Assets/Scripts/Project/Manager/ReconnectMgr.cs b/Assets/Scripts/Project/Manager/ReconnectMgr.cs index 24f4609..156327b 100644 --- a/Assets/Scripts/Project/Manager/ReconnectMgr.cs +++ b/Assets/Scripts/Project/Manager/ReconnectMgr.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json.Linq; using System.IO; using LitJson; using System; +using Unity.Burst.CompilerServices; /// /// 断线重连管理 @@ -13,18 +14,19 @@ using System; public class ReconnectMgr : SingletonMono { [HideInInspector] - public float recordDuration = -1; - private float recordCountdown = -1; - private TB_UserExamStat UserExamStat = new TB_UserExamStat(); - private string localStatPath = ""; - private string localStatFileName = "realtimeStat.json"; - + public string localStatFileName = "realtimeStat.json";//保存文件的文件名 + [HideInInspector] + public int countDown_AutoSave = 120;//自动保存的时间间隔 + private TB_UserExamStat UserExamStat = new TB_UserExamStat(); + private string localStatPath = ""; + private Coroutine coroutine;//自动保存倒计时 + /// /// 初始化函数,记录时间间隔 /// public void Init( ) { - localStatPath = Application.streamingAssetsPath + "/" + localStatFileName; + localStatPath = Application.streamingAssetsPath + "/" + localStatFileName; //if (File.Exists( localStatPath ))//启动后检查有没有之前的遗留 //{ // File.Delete( localStatPath ); @@ -182,15 +184,20 @@ public class ReconnectMgr : SingletonMono } //恢复已穿戴的装备 - List itemWear = ToolAndmaterialMgr.Instance.CreateItemInfoByName(UserExamStat.allWear); + List itemWear = ToolAndmaterialMgr.Instance.CreateItemInfoByName(UserExamStat.allWear); + TooRoomMannger tooRoomMannger = FindAnyObjectByType(); foreach (ItemInfo item in itemWear) { PacksackBagMgr.Instance.WearItemState(item, true); + if (tooRoomMannger != null)//如果在工具间,则修改穿着 + { + tooRoomMannger.Wear(item.toolName, true); + } } //恢复场景内各个触发器状态 - PermanentTriggerBase[] allPermanentTriggers = FindObjectsOfType(); - List allReconTrigs = UserExamStat.currentSceneTriggers; + PermanentTriggerBase[] allPermanentTriggers = FindObjectsOfType(); + List allReconTrigs = UserExamStat.currentSceneTriggers; foreach (PermanentTriggerBase item in allPermanentTriggers) { item.gameObject.SetActive(false); @@ -205,9 +212,53 @@ public class ReconnectMgr : SingletonMono } } } + + //恢复记录的分数 + ScoreBase scoreBase = FindFirstObjectByType(); + Dictionary reconnectScore = scoreBase.GetStepScore(); + foreach (var item in UserExamStat.allSubScore) + { + if (reconnectScore.ContainsKey(item.index)) + { + reconnectScore[item.index].currentScore = item.currentScore; + reconnectScore[item.index].isDone = item.isDone; + } + } + scoreBase.setCurrentScore(UserExamStat.currentScore); }); } + /// + /// 自动保存用户状态, + /// + /// + private IEnumerator AutoSaveStat() + { + int countDown = countDown_AutoSave; + WaitForSeconds waitForSeconds = new WaitForSeconds(1); + while (countDown > 0) + { + yield return waitForSeconds; + //Exam为考试模式,Practice为练习模式,考试模式加入后,进入要重置时间,重新启动 + if (ProcessManager.Instance.mode == E_ModeType.Practice) + { + countDown--; + //Debug.Log("自动保存倒计时:" + countDown); + if (countDown <= 0) + { + ReconnectMgr.Instance.RealtimeStatWriter();//需要在GameManager里面初始化 + Debug.Log("完成状态自动保存"); + countDown = countDown_AutoSave; + } + } + } + } + + private void Start() + { + coroutine = StartCoroutine(AutoSaveStat()); + } + // Update is called once per frame void Update() {