HAARFTE/Assets/DemoGame/GameScript/Loader/Global.cs

136 lines
5.2 KiB
C#

using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
using YooAsset;
using ZC;
namespace Unity.Loader
{
public class Global : MonoBehaviour
{
private static Global _global;
private InitializePackage _initializePackage;
[SerializeField] EPlayMode playMode;
[SerializeField] private string packageName = "DefaultPackage";
private GlobalData _globalData;
public GlobalData Data => _globalData;
// Action
public static Action<string> updateTime;
public static Action<string> updateScore;
public static Action<string> updateProgress;
private Transform _objectPool;
private bool isDisposed;
private bool isPause;
private bool _isInitFinish;
private float gameTime;
private UIManager _uiManager;
private ProcedureManager _procedureManager;
private ObjectManager _objectManager;
private ResourcesLocalComponent _resourcesLocalComponent;
public static Transform Self => _global.transform;
public static Transform ObjectPool => _global._objectPool;
public static float GameTime => _global.gameTime;
public static IUIManager UIManager => _global._uiManager;
public static IProcedureManager ProcedureManager => _global._procedureManager;
public static IObjectManager ObjectManager => _global._objectManager;
public static IResourcesLocalComponent ResourcesLocalComponent => _global._resourcesLocalComponent;
#region 可视化
#endregion
#region mono
private void Awake()
{
_global = this;
DontDestroyOnLoad(this.gameObject);
}
private void Start()
{
this._initializePackage = new InitializePackage(playMode, this.packageName, FinishCallback);
}
private void Update()
{
if (!_isInitFinish || this.isPause) return;
this.gameTime += Time.fixedTime;
updateTime?.Invoke(_globalData.runTimeStr);
_procedureManager.OnUpdate(gameTime);
// _uiManager.OnUpdate(gameTime);
// _objectManager.OnUpdate(gameTime);
}
private void OnDestroy()
{
isDisposed = true;
_globalData?.Dispose();
_procedureManager.OnDispose();
_uiManager.OnDispose();
_objectManager.OnDispose();
_resourcesLocalComponent.Dispose();
Debug.Log("关闭应用了");
}
#endregion
private void FinishCallback()
{
// yoo init finish
Debug.Log($"yoo init finish {DateTime.Now}");
this._objectPool = transform.Find("ObjectPool");
this.isDisposed = false;
this.isPause = false;
_globalData = new GlobalData();
AssemblyManager.Initialize();
this._resourcesLocalComponent = new ResourcesLocalComponent();
this._objectManager = new ObjectManager();
this._uiManager = new UIManager();
this._procedureManager = new ProcedureManager();
_objectManager.OnInit();
_uiManager.OnInit();
_procedureManager.OnInit();
//
CreateUI();
_isInitFinish = true;
this._procedureManager.ChangeProcedure(ProcedureType.Procedure);
}
private void CreateUI()
{
UIGameObjectFactory.CreateUI<AnalysisReportUI>(UIType.AnalysisReportUI,AssetConst.Assets_DemoGame_GameRes_UIPanel_UIAnalysisReport_prefab,UILayer.Mid);
UIGameObjectFactory.CreateUI<AnswerUI>(UIType.AnswerUI,AssetConst.Assets_DemoGame_GameRes_UIPanel_UIAnswer_prefab,UILayer.Mid);
UIGameObjectFactory.CreateUI<BasicInformationUI>(UIType.BasicInformationUI,AssetConst.Assets_DemoGame_GameRes_UIPanel_UIBasicInformation_prefab,UILayer.Mid);
UIGameObjectFactory.CreateUI<BigTipsUI>(UIType.BigTipsUI,AssetConst.Assets_DemoGame_GameRes_UIPanel_UIBigTips_prefab,UILayer.Mid);
UIGameObjectFactory.CreateUI<BlackUI>(UIType.BlackUI,AssetConst.Assets_DemoGame_GameRes_UIPanel_UIBlack_prefab,UILayer.Mid);
UIGameObjectFactory.CreateUI<DialogueUI>(UIType.DialogueUI,AssetConst.Assets_DemoGame_GameRes_UIPanel_UIDialogue_prefab,UILayer.Mid);
UIGameObjectFactory.CreateUI<IntroduceUI>(UIType.IntroduceUI,AssetConst.Assets_DemoGame_GameRes_UIPanel_UIIntroduce_prefab,UILayer.Mid);
UIGameObjectFactory.CreateUI<MainUI>(UIType.MainUI,AssetConst.Assets_DemoGame_GameRes_UIPanel_UIMain_prefab,UILayer.Mid);
UIGameObjectFactory.CreateUI<MinTipsUI>(UIType.MinTipsUI,AssetConst.Assets_DemoGame_GameRes_UIPanel_UIMinTips_prefab,UILayer.Mid);
UIGameObjectFactory.CreateUI<TaskListUI>(UIType.TaskListUI,AssetConst.Assets_DemoGame_GameRes_UIPanel_UITaskList_prefab,UILayer.Mid);
UIGameObjectFactory.CreateUI<ModelDisplayUI>(UIType.ModelDisplayUI,AssetConst.Assets_DemoGame_GameRes_UIPanel_UIModelDisplay_prefab,UILayer.Mid);
UIGameObjectFactory.CreateUI<UrineSamplingUI>(UIType.UrineSamplingUI,AssetConst.Assets_DemoGame_GameRes_UIPanel_UIUrineSampling_prefab,UILayer.Mid);
}
}
}