mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
TEngine 6
This commit is contained in:
@@ -1,159 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using GameBase;
|
||||
using GameLogic;
|
||||
using TEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// 游戏App。
|
||||
/// </summary>
|
||||
public partial class GameApp:Singleton<GameApp>
|
||||
public partial class GameApp
|
||||
{
|
||||
private static List<Assembly> _hotfixAssembly;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 热更域App主入口。
|
||||
/// </summary>
|
||||
/// <param name="objects"></param>
|
||||
public static void Entrance(object[] objects)
|
||||
{
|
||||
GameEventHelper.Init();
|
||||
_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();
|
||||
ModuleSystem.GetModule<IUpdateDriver>().AddDestroyListener(Release);
|
||||
StartGameLogic();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始游戏业务层逻辑。
|
||||
/// <remarks>显示UI、加载场景等。</remarks>
|
||||
/// </summary>
|
||||
private void StartGameLogic()
|
||||
|
||||
private static void StartGameLogic()
|
||||
{
|
||||
|
||||
GameEvent.Get<ILoginUI>().ShowLoginUI(NetworkError.Ok);
|
||||
GameModule.UI.ShowUIAsync<BattleMainUI>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭游戏。
|
||||
/// </summary>
|
||||
/// <param name="shutdownType">关闭游戏框架类型。</param>
|
||||
public static void Shutdown(ShutdownType shutdownType)
|
||||
|
||||
private static void Release()
|
||||
{
|
||||
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);
|
||||
}
|
||||
Log.Warning("======= Release GameApp =======");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user