//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 loyalsoft. All rights reserved.
// Homepage: http://www.game7000.com/
// Feedback: http://www.game7000.com/
//------------------------------------------------------------
using System;
using System.Collections.Generic;
namespace GameFramework.Setting
{
///
/// 游戏配置管理器。
///
internal sealed class SettingManager : GameFrameworkModule, ISettingManager
{
private ISettingHelper m_SettingHelper;
///
/// 初始化游戏配置管理器的新实例。
///
public SettingManager()
{
m_SettingHelper = null;
}
///
/// 获取游戏配置项数量。
///
public int Count
{
get
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
return m_SettingHelper.Count;
}
}
///
/// 游戏配置管理器轮询。
///
/// 逻辑流逝时间,以秒为单位。
/// 真实流逝时间,以秒为单位。
internal override void Update(float elapseSeconds, float realElapseSeconds)
{
}
///
/// 关闭并清理游戏配置管理器。
///
internal override void Shutdown()
{
Save();
}
///
/// 设置游戏配置辅助器。
///
/// 游戏配置辅助器。
public void SetSettingHelper(ISettingHelper settingHelper)
{
if (settingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
m_SettingHelper = settingHelper;
}
///
/// 加载游戏配置。
///
/// 是否加载游戏配置成功。
public bool Load()
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
return m_SettingHelper.Load();
}
///
/// 保存游戏配置。
///
/// 是否保存游戏配置成功。
public bool Save()
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
return m_SettingHelper.Save();
}
///
/// 获取所有游戏配置项的名称。
///
/// 所有游戏配置项的名称。
public string[] GetAllSettingNames()
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
return m_SettingHelper.GetAllSettingNames();
}
///
/// 获取所有游戏配置项的名称。
///
/// 所有游戏配置项的名称。
public void GetAllSettingNames(List results)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
m_SettingHelper.GetAllSettingNames(results);
}
///
/// 检查是否存在指定游戏配置项。
///
/// 要检查游戏配置项的名称。
/// 指定的游戏配置项是否存在。
public bool HasSetting(string settingName)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.HasSetting(settingName);
}
///
/// 移除指定游戏配置项。
///
/// 要移除游戏配置项的名称。
/// 是否移除指定游戏配置项成功。
public bool RemoveSetting(string settingName)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.RemoveSetting(settingName);
}
///
/// 清空所有游戏配置项。
///
public void RemoveAllSettings()
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
m_SettingHelper.RemoveAllSettings();
}
///
/// 从指定游戏配置项中读取布尔值。
///
/// 要获取游戏配置项的名称。
/// 读取的布尔值。
public bool GetBool(string settingName)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.GetBool(settingName);
}
///
/// 从指定游戏配置项中读取布尔值。
///
/// 要获取游戏配置项的名称。
/// 当指定的游戏配置项不存在时,返回此默认值。
/// 读取的布尔值。
public bool GetBool(string settingName, bool defaultValue)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.GetBool(settingName, defaultValue);
}
///
/// 向指定游戏配置项写入布尔值。
///
/// 要写入游戏配置项的名称。
/// 要写入的布尔值。
public void SetBool(string settingName, bool value)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
m_SettingHelper.SetBool(settingName, value);
}
///
/// 从指定游戏配置项中读取整数值。
///
/// 要获取游戏配置项的名称。
/// 读取的整数值。
public int GetInt(string settingName)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.GetInt(settingName);
}
///
/// 从指定游戏配置项中读取整数值。
///
/// 要获取游戏配置项的名称。
/// 当指定的游戏配置项不存在时,返回此默认值。
/// 读取的整数值。
public int GetInt(string settingName, int defaultValue)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.GetInt(settingName, defaultValue);
}
///
/// 向指定游戏配置项写入整数值。
///
/// 要写入游戏配置项的名称。
/// 要写入的整数值。
public void SetInt(string settingName, int value)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
m_SettingHelper.SetInt(settingName, value);
}
///
/// 从指定游戏配置项中读取浮点数值。
///
/// 要获取游戏配置项的名称。
/// 读取的浮点数值。
public float GetFloat(string settingName)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.GetFloat(settingName);
}
///
/// 从指定游戏配置项中读取浮点数值。
///
/// 要获取游戏配置项的名称。
/// 当指定的游戏配置项不存在时,返回此默认值。
/// 读取的浮点数值。
public float GetFloat(string settingName, float defaultValue)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.GetFloat(settingName, defaultValue);
}
///
/// 向指定游戏配置项写入浮点数值。
///
/// 要写入游戏配置项的名称。
/// 要写入的浮点数值。
public void SetFloat(string settingName, float value)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
m_SettingHelper.SetFloat(settingName, value);
}
///
/// 从指定游戏配置项中读取字符串值。
///
/// 要获取游戏配置项的名称。
/// 读取的字符串值。
public string GetString(string settingName)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.GetString(settingName);
}
///
/// 从指定游戏配置项中读取字符串值。
///
/// 要获取游戏配置项的名称。
/// 当指定的游戏配置项不存在时,返回此默认值。
/// 读取的字符串值。
public string GetString(string settingName, string defaultValue)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.GetString(settingName, defaultValue);
}
///
/// 向指定游戏配置项写入字符串值。
///
/// 要写入游戏配置项的名称。
/// 要写入的字符串值。
public void SetString(string settingName, string value)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
m_SettingHelper.SetString(settingName, value);
}
///
/// 从指定游戏配置项中读取对象。
///
/// 要读取对象的类型。
/// 要获取游戏配置项的名称。
/// 读取的对象。
public T GetObject(string settingName)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.GetObject(settingName);
}
///
/// 从指定游戏配置项中读取对象。
///
/// 要读取对象的类型。
/// 要获取游戏配置项的名称。
/// 读取的对象。
public object GetObject(Type objectType, string settingName)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (objectType == null)
{
throw new GameFrameworkException("Object type is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.GetObject(objectType, settingName);
}
///
/// 从指定游戏配置项中读取对象。
///
/// 要读取对象的类型。
/// 要获取游戏配置项的名称。
/// 当指定的游戏配置项不存在时,返回此默认对象。
/// 读取的对象。
public T GetObject(string settingName, T defaultObj)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.GetObject(settingName, defaultObj);
}
///
/// 从指定游戏配置项中读取对象。
///
/// 要读取对象的类型。
/// 要获取游戏配置项的名称。
/// 当指定的游戏配置项不存在时,返回此默认对象。
/// 读取的对象。
public object GetObject(Type objectType, string settingName, object defaultObj)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (objectType == null)
{
throw new GameFrameworkException("Object type is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
return m_SettingHelper.GetObject(objectType, settingName, defaultObj);
}
///
/// 向指定游戏配置项写入对象。
///
/// 要写入对象的类型。
/// 要写入游戏配置项的名称。
/// 要写入的对象。
public void SetObject(string settingName, T obj)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
m_SettingHelper.SetObject(settingName, obj);
}
///
/// 向指定游戏配置项写入对象。
///
/// 要写入游戏配置项的名称。
/// 要写入的对象。
public void SetObject(string settingName, object obj)
{
if (m_SettingHelper == null)
{
throw new GameFrameworkException("Setting helper is invalid.");
}
if (string.IsNullOrEmpty(settingName))
{
throw new GameFrameworkException("Setting name is invalid.");
}
m_SettingHelper.SetObject(settingName, obj);
}
}
}