PC-20230316NUNE\Administrator c5700ce655 提交
2024-09-29 20:18:48 +08:00

150 lines
4.4 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
namespace SHFrame
{
/// <summary>
/// 游戏模块。
/// </summary>
public partial class GameModule : MonoBehaviour
{
private static readonly Dictionary<Type, Module> _moduleMaps = new Dictionary<Type, Module>(ModuleImpSystem.DesignModuleCount);
private static GameObject _gameModuleRoot;
#region
/// <summary>
/// 获取游戏基础模块。
/// </summary>
public static RootModule Base
{
get => _base ??= Get<RootModule>();
private set => _base = value;
}
private static RootModule _base;
// /// <summary>
// /// 获取调试模块。
// /// </summary>
// public static DebuggerModule Debugger
// {
// get => _debugger ??= Get<DebuggerModule>();
// private set => _debugger = value;
// }
//
//
// private static DebuggerModule _debugger;
/// <summary>
/// 获取有限状态机模块。
/// </summary>
public static FSM.FsmModule Fsm => _fsm ??= Get<FSM.FsmModule>();
private static FSM.FsmModule _fsm;
/// <summary>
/// 流程管理模块。
/// </summary>
public static ProcedureModule Procedure => _procedure ??= Get<ProcedureModule>();
private static ProcedureModule _procedure;
/// <summary>
/// 获取对象池模块。
/// </summary>
public static ObjectPoolModule ObjectPool => _objectPool ??= Get<ObjectPoolModule>();
private static ObjectPoolModule _objectPool;
// /// <summary>
// /// 获取资源模块。
// /// </summary>
// public static ResourceModule Resource => _resource ??= Get<ResourceModule>();
//
// private static ResourceModule _resource;
/// <summary>
/// 获取音频模块。
/// </summary>
public static AudioModule Audio => _audio ??= Get<AudioModule>();
private static AudioModule _audio;
// /// <summary>
// /// 获取配置模块。
// /// </summary>
// public static SettingModule Setting => _setting ??= Get<SettingModule>();
//
// private static SettingModule _setting;
// /// <summary>
// /// 获取多语言模块。
// /// </summary>
// public static LocalizationModule Localization => _localization ??= Get<LocalizationModule>();
//
// private static LocalizationModule _localization;
// /// <summary>
// /// 获取计时器模块。
// /// </summary>
// public static TimerModule Timer => _timer ??= Get<TimerModule>();
//
// private static TimerModule _timer;
#endregion
/// <summary>
/// 获取游戏框架模块类。
/// </summary>
/// <typeparam name="T">游戏框架模块类。</typeparam>
/// <returns>游戏框架模块实例。</returns>
public static T Get<T>() where T : Module
{
Type type = typeof(T);
if (_moduleMaps.TryGetValue(type, out var ret))
{
return ret as T;
}
T module = ModuleSystem.GetModule<T>();
Log.Assert(condition: module != null, $"{typeof(T)} is null");
_moduleMaps.Add(type, module);
return module;
}
private void Start()
{
Log.Info("GameModule Active");
_gameModuleRoot = gameObject;
_gameModuleRoot.name = $"[{nameof(GameModule)}]";
DontDestroyOnLoad(_gameModuleRoot);
}
public static void Shutdown(ShutdownType shutdownType)
{
Log.Info("GameModule Shutdown");
if (_gameModuleRoot != null)
{
Destroy(_gameModuleRoot);
_gameModuleRoot = null;
}
_moduleMaps.Clear();
_base = null;
// _debugger = null;
_fsm = null;
_procedure = null;
_objectPool = null;
// _resource = null;
_audio = null;
// _setting = null;
}
}
}