107 lines
3.4 KiB
C#
107 lines
3.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.IO;
|
|
using LitJson;
|
|
|
|
/// <summary>
|
|
/// 断线重连管理
|
|
/// </summary>
|
|
public class ReconnectMgr : SingletonMono<ReconnectMgr>
|
|
{
|
|
[HideInInspector]
|
|
public float recordDuration = -1;
|
|
private float recordCountdown = -1;
|
|
private TB_UserExamStat UserExamStat = new TB_UserExamStat();
|
|
private string localStatPath = "";
|
|
private string localStatFileName = "realtimeStat.json";
|
|
/// <summary>
|
|
/// 初始化函数,记录时间间隔
|
|
/// </summary>
|
|
public void Init( )
|
|
{
|
|
localStatPath = Application.streamingAssetsPath + "/" + localStatFileName;
|
|
//if (File.Exists( localStatPath ))//启动后检查有没有之前的遗留
|
|
//{
|
|
// File.Delete( localStatPath );
|
|
//}
|
|
}
|
|
|
|
ReconnectMgr()//构造函数
|
|
{
|
|
Init( );
|
|
}
|
|
|
|
/// <summary>
|
|
/// 记录用户状态
|
|
/// </summary>
|
|
public void RealtimeStatWriter()
|
|
{
|
|
//记录步骤相关各项信息
|
|
UserExamStat.schemeID = ProcessManager.Instance.schemeID;
|
|
UserExamStat.processId = ProcessManager.Instance.processId;
|
|
UserExamStat.subProcessId = ProcessManager.Instance.subProcessId;
|
|
UserExamStat.subProcessStepId = ProcessManager.Instance.subProcessStepId;
|
|
|
|
string UserJson = JsonConvert.SerializeObject(UserExamStat, Formatting.Indented);
|
|
Debug.Log("用户当前状态" + UserJson);
|
|
|
|
File.WriteAllText(localStatPath, UserJson);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 读取用户状态(先使用同步,后用异步)
|
|
/// </summary>
|
|
public bool RealtimeStatReader()
|
|
{
|
|
if (File.Exists(localStatPath))
|
|
{
|
|
try
|
|
{
|
|
StreamReader sr = new StreamReader(localStatPath);
|
|
string user_last_stat = sr.ReadToEnd();
|
|
sr.Close();
|
|
UserExamStat = JsonMapper.ToObject<TB_UserExamStat>(user_last_stat);
|
|
Debug.Log("用户当前schemeID:" + UserExamStat.schemeID);
|
|
return true;
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError(e.ToString());
|
|
return false;
|
|
}
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
//void Start()
|
|
//{
|
|
|
|
//}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.S))//测试用,按S读取状态保存
|
|
{
|
|
RealtimeStatWriter();
|
|
}
|
|
else if(Input.GetKeyDown(KeyCode.R))
|
|
{
|
|
RealtimeStatReader();
|
|
|
|
ProcessManager.Instance.HandoverProcess(UserExamStat.processId, UserExamStat.subProcessId, UserExamStat.subProcessStepId);
|
|
StepStateControl.instance.InvokeInitStepState(GameManager.Instance.systemId, GameManager.ProcessMgr.d_Scheme.id, UserExamStat.subProcessId);
|
|
GameManager.EventMgr.EventTrigger<int>(Enum_EventType.SwitchSubProcess, UserExamStat.subProcessId);
|
|
//Debug.LogError(ProcessManager.Instance.subProcessStepTriggerID);
|
|
GameManager.EventMgr.EventTrigger<string>(Enum_EventType.SwitchSubProcessStepTriggerID, ProcessManager.Instance.subProcessStepTriggerID);
|
|
}
|
|
}
|
|
}
|