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

134 lines
4.9 KiB
C#
Raw Normal View History

2024-10-24 16:16:57 +08:00
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
using YooAsset;
using ZC;
namespace Unity.Loader
{
public class Global : MonoBehaviour
{
private static Global _global;
2024-10-24 16:16:57 +08:00
private InitializePackage _initializePackage;
[SerializeField] EPlayMode playMode;
[SerializeField] private string packageName = "DefaultPackage";
2024-10-26 23:50:18 +08:00
private GlobalData _globalData;
public GlobalData Data => _globalData;
2024-10-24 16:16:57 +08:00
2024-11-07 20:55:29 +08:00
// Action
2024-11-07 23:51:24 +08:00
public static Action<string> updateTime;
public static Action<string> updateScore;
public static Action<string> updateProgress;
2024-11-07 23:51:24 +08:00
private Transform _objectPool;
private bool isDisposed;
private bool isPause;
private bool _isInitFinish;
2024-11-07 23:51:24 +08:00
private float gameTime;
2024-11-07 23:51:24 +08:00
private UIManager _uiManager;
private ProcedureManager _procedureManager;
private ObjectManager _objectManager;
2024-11-07 23:51:24 +08:00
private ResourcesLocalComponent _resourcesLocalComponent;
public static Transform Self => _global.transform;
2024-11-07 23:51:24 +08:00
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;
2024-11-07 23:51:24 +08:00
public static IResourcesLocalComponent ResourcesLocalComponent => _global._resourcesLocalComponent;
#region 可视化
#endregion
2024-11-07 20:55:29 +08:00
#region mono
2024-10-24 16:16:57 +08:00
private void Awake()
{
2024-11-07 23:51:24 +08:00
_global = this;
2024-10-24 16:16:57 +08:00
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;
2024-11-07 22:49:10 +08:00
updateTime?.Invoke(_globalData.runTimeStr);
_procedureManager.OnUpdate(gameTime);
// _uiManager.OnUpdate(gameTime);
// _objectManager.OnUpdate(gameTime);
2024-10-26 23:50:18 +08:00
}
private void OnDestroy()
{
isDisposed = true;
2024-10-26 23:50:18 +08:00
_globalData.Dispose();
_procedureManager.OnDispose();
_uiManager.OnDispose();
_objectManager.OnDispose();
_resourcesLocalComponent.Dispose();
Debug.Log("关闭应用了");
2024-10-24 16:16:57 +08:00
}
#endregion
2024-10-24 16:16:57 +08:00
private void FinishCallback()
{
// yoo init finish
Debug.Log($"yoo init finish {DateTime.Now}");
2024-11-07 23:51:24 +08:00
this._objectPool = transform.Find("ObjectPool");
this.isDisposed = false;
this.isPause = false;
_globalData = new GlobalData();
2024-11-07 23:51:24 +08:00
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);
2024-10-24 16:16:57 +08:00
}
}
}