191 lines
5.5 KiB
C#
191 lines
5.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using Cysharp.Threading.Tasks;
|
|
using GameBase;
|
|
using GameLogic;
|
|
using TEngine;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 游戏App。
|
|
/// </summary>
|
|
public partial class GameApp : Singleton<GameApp>
|
|
{
|
|
private static List<Assembly> _hotfixAssembly;
|
|
|
|
/// <summary>
|
|
/// 热更域App主入口。
|
|
/// </summary>
|
|
/// <param name="objects"></param>
|
|
public static void Entrance(object[] objects)
|
|
{
|
|
_hotfixAssembly = (List<Assembly>)objects[0];
|
|
Log.Warning("======= 看到此条日志代表你成功运行了热更新代码 =======");
|
|
Log.Warning("======= Entrance GameApp =======");
|
|
Instance.Active();
|
|
Instance.Start();
|
|
Utility.Unity.AddUpdateListener(Instance.Update);
|
|
Utility.Unity.AddFixedUpdateListener(Instance.FixedUpdate);
|
|
Utility.Unity.AddLateUpdateListener(Instance.LateUpdate);
|
|
Utility.Unity.AddDestroyListener(Instance.OnDestroy);
|
|
Utility.Unity.AddOnDrawGizmosListener(Instance.OnDrawGizmos);
|
|
Utility.Unity.AddOnApplicationPauseListener(Instance.OnApplicationPause);
|
|
GameModule.Procedure.RestartProcedure(new GameLogic.OnEnterGameAppProcedure());
|
|
Instance.StartGameLogic();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开始游戏业务层逻辑。
|
|
/// <remarks>显示UI、加载场景等。</remarks>
|
|
/// </summary>
|
|
private void StartGameLogic()
|
|
{
|
|
//LoadGame().Forget();
|
|
GameModule.UI.ShowUI<UIARGameWindow>();
|
|
}
|
|
|
|
public async UniTask LoadGame()
|
|
{
|
|
//await GameManager.Instance.LoadGame(true);
|
|
//return;
|
|
//await GameModule.Scene.LoadScene("scene_arTest").ToUniTask();
|
|
//await SceneManager.LoadSceneAsync("scene_arTest").ToUniTask();
|
|
GameModule.UI.ShowUI<UIInit>();
|
|
|
|
// GameObject go = new GameObject("SetPlatformResolutionManager");
|
|
// go.AddComponent<SetPlatformResolutionManager>();
|
|
await UniTask.Yield();
|
|
GameEvent.Send(LoadEventDefine.InitSceneAndData, "场景加载中...");
|
|
|
|
|
|
await GameModule.Scene.LoadScene("scene_home").ToUniTask();
|
|
GameManager.Instance.Init();
|
|
|
|
GameEvent.Send(LoadEventDefine.InitSceneAndData, "场景加载完毕");
|
|
ARBrochureHomeSystem.Instance.LoadHomeRoom().Forget();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭游戏。
|
|
/// </summary>
|
|
/// <param name="shutdownType">关闭游戏框架类型。</param>
|
|
public static void Shutdown(ShutdownType shutdownType)
|
|
{
|
|
Log.Info("GameApp Shutdown");
|
|
if (shutdownType == ShutdownType.None)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (shutdownType == ShutdownType.Restart)
|
|
{
|
|
Utility.Unity.RemoveUpdateListener(Instance.Update);
|
|
Utility.Unity.RemoveFixedUpdateListener(Instance.FixedUpdate);
|
|
Utility.Unity.RemoveLateUpdateListener(Instance.LateUpdate);
|
|
Utility.Unity.RemoveDestroyListener(Instance.OnDestroy);
|
|
Utility.Unity.RemoveOnDrawGizmosListener(Instance.OnDrawGizmos);
|
|
Utility.Unity.RemoveOnApplicationPauseListener(Instance.OnApplicationPause);
|
|
}
|
|
|
|
SingletonSystem.Release();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
var listLogic = _listLogicMgr;
|
|
var logicCnt = listLogic.Count;
|
|
for (int i = 0; i < logicCnt; i++)
|
|
{
|
|
var logic = listLogic[i];
|
|
logic.OnStart();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
{
|
|
TProfiler.BeginFirstSample("Update");
|
|
var listLogic = _listLogicMgr;
|
|
var logicCnt = listLogic.Count;
|
|
for (int i = 0; i < logicCnt; i++)
|
|
{
|
|
var logic = listLogic[i];
|
|
TProfiler.BeginSample(logic.GetType().FullName);
|
|
logic.OnUpdate();
|
|
TProfiler.EndSample();
|
|
}
|
|
|
|
TProfiler.EndFirstSample();
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
TProfiler.BeginFirstSample("FixedUpdate");
|
|
var listLogic = _listLogicMgr;
|
|
var logicCnt = listLogic.Count;
|
|
for (int i = 0; i < logicCnt; i++)
|
|
{
|
|
var logic = listLogic[i];
|
|
TProfiler.BeginSample(logic.GetType().FullName);
|
|
logic.OnFixedUpdate();
|
|
TProfiler.EndSample();
|
|
}
|
|
|
|
TProfiler.EndFirstSample();
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
TProfiler.BeginFirstSample("LateUpdate");
|
|
var listLogic = _listLogicMgr;
|
|
var logicCnt = listLogic.Count;
|
|
for (int i = 0; i < logicCnt; i++)
|
|
{
|
|
var logic = listLogic[i];
|
|
TProfiler.BeginSample(logic.GetType().FullName);
|
|
logic.OnLateUpdate();
|
|
TProfiler.EndSample();
|
|
}
|
|
|
|
TProfiler.EndFirstSample();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
var listLogic = _listLogicMgr;
|
|
var logicCnt = listLogic.Count;
|
|
for (int i = 0; i < logicCnt; i++)
|
|
{
|
|
var logic = listLogic[i];
|
|
logic.OnDestroy();
|
|
}
|
|
|
|
Shutdown(ShutdownType.Restart);
|
|
}
|
|
|
|
private void OnDrawGizmos()
|
|
{
|
|
#if UNITY_EDITOR
|
|
var listLogic = _listLogicMgr;
|
|
var logicCnt = listLogic.Count;
|
|
for (int i = 0; i < logicCnt; i++)
|
|
{
|
|
var logic = listLogic[i];
|
|
logic.OnDrawGizmos();
|
|
}
|
|
#endif
|
|
}
|
|
|
|
private void OnApplicationPause(bool isPause)
|
|
{
|
|
var listLogic = _listLogicMgr;
|
|
var logicCnt = listLogic.Count;
|
|
for (int i = 0; i < logicCnt; i++)
|
|
{
|
|
var logic = listLogic[i];
|
|
logic.OnApplicationPause(isPause);
|
|
}
|
|
}
|
|
} |