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
|
|
|
|
|
{
|
2024-11-08 17:25:44 +08:00
|
|
|
|
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-08 11:05:33 +08:00
|
|
|
|
|
|
|
|
|
|
2024-11-07 23:51:24 +08:00
|
|
|
|
private Transform _objectPool;
|
|
|
|
|
private bool isDisposed;
|
|
|
|
|
private bool isPause;
|
2024-11-08 17:25:44 +08:00
|
|
|
|
private bool _isInitFinish;
|
2024-11-07 23:51:24 +08:00
|
|
|
|
private float gameTime;
|
|
|
|
|
|
2024-11-08 11:05:33 +08:00
|
|
|
|
|
2024-11-07 23:51:24 +08:00
|
|
|
|
private UIManager _uiManager;
|
|
|
|
|
private ProcedureManager _procedureManager;
|
2024-11-08 17:25:44 +08:00
|
|
|
|
private ObjectManager _objectManager;
|
2024-11-07 23:51:24 +08:00
|
|
|
|
private ResourcesLocalComponent _resourcesLocalComponent;
|
|
|
|
|
|
2024-11-08 11:05:33 +08:00
|
|
|
|
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;
|
2024-11-08 17:25:44 +08:00
|
|
|
|
public static IObjectManager ObjectManager => _global._objectManager;
|
2024-11-07 23:51:24 +08:00
|
|
|
|
public static IResourcesLocalComponent ResourcesLocalComponent => _global._resourcesLocalComponent;
|
|
|
|
|
|
2024-11-08 17:25:44 +08:00
|
|
|
|
#region 可视化
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2024-11-07 20:55:29 +08:00
|
|
|
|
|
2024-11-08 11:05:33 +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);
|
2024-10-25 23:16:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
2024-11-08 17:25:44 +08:00
|
|
|
|
if (!_isInitFinish || this.isPause) return;
|
2024-11-08 11:05:33 +08:00
|
|
|
|
|
|
|
|
|
this.gameTime += Time.fixedTime;
|
2024-11-07 22:49:10 +08:00
|
|
|
|
updateTime?.Invoke(_globalData.runTimeStr);
|
2024-11-08 17:25:44 +08:00
|
|
|
|
|
|
|
|
|
_procedureManager.OnUpdate(gameTime);
|
|
|
|
|
// _uiManager.OnUpdate(gameTime);
|
|
|
|
|
// _objectManager.OnUpdate(gameTime);
|
2024-10-26 23:50:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
{
|
2024-11-08 11:05:33 +08:00
|
|
|
|
isDisposed = true;
|
2024-10-26 23:50:18 +08:00
|
|
|
|
_globalData.Dispose();
|
2024-11-08 11:05:33 +08:00
|
|
|
|
_procedureManager.OnDispose();
|
|
|
|
|
_uiManager.OnDispose();
|
2024-11-08 17:25:44 +08:00
|
|
|
|
_objectManager.OnDispose();
|
2024-11-08 11:05:33 +08:00
|
|
|
|
|
|
|
|
|
_resourcesLocalComponent.Dispose();
|
|
|
|
|
Debug.Log("关闭应用了");
|
2024-10-24 16:16:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-08 11:05:33 +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-08 11:05:33 +08:00
|
|
|
|
|
2024-11-07 23:51:24 +08:00
|
|
|
|
this._objectPool = transform.Find("ObjectPool");
|
|
|
|
|
this.isDisposed = false;
|
|
|
|
|
this.isPause = false;
|
2024-11-08 11:05:33 +08:00
|
|
|
|
_globalData = new GlobalData();
|
2024-11-07 23:51:24 +08:00
|
|
|
|
|
|
|
|
|
AssemblyManager.Initialize();
|
2024-11-08 11:05:33 +08:00
|
|
|
|
|
2024-11-08 17:25:44 +08:00
|
|
|
|
this._resourcesLocalComponent = new ResourcesLocalComponent();
|
|
|
|
|
this._objectManager = new ObjectManager();
|
2024-11-08 11:05:33 +08:00
|
|
|
|
this._uiManager = new UIManager();
|
|
|
|
|
this._procedureManager = new ProcedureManager();
|
2024-11-08 17:25:44 +08:00
|
|
|
|
|
|
|
|
|
_objectManager.OnInit();
|
2024-11-08 11:05:33 +08:00
|
|
|
|
_uiManager.OnInit();
|
|
|
|
|
_procedureManager.OnInit();
|
2024-11-29 17:35:04 +08:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
CreateUI();
|
2024-11-08 11:05:33 +08:00
|
|
|
|
|
2024-11-08 17:25:44 +08:00
|
|
|
|
_isInitFinish = true;
|
2024-11-29 17:35:04 +08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|