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

118 lines
4.1 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-09 13:22:52 +08:00
using Game.Boss;
2024-04-05 18:12:04 +08:00
using Game.Pathfinding;
using Game.Player;
2024-04-08 18:20:55 +08:00
using Game.RayCast;
2024-04-06 11:59:18 +08:00
using Game.Room;
2024-04-08 18:44:01 +08:00
using TMPro;
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-04 23:51:14 +08:00
private static Game _game;
2024-04-08 18:20:55 +08:00
private GameObject _self => gameObject;
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;
2024-04-08 18:20:55 +08:00
private PlayerManager _playerManager;
private BFSManager _bfsManager;
private RoomManager _roomManager;
private MouseInputManager _mouseInputManager;
2024-04-09 13:22:52 +08:00
private BossManager _bossManager;
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-08 18:20:55 +08:00
public static GameObject self => _game._self;
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-08 18:20:55 +08:00
public static IMouseInputManager mouseInputManager => _game._mouseInputManager;
2024-04-09 13:22:52 +08:00
public static IBossManager bossManager => _game._bossManager;
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-08 18:20:55 +08:00
this._mouseInputManager = new MouseInputManager();
2024-04-09 13:22:52 +08:00
this._bossManager = new BossManager();
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-08 18:20:55 +08:00
this._mouseInputManager.Init();
2024-04-09 13:22:52 +08:00
this._bossManager.Init();
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!");
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-08 18:20:55 +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-09 13:22:52 +08:00
this._bossManager.Update(this.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-09 13:22:52 +08:00
this._bossManager.Dispose();
2024-04-02 18:17:57 +08:00
}
}
}