using System;
using System.Collections.Generic;
using UnityEngine;
namespace SHFrame
{
///
/// 游戏模块。
///
public partial class GameModule : MonoBehaviour
{
private static readonly Dictionary _moduleMaps = new Dictionary(ModuleImpSystem.DesignModuleCount);
private static GameObject _gameModuleRoot;
#region 框架模块
///
/// 获取游戏基础模块。
///
public static RootModule Base
{
get => _base ??= Get();
private set => _base = value;
}
private static RootModule _base;
// ///
// /// 获取调试模块。
// ///
// public static DebuggerModule Debugger
// {
// get => _debugger ??= Get();
// private set => _debugger = value;
// }
//
//
// private static DebuggerModule _debugger;
///
/// 获取有限状态机模块。
///
public static FSM.FsmModule Fsm => _fsm ??= Get();
private static FSM.FsmModule _fsm;
///
/// 流程管理模块。
///
public static ProcedureModule Procedure => _procedure ??= Get();
private static ProcedureModule _procedure;
///
/// 获取对象池模块。
///
public static ObjectPoolModule ObjectPool => _objectPool ??= Get();
private static ObjectPoolModule _objectPool;
// ///
// /// 获取资源模块。
// ///
// public static ResourceModule Resource => _resource ??= Get();
//
// private static ResourceModule _resource;
///
/// 获取音频模块。
///
public static AudioModule Audio => _audio ??= Get();
private static AudioModule _audio;
// ///
// /// 获取配置模块。
// ///
// public static SettingModule Setting => _setting ??= Get();
//
// private static SettingModule _setting;
// ///
// /// 获取多语言模块。
// ///
// public static LocalizationModule Localization => _localization ??= Get();
//
// private static LocalizationModule _localization;
// ///
// /// 获取计时器模块。
// ///
// public static TimerModule Timer => _timer ??= Get();
//
// private static TimerModule _timer;
#endregion
///
/// 获取游戏框架模块类。
///
/// 游戏框架模块类。
/// 游戏框架模块实例。
public static T Get() where T : Module
{
Type type = typeof(T);
if (_moduleMaps.TryGetValue(type, out var ret))
{
return ret as T;
}
T module = ModuleSystem.GetModule();
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;
}
}
}