176 lines
5.1 KiB
C#
176 lines
5.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using GameBase;
|
|
using GameLogic;
|
|
using TEngine;
|
|
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
|
|
/// <summary>
|
|
/// 游戏App。
|
|
/// </summary>
|
|
public partial class GameApp : Singleton<GameApp>
|
|
{
|
|
private static List<Assembly> _hotfixAssembly;
|
|
|
|
private static List<ProcedureBase> _procedureList;
|
|
|
|
/// <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);
|
|
|
|
_procedureList = new List<ProcedureBase>();
|
|
_procedureList.Add(new GameLogic.OnEnterGameAppProcedure());
|
|
_procedureList.Add(new GameLogic.GameChangeSceneProcedure());
|
|
_procedureList.Add(new GameLogic.GameSceneProcedure());
|
|
GameModule.Procedure.RestartProcedure(_procedureList.ToArray());
|
|
|
|
PlayableAsset playableAsset;
|
|
|
|
Instance.StartGameLogic();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开始游戏业务层逻辑。
|
|
/// <remarks>显示UI、加载场景等。</remarks>
|
|
/// </summary>
|
|
private void StartGameLogic()
|
|
{
|
|
// GameModule.Audio.UISoundVolume = 0.7f;
|
|
GameModule.UI.ShowUI<UIGameStarForm>();
|
|
}
|
|
|
|
/// <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);
|
|
}
|
|
}
|
|
}
|