117 lines
3.4 KiB
C#
117 lines
3.4 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();
|
|
|
|
_isInitFinish = true;
|
|
this._procedureManager.ChangeProcedure(ProcedureType.LoadingGameSceneProcedure);
|
|
}
|
|
}
|
|
} |