107 lines
3.2 KiB
C#
107 lines
3.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Cysharp.Threading.Tasks;
|
|
using SK.Framework;
|
|
using System;
|
|
public class GameManager : MonoSingleton<GameManager>
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
/// 系统Id
|
|
/// </summary>
|
|
public int systemId;
|
|
/// <summary>
|
|
/// 学习或者练习的管理类
|
|
/// </summary>
|
|
public static RunModelMgr RunModelMgr { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 网络接口管理类
|
|
/// </summary>
|
|
public static NetManager NetMgr { get; private set; }
|
|
|
|
public string tokenUrl;
|
|
|
|
public void Init()
|
|
{
|
|
NetMgr = NetManager.Instance;
|
|
RunModelMgr = RunModelMgr.Instance;
|
|
NetMgr.Init(SendGet);
|
|
|
|
InitData();
|
|
|
|
}
|
|
|
|
private void SendGet(IEnumerator obj)
|
|
{
|
|
StartCoroutine(obj);
|
|
}
|
|
public void InitData()
|
|
{
|
|
NetMgr.GetConfig((isSuccess) =>
|
|
{
|
|
if (isSuccess)
|
|
{
|
|
//读取成功 获取模式 根据模式显示初始化页面
|
|
if (NetMgr.operationType == "3")
|
|
{
|
|
RunModelMgr.ModeType = E_ModeType.Exam;
|
|
RunModelMgr.schemeID = NetMgr.schemeID;
|
|
|
|
if (NetMgr.currentExamData.data != null)
|
|
{
|
|
ScoreBase sb = ScoreManager.Instance.GetScoreBaseBySchemeID(RunModelMgr.schemeID);
|
|
if (sb != null)
|
|
{
|
|
List<float> scoreTemp = new List<float>();
|
|
List<ExamContentJsonItem> examContentJson = NetMgr.currentExamData.data.examContentJson;
|
|
for (int i = 0; i < examContentJson.Count; i++)
|
|
{
|
|
scoreTemp.Add(examContentJson[i].defaultScore);
|
|
}
|
|
|
|
sb.SetScore(scoreTemp);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("科目不对");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("数据不对");
|
|
}
|
|
SceneLoader.LoadAsync("Models _tsq");
|
|
RunModelMgr.startTime = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
///练习模式和学习模式
|
|
SceneLoader.LoadAsync("Models _tsq");
|
|
}
|
|
|
|
tokenUrl = NetMgr.GetTokenURL();
|
|
OnRefreshToken();
|
|
}
|
|
else
|
|
{
|
|
|
|
print("读取配置信息失败,退出应用");
|
|
Application.Quit();
|
|
}
|
|
});
|
|
}
|
|
|
|
public async void OnRefreshToken()
|
|
{
|
|
while (true)
|
|
{
|
|
await NetMgr.Get(tokenUrl);
|
|
Debug.Log(NetMgr.token);
|
|
await UniTask.Delay(TimeSpan.FromSeconds(60.0*20));
|
|
}
|
|
}
|
|
}
|