Frame/Assets/Scripts/Game.cs

129 lines
4.6 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;
using Game.Dinosaurs;
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 GlobalPlayerData
{
public string name;
public long id;
public float jinBei;
// ....
public GlobalPlayerData(string name, long id, float jinBei)
{
this.name = name;
this.id = id;
this.jinBei = jinBei;
}
}
2024-04-02 18:17:57 +08:00
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;
private SocketManager _socketManager;
private HttpManager _httpManager;
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 ISocketManager socketManager => _game._socketManager;
public static IHttpManager httpManager => _game._httpManager;
public static GlobalPlayerData currentPlayerData;
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._socketManager = new SocketManager();
this._httpManager = new HttpManager();
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._socketManager.Init();
this._httpManager.Init();
2024-04-02 18:17:57 +08:00
}
private void Start()
{
Application.targetFrameRate = 60;
QualitySettings.vSyncCount = 2;
Screen.SetResolution(1080, 1920, true);
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
this.OnCreateUI();
//#if !UNITY_EDITOR
// Game.uiManager.ShowUI(UIType.GlobalLogOnlyAppUI);
//#endif
this._procedureManager.StartProcedure(ProcedureType.LoadingHallSceneProcedure);
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()
{
Game.uiManager.CreateUI(UIType.GlobalLogOnlyAppUI, AssetConstPath.Assets_GameRes_Prefabs_UI_GlobalLogOnlyAppUI, UILayer.High);
CommonHelper.AddAppLog("start create ui !");
Game.uiManager.CreateUI(UIType.InputNameUI, AssetConstPath.Assets_GameRes_Prefabs_UI_InputNameUI, UILayer.Mid);
Game.uiManager.CreateUI(UIType.GameSceneHelpUI, AssetConstPath.Assets_GameRes_Prefabs_UI_GameSceneHelpUI, UILayer.High);
Game.uiManager.CreateUI(UIType.GameSceneMainUI, AssetConstPath.Assets_GameRes_Prefabs_UI_GameSceneMainUI, UILayer.Low);
Game.uiManager.CreateUI(UIType.GameSceneResultUI, AssetConstPath.Assets_GameRes_Prefabs_UI_GameSceneResultUI, UILayer.High);
2024-04-17 16:07:55 +08:00
Game.uiManager.CreateUI(UIType.GameStorePurchaseUI, AssetConstPath.Assets_GameRes_Prefabs_UI_GameStorePurchaseUI, UILayer.Mid);
Game.uiManager.CreateUI(UIType.HallSceneMainUI, AssetConstPath.Assets_GameRes_Prefabs_UI_HallSceneMainUI, UILayer.Mid);
Game.uiManager.CreateUI(UIType.HallSceneMallUI, AssetConstPath.Assets_GameRes_Prefabs_UI_HallSceneMallUI, UILayer.Mid);
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._socketManager.Update(this.time);
this._httpManager.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._socketManager.Dispose();
this._httpManager.Dispose();
2024-04-02 18:17:57 +08:00
}
}
}