ZK_Framework/Assets/Scripts/Hotfix/Game/Game.cs

111 lines
3.6 KiB
C#

using System;
using Cysharp.Threading.Tasks;
using Game.RayCast;
using TMPro;
using UnityEngine;
using YooAsset;
namespace Game
{
public interface IGame
{
void Awake();
void Start();
void Update();
void OnDestroy();
}
public class Game : IGame
{
private static Game _game;
private GameObject _self;
private UIManager _uiManager;
private ResourceManager _resourceManager;
private ProcedureManager _procedureManager;
private MouseInputManager _mouseInputManager;
private EPlayMode _loadType = EPlayMode.EditorSimulateMode;
private float time;
private GameInitType _gameInitType = GameInitType.None;
public static GameObject self => _game._self;
public static IProcedureManager procedureManager => _game._procedureManager;
public static IResourceManager resourceManager => _game._resourceManager;
public static IUIManager uiManager => _game._uiManager;
public static IMouseInputManager mouseInputManager => _game._mouseInputManager;
public Game(GameObject self, EPlayMode loadType, GameInitType gameInitType)
{
_self = self;
this._loadType = loadType;
this._gameInitType = gameInitType;
this.time = 0;
}
public void Awake()
{
_game = this;
AssemblyManager.Initialize();
//
//#if UNITY_EDITOR
//// this._loadType = EPlayMode.EditorSimulateMode;
//#elif UNITY_ANDROID|| PLATFORM_ANDROID|| ENABLE_WEBCAM|| UNITY_WEBGL|| UNITY_EDITOR_WIN
// this._loadType = EPlayMode.HostPlayMode;
//#endif
this._uiManager = new UIManager();
this._resourceManager = new ResourceManager();
this._procedureManager = new ProcedureManager();
this._mouseInputManager = new MouseInputManager();
this._resourceManager.Init();
this._uiManager.Init();
this._procedureManager.Init();
this._mouseInputManager.Init();
}
public void Start()
{
_resourceManager.InitLoadModeSync(this._loadType);
// Game.uiManager.CreateUI(UIType.GlobalLogOnlyAppUI, UILayer.High);
// Game.uiManager.ShowUI(UIType.GlobalLogOnlyAppUI);
Debug.Log("asset init finish!");
this.OnCreateUI();
if (this._gameInitType == GameInitType.None)
this._procedureManager.StartProcedure(ProcedureType.LoadingGameSceneProcedure);
else
EventManager.Instance.FireNow(GameInitFinishEventArgs.EventId, new GameInitFinishEventArgs(_gameInitType));
}
private void OnCreateUI()
{
Debug.Log("start create ui !");
Game.uiManager.CreateUI(UIType.GameUI, AssetsConst.Assets_Res_Prefab_UI_GameUI_prefab, UILayer.Mid);
Game.uiManager.CreateUI(UIType.LoadingUI, AssetsConst.Assets_Res_Prefab_UI_LoadingUI_prefab, UILayer.Mid);
Debug.Log("AddAppLogcreate ui finish !");
}
public void Update()
{
time += Time.deltaTime;
this._resourceManager.Update(time);
this._uiManager.Update(time);
this._procedureManager.Update(time);
this._mouseInputManager.Update(this.time);
}
public void OnDestroy()
{
this._resourceManager.Dispose();
this._uiManager.Dispose();
this._procedureManager.Dispose();
this._mouseInputManager.Dispose();
}
}
}