forked from zxl/Frame
1
0
Fork 0
Frame/Assets/Scripts/Game.cs

124 lines
4.2 KiB
C#
Raw Normal View History

2024-04-02 18:17:57 +08:00
using System;
2024-04-03 14:38:44 +08:00
using Cysharp.Threading.Tasks;
2024-04-05 18:12:04 +08:00
using Game.Pathfinding;
using Game.Player;
2024-04-06 11:59:18 +08:00
using Game.Room;
2024-04-02 18:17:57 +08:00
using UnityEngine;
2024-04-07 17:20:48 +08:00
using UnityEngine.Serialization;
2024-04-02 18:17:57 +08:00
namespace Game
{
public class Game : MonoBehaviour
{
2024-04-07 17:20:48 +08:00
enum Test1
{
_1,_2,_3
}
[SerializeField]
private Test1 aa;
2024-04-04 23:51:14 +08:00
private static Game _game;
2024-04-02 18:17:57 +08:00
private UIManager _uiManager;
private ResourceManager _resourceManager;
2024-04-03 17:46:56 +08:00
private ProcedureManager _procedureManager;
public PlayerManager _playerManager;
2024-04-05 18:12:04 +08:00
public BFSManager _bfsManager;
2024-04-06 11:59:18 +08:00
public RoomManager _roomManager;
2024-04-07 17:20:48 +08:00
[SerializeField] private LoadType _loadType1 = LoadType.Editor;
2024-04-02 18:17:57 +08:00
[SerializeField] private float time;
2024-04-04 23:51:14 +08:00
public static IProcedureManager procedureManager => _game._procedureManager;
public static IResourceManager resourceManager => _game._resourceManager;
public static IUIManager uiManager => _game._uiManager;
public static IPlayerManager playerManager => _game._playerManager;
2024-04-05 18:12:04 +08:00
public static IBFSManager bfsManager => _game._bfsManager;
2024-04-06 11:59:18 +08:00
public static IRoomManager roomManager => _game._roomManager;
2024-04-02 18:17:57 +08:00
private void Awake()
{
2024-04-04 23:51:14 +08:00
_game = this;
2024-04-02 18:17:57 +08:00
DontDestroyOnLoad(this.gameObject);
2024-04-04 23:51:14 +08:00
AssemblyManager.Initialize();
2024-04-02 18:17:57 +08:00
2024-04-06 11:59:18 +08:00
this._uiManager = new UIManager();
this._resourceManager = new ResourceManager();
2024-04-03 17:46:56 +08:00
this._procedureManager = new ProcedureManager();
this._playerManager = new PlayerManager();
2024-04-05 18:12:04 +08:00
this._bfsManager = new BFSManager();
2024-04-06 11:59:18 +08:00
this._roomManager = new RoomManager();
2024-04-02 18:17:57 +08:00
2024-04-06 11:59:18 +08:00
this._resourceManager.Init();
this._uiManager.Init();
2024-04-03 17:46:56 +08:00
this._procedureManager.Init();
this._playerManager.Init();
2024-04-05 18:12:04 +08:00
this._bfsManager.Init();
2024-04-06 11:59:18 +08:00
this._roomManager.Init();
2024-04-03 18:07:05 +08:00
2024-04-04 23:51:14 +08:00
// ProcedureBase[] procedureBases = new ProcedureBase[]
// {
// new LoadingGameSceneProcedure(),
// new EnterGameSceneProcedure(),
// new GameSceneLogicProcedure(),
2024-04-04 23:51:14 +08:00
// };
// this._procedureManager.AddProcedure(procedureBases);
2024-04-02 18:17:57 +08:00
}
private void Start()
{
2024-04-03 14:38:44 +08:00
UniTask.Create(
async () =>
{
2024-04-07 17:20:48 +08:00
await _resourceManager.InitLoadModeAsync(_loadType1);
2024-04-03 14:38:44 +08:00
2024-04-07 17:20:48 +08:00
Game.uiManager.CreateUI(UIType.GlobalLogOnlyAppUI, UILayer.High);
Game.uiManager.ShowUI(UIType.GlobalLogOnlyAppUI);
CommonHelper.AddAppLog("asset init finish!");
// var loadingGameSceneUI = UIManager.Instance.CreateUI(UIType.LoadingGameSceneUI);
// UIManager.Instance.ShowUI(UIType.LoadingGameSceneUI);
2024-04-03 14:38:44 +08:00
2024-04-03 17:46:56 +08:00
// await this._resourceManager.LoadSceneAsync(SceneType.Game.ToString());
// EventManager.Instance.FireNow(this,new LoadingGameSceneFinishEventArgs(true));
this.OnCreateUI();
2024-04-03 17:46:56 +08:00
this._procedureManager.StartProcedure(ProcedureType.LoadingGameSceneProcedure);
2024-04-03 14:38:44 +08:00
return "11";
2024-04-04 23:51:14 +08:00
}).Forget();
2024-04-02 18:17:57 +08:00
}
private void OnCreateUI()
{
CommonHelper.AddAppLog("start create ui !");
Game.uiManager.CreateUI(UIType.InputNameUI, UILayer.Mid);
Game.uiManager.CreateUI(UIType.GameSceneHelpUI, UILayer.High);
Game.uiManager.CreateUI(UIType.GameSceneMainUI, UILayer.Low);
2024-04-07 17:20:48 +08:00
CommonHelper.AddAppLog("create ui finish !");
}
2024-04-02 18:17:57 +08:00
private void Update()
{
2024-04-04 23:51:14 +08:00
time = Time.deltaTime;
2024-04-06 11:59:18 +08:00
this._resourceManager.Update(time);
this._uiManager.Update(time);
this._procedureManager.Update(time);
this._bfsManager.Update(time);
this._playerManager.Update(time);
this._roomManager.Update(time);
2024-04-02 18:17:57 +08:00
}
private void OnDestroy()
{
2024-04-06 11:59:18 +08:00
this._resourceManager.Dispose();
this._uiManager.Dispose();
this._procedureManager.Dispose();
this._bfsManager.Dispose();
this._playerManager.Dispose();
this._roomManager.Dispose();
2024-04-02 18:17:57 +08:00
}
}
}