//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using System;
using AlicizaX.Runtime;
using UnityEngine;
namespace AlicizaX.Config.Runtime
{
///
/// 全局配置组件。
///
[DisallowMultipleComponent]
[AddComponentMenu("Game Framework/Config")]
public sealed class ConfigComponent : GameFrameworkComponent
{
private IConfigManager m_ConfigManager = null;
///
/// 获取全局配置项数量。
///
public int Count
{
get { return m_ConfigManager.Count; }
}
///
/// 游戏框架组件初始化。
///
protected override void Awake()
{
ImplementationComponentType = Utility.Assembly.GetType(componentType);
InterfaceComponentType = typeof(IConfigManager);
base.Awake();
m_ConfigManager = SysModuleCenter.GetModule();
if (m_ConfigManager == null)
{
Log.Fatal("Config manager is invalid.");
return;
}
}
///
/// 获取指定全局配置项。
///
///
///
public T GetConfig() where T : IDataTable
{
if (HasConfig())
{
var configName = typeof(T).Name;
var config = m_ConfigManager.GetConfig(configName);
if (config != null)
{
return (T)config;
}
}
return default;
}
///
/// 检查是否存在指定全局配置项。
///
/// 指定的全局配置项是否存在。
public bool HasConfig() where T : IDataTable
{
var configName = typeof(T).Name;
return m_ConfigManager.HasConfig(configName);
}
///
/// 移除指定全局配置项。
///
/// 是否移除全局配置项成功。
public bool RemoveConfig() where T : IDataTable
{
var configName = typeof(T).Name;
return m_ConfigManager.RemoveConfig(configName);
}
///
/// 清空所有全局配置项。
///
public void RemoveAllConfigs()
{
m_ConfigManager.RemoveAllConfigs();
}
///
/// 增加
///
///
///
public void Add(string configName, IDataTable dataTable)
{
m_ConfigManager.AddConfig(configName, dataTable);
}
}
}