469 lines
15 KiB
C#
469 lines
15 KiB
C#
using Cysharp.Threading.Tasks;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Reflection;
|
||
using System.Runtime.InteropServices.ComTypes;
|
||
using Cysharp.Threading.Tasks;
|
||
using UnityEngine;
|
||
using System.Diagnostics;
|
||
using Sirenix.Utilities;
|
||
|
||
/// <summary>
|
||
/// 统一引用单例类
|
||
/// </summary>
|
||
public class GameManager : SingletonAutoMono<GameManager>
|
||
{
|
||
/// <summary>
|
||
/// 系统Id
|
||
/// </summary>
|
||
public int systemId;
|
||
|
||
/// <summary>
|
||
/// 选择科目之后跳入的场景名称
|
||
/// </summary>
|
||
public string startSceneName;
|
||
|
||
public string tokenUrl;
|
||
|
||
#region 底层框架内容
|
||
|
||
/// <summary>
|
||
/// Ui管理类
|
||
/// </summary>
|
||
public static UIManager UIMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 事件中心
|
||
/// </summary>
|
||
public static EventCenter EventMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 公共mono
|
||
/// </summary>
|
||
public static MonoMgr MonoMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 二进制管理类
|
||
/// </summary>
|
||
public static BinaryManager BinaryMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// json管理类
|
||
/// </summary>
|
||
public static JsonManager JsonMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 场景加载管理类
|
||
/// </summary>
|
||
public static ScenesManager ScenesMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 资源加载类
|
||
/// </summary>
|
||
public static ResourcesManager ResourcesMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 音乐音效管理类
|
||
/// </summary>
|
||
public static MusicManager MusicMgr { get; private set; }
|
||
|
||
#endregion
|
||
|
||
#region 项目管理类
|
||
|
||
/// <summary>
|
||
/// 数据管理类
|
||
/// </summary>
|
||
public static DataManager DataMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 网络接口管理类
|
||
/// </summary>
|
||
public static NetManager NetMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 实训流程管理类
|
||
/// </summary>
|
||
public static ProcessManager ProcessMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 报告管理类
|
||
/// </summary>
|
||
public static ReportManager ReportMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 实训操作管理类
|
||
/// </summary>
|
||
public static HandsOnTrainingMgr HandsOnTrainingMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 学习或者练习的管理类
|
||
/// </summary>
|
||
public static RunModelMgr RunModelMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 背包管理类
|
||
/// </summary>
|
||
public static PacksackBagMgr PacksackBagMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 工具材料管理类
|
||
/// </summary>
|
||
public static ToolAndmaterialMgr ToolAndmaterialMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 数据重连管理类
|
||
/// </summary>
|
||
public static ReconnectMgr ReconnectMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 工单管理类
|
||
/// </summary>
|
||
public static WorkorderMgr WorkorderMgr { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 故障管理类
|
||
/// </summary>
|
||
public static FaultManager FaultManager { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 任务管理类
|
||
/// </summary>
|
||
public static MissionMgr MissionMgr { get; private set; }
|
||
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 初始化
|
||
/// </summary>
|
||
public void Init(int _systemId, string _startSceneName)
|
||
{
|
||
systemId = _systemId;
|
||
startSceneName = _startSceneName;
|
||
UIMgr = UIManager.Instance;
|
||
EventMgr = EventCenter.Instance;
|
||
MonoMgr = MonoMgr.Instance;
|
||
JsonMgr = JsonManager.Instance;
|
||
ScenesMgr = ScenesManager.Instance;
|
||
ResourcesMgr = ResourcesManager.Instance;
|
||
MusicMgr = MusicManager.Instance;
|
||
|
||
DataMgr = DataManager.Instance;
|
||
NetMgr = NetManager.Instance;
|
||
ProcessMgr = ProcessManager.Instance;
|
||
ReportMgr = ReportManager.Instance;
|
||
HandsOnTrainingMgr = HandsOnTrainingMgr.Instance;
|
||
RunModelMgr = RunModelMgr.Instance;
|
||
ToolAndmaterialMgr = ToolAndmaterialMgr.Instance;
|
||
PacksackBagMgr = PacksackBagMgr.Instance;
|
||
ReconnectMgr = ReconnectMgr.Instance; //重连管理初始化
|
||
WorkorderMgr = WorkorderMgr.Instance; //工单管理初始化
|
||
FaultManager = FaultManager.Instance;
|
||
MissionMgr = MissionMgr.Instance;
|
||
DataMgr.Init();
|
||
WorkorderMgr.Init();
|
||
NetMgr.Init(SendGet);
|
||
InitData();
|
||
}
|
||
|
||
private void SendGet(IEnumerator obj)
|
||
{
|
||
StartCoroutine(obj);
|
||
}
|
||
|
||
private void InitData()
|
||
{
|
||
UIMgr.ShowPanel<UI_LoadingPanel>(E_UI_Layer.System, (panel) =>
|
||
{
|
||
print("显示加载页面");
|
||
panel.Init();
|
||
EventMgr.EventTrigger<float>(Enum_EventType.UpdateProgress, 0.1f);
|
||
//加载本地文件数据
|
||
//初始化用户数据 模式 token等必要数据
|
||
//读取成功 获取模式 根据模式显示初始化页面
|
||
NetMgr.GetConfig((isSuccess) =>
|
||
{
|
||
if (isSuccess)
|
||
{
|
||
//读取成功 获取模式 根据模式显示初始化页面
|
||
// 3 为考试模式
|
||
if (NetMgr.operationType == "3")
|
||
{
|
||
RunModelMgr.ModeType = E_ModeType.Exam;
|
||
RunModelMgr.schemeID = NetMgr.schemeID;
|
||
EventMgr.EventTrigger(Enum_EventType.SwitchMode);
|
||
ProcessMgr.Init(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
|
||
{
|
||
UnityEngine.Debug.Log("科目不对");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
UIMgr.ShowPanel<UI_MessagePanel>(E_UI_Layer.System,
|
||
(p) => { p.Init("错误", "试卷数据没有获取到", E_MessageType.Warning, () => { }); });
|
||
UnityEngine.Debug.Log("数据不对");
|
||
}
|
||
|
||
//HQB 1106 网络加载故障数据
|
||
if (NetMgr.currentExamData.data.faultData != null)
|
||
FaultManager.Instance.InitFaults(
|
||
new List<string>(NetMgr.currentExamData.data.faultData.faultText.Split(',')));
|
||
//HQB 1123 网络加载任务背景数据
|
||
if (NetMgr.currentExamData.data.backJson != null)
|
||
{
|
||
MissionMgr.Init();
|
||
JObject jsonObj = JObject.Parse(NetMgr.currentExamData.data.backJson);
|
||
Type typeOfconfig = MissionMgr.mission.configurations.GetType();
|
||
PropertyInfo[] properties = typeOfconfig.GetProperties();
|
||
foreach (PropertyInfo property in properties)
|
||
{
|
||
if (jsonObj[property.Name] != null)
|
||
{
|
||
property.SetValue(MissionMgr.mission.configurations,
|
||
jsonObj[property.Name].ToObject(property.PropertyType), null);
|
||
}
|
||
else
|
||
{
|
||
property.SetValue(MissionMgr.mission.configurations, "XXX", null);
|
||
}
|
||
}
|
||
|
||
MissionMgr.SaveMissionData();
|
||
}
|
||
|
||
//HQB 1123 考试的起始时间
|
||
RunModelMgr.startTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
///练习模式和学习模式
|
||
}
|
||
|
||
tokenUrl = NetMgr.GetTokenURL();
|
||
OnRefreshToken();
|
||
ShowUIPanelAndLoadScene();
|
||
}
|
||
else
|
||
{
|
||
//读取失败 提示信息并退出应用
|
||
print("读取配置信息失败,退出应用");
|
||
Application.Quit();
|
||
}
|
||
});
|
||
});
|
||
|
||
InitialTaskUIShow.Instance.Init(); //HQB
|
||
}
|
||
|
||
IEnumerator AsyncLoadScene(bool isReset = false)
|
||
{
|
||
while(SecurityCheck.instance.check_finish)
|
||
yield return null;
|
||
if (SecurityCheck.instance.result)
|
||
{
|
||
EventMgr.EventTrigger<float>(Enum_EventType.UpdateProgress, 0.4f);
|
||
ShowUIPanelAndLoadScene(isReset);
|
||
}
|
||
else
|
||
{
|
||
|
||
UIMgr.ShowPanel<UI_MessagePanel>(E_UI_Layer.System,
|
||
(p) => { p.Init("错误", "安全检查失败,请重新启动应用!", E_MessageType.Warning,
|
||
() => {
|
||
UnityEngine.Debug.Log("爆了!");
|
||
Application.Quit();
|
||
}); });
|
||
|
||
}
|
||
}
|
||
|
||
// ReSharper disable Unity.PerformanceAnalysis
|
||
/// <summary>
|
||
///首次加载和返回模式选择界面
|
||
/// </summary>
|
||
/// <param name="isReset"></param>
|
||
public void ShowUIPanelAndLoadScene(bool isReset = false)
|
||
{
|
||
if (isReset)
|
||
{
|
||
ResetStateAndEvent();
|
||
}
|
||
|
||
UIMgr.ShowPanel<UI_BGPanel>(E_UI_Layer.Bot);
|
||
UIMgr.ShowPanel<UI_MainTitlePanel>(E_UI_Layer.Bot, (panel) => { panel.Init(); });
|
||
//显示UI菜单列表
|
||
if (NetMgr.operationType != "3")
|
||
{
|
||
UIMgr.ShowPanel<UI_SelectModePanel>(E_UI_Layer.Mid, panel => { panel.Init(); });
|
||
//加载场景 /显示UI
|
||
ScenesMgr.LoadSceneAsyn("02_MenuScene", () =>
|
||
{
|
||
//修改本地文件
|
||
NetMgr.SaveInfo("1");
|
||
EventMgr.EventTrigger<float>(Enum_EventType.UpdateProgress, 0.9f);
|
||
});
|
||
}
|
||
else
|
||
{
|
||
ScenesMgr.LoadSceneAsyn($"{systemId}_{RunModelMgr.schemeID}_{startSceneName}", () =>
|
||
{
|
||
UIMgr.HidePanel<UI_BGPanel>();
|
||
NetMgr.SaveInfo("1");
|
||
EventMgr.EventTrigger<float>(Enum_EventType.UpdateProgress, 0.9f);
|
||
});
|
||
}
|
||
|
||
StartCoroutine(AsyncSecurityCheck());
|
||
}
|
||
|
||
|
||
IEnumerator AsyncSecurityCheck()
|
||
{
|
||
while (!SecurityCheck.instance.check_finish)
|
||
{
|
||
//debugInfo = "check_finish";
|
||
yield return null;
|
||
}
|
||
|
||
while (Process.GetProcessesByName("AppStart").Length != 0)
|
||
{
|
||
//debugInfo = "AppStart";
|
||
yield return null;
|
||
}
|
||
EventMgr.EventTrigger<float>(Enum_EventType.UpdateProgress, 0.1f);
|
||
if (!SecurityCheck.instance.result)
|
||
{
|
||
//debugInfo = "okkkk";
|
||
UnityEngine.Debug.LogError("安全检查失败,请重新启动应用!");
|
||
Application.Quit();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 练习,重新练习会调用
|
||
/// </summary>
|
||
public void Practice()
|
||
{
|
||
ResetStateAndEvent();
|
||
RunModelMgr.ModeType = E_ModeType.Practice;
|
||
EventMgr.EventTrigger(Enum_EventType.SwitchMode);
|
||
ProcessMgr.Init(RunModelMgr.schemeID);
|
||
UIMgr.ShowPanel<UI_LoadingPanel>(E_UI_Layer.System, (panel) =>
|
||
{
|
||
panel.Init();
|
||
EventMgr.EventTrigger<float>(Enum_EventType.UpdateProgress, 0.1f);
|
||
ScenesMgr.LoadSceneAsyn($"{systemId}_{RunModelMgr.schemeID}_{startSceneName}", () =>
|
||
{
|
||
if (UIMgr.GetPanel<UI_SelectDevicePanel>())
|
||
UIMgr.HidePanel<UI_SelectDevicePanel>();
|
||
if (UIMgr.GetPanel<UI_BGPanel>())
|
||
UIMgr.HidePanel<UI_BGPanel>();
|
||
EventMgr.EventTrigger<float>(Enum_EventType.UpdateProgress, 0.9f);
|
||
});
|
||
});
|
||
}
|
||
|
||
//#if UNITY_EDITOR
|
||
// void OnGUI()
|
||
// {
|
||
// // 设置GUI样式(可选)
|
||
// GUIStyle style = new GUIStyle();
|
||
// style.fontSize = 20;
|
||
// style.normal.textColor = Color.red;
|
||
|
||
// // 在屏幕上绘制调试信息
|
||
// GUILayout.Label(" " + SecurityCheck.instance.debugStr + "\n " + SecurityCheck.instance.read + "/" + SecurityCheck.instance.total, style);
|
||
// GUILayout.Label(" " + debugInfo, style);
|
||
// }
|
||
//#endif
|
||
|
||
/// <summary>
|
||
/// 学习调用
|
||
/// </summary>
|
||
public void Study()
|
||
{
|
||
ResetStateAndEvent();
|
||
RunModelMgr.ModeType = E_ModeType.Study;
|
||
EventMgr.EventTrigger(Enum_EventType.SwitchMode);
|
||
ProcessMgr.Init(RunModelMgr.schemeID);
|
||
UIMgr.ShowPanel<UI_LoadingPanel>(E_UI_Layer.System, (panel) =>
|
||
{
|
||
panel.Init();
|
||
EventMgr.EventTrigger<float>(Enum_EventType.UpdateProgress, 0.1f);
|
||
ScenesMgr.LoadSceneAsyn($"{systemId}_{RunModelMgr.schemeID}_{startSceneName}", () =>
|
||
{
|
||
if (UIMgr.GetPanel<UI_SelectDevicePanel>())
|
||
UIMgr.HidePanel<UI_SelectDevicePanel>();
|
||
if (UIMgr.GetPanel<UI_BGPanel>())
|
||
UIMgr.HidePanel<UI_BGPanel>();
|
||
EventMgr.EventTrigger<float>(Enum_EventType.UpdateProgress, 0.9f);
|
||
});
|
||
});
|
||
}
|
||
/// <summary>
|
||
/// 清除一些动态
|
||
/// </summary>
|
||
private void ResetStateAndEvent()
|
||
{
|
||
UIMgr.imageTips.HideTips();
|
||
if (UIMgr.GetPanel<UI_TopTipPanel>())
|
||
UIMgr.HidePanel<UI_TopTipPanel>();
|
||
if (UIMgr.GetPanel<UI_TaskListPanel>())
|
||
UIMgr.HidePanel<UI_TaskListPanel>();
|
||
if (UIMgr.GetPanel<UI_MenuBar>())
|
||
UIMgr.HidePanel<UI_MenuBar>();
|
||
UIMgr.GetPanel<UI_MainTitlePanel>().ResetByModeType();
|
||
PacksackBagMgr.ClearAllData();
|
||
EventMgr.Clear();
|
||
UIMgr.GetPanel<UI_MainTitlePanel>().ShowMe();
|
||
ScoreManager.instance.ReInit();
|
||
if (SubjectControllerBase.Instance != null)
|
||
SubjectControllerBase.Instance.OnInit();
|
||
RunModelMgr.startTime = DateTime.Now;
|
||
UnityEngine.Debug.Log("重置开始时间");
|
||
RunModelMgr.isOnceOfficeAni = false;
|
||
InitialTaskUIShow.Instance.Init(); //HQB 进入场景弹出任务说明
|
||
}
|
||
|
||
public async void OnRefreshToken()
|
||
{
|
||
while (true)
|
||
{
|
||
UnityEngine.Debug.Log("NetMgr.Get(tokenUrl)11111111");
|
||
await NetMgr.Get(tokenUrl);
|
||
UnityEngine.Debug.Log("NetMgr.Get(tokenUrl)");
|
||
await UniTask.Delay(300000);
|
||
}
|
||
}
|
||
|
||
public void End()
|
||
{
|
||
//修改本地文件
|
||
NetMgr.SaveInfo("0");
|
||
//退出应用
|
||
Application.Quit();
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
//修改本地文件
|
||
NetMgr.SaveInfo("0");
|
||
}
|
||
} |