123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 |
- //------------------------------------------------------------
- // 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
- {
- /// <summary>
- /// 游戏配置管理器。
- /// </summary>
- internal sealed class SettingManager : GameFrameworkModule, ISettingManager
- {
- private ISettingHelper m_SettingHelper;
- /// <summary>
- /// 初始化游戏配置管理器的新实例。
- /// </summary>
- public SettingManager()
- {
- m_SettingHelper = null;
- }
- /// <summary>
- /// 获取游戏配置项数量。
- /// </summary>
- public int Count
- {
- get
- {
- if (m_SettingHelper == null)
- {
- throw new GameFrameworkException("Setting helper is invalid.");
- }
- return m_SettingHelper.Count;
- }
- }
- /// <summary>
- /// 游戏配置管理器轮询。
- /// </summary>
- /// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
- /// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
- internal override void Update(float elapseSeconds, float realElapseSeconds)
- {
- }
- /// <summary>
- /// 关闭并清理游戏配置管理器。
- /// </summary>
- internal override void Shutdown()
- {
- Save();
- }
- /// <summary>
- /// 设置游戏配置辅助器。
- /// </summary>
- /// <param name="settingHelper">游戏配置辅助器。</param>
- public void SetSettingHelper(ISettingHelper settingHelper)
- {
- if (settingHelper == null)
- {
- throw new GameFrameworkException("Setting helper is invalid.");
- }
- m_SettingHelper = settingHelper;
- }
- /// <summary>
- /// 加载游戏配置。
- /// </summary>
- /// <returns>是否加载游戏配置成功。</returns>
- public bool Load()
- {
- if (m_SettingHelper == null)
- {
- throw new GameFrameworkException("Setting helper is invalid.");
- }
- return m_SettingHelper.Load();
- }
- /// <summary>
- /// 保存游戏配置。
- /// </summary>
- /// <returns>是否保存游戏配置成功。</returns>
- public bool Save()
- {
- if (m_SettingHelper == null)
- {
- throw new GameFrameworkException("Setting helper is invalid.");
- }
- return m_SettingHelper.Save();
- }
- /// <summary>
- /// 获取所有游戏配置项的名称。
- /// </summary>
- /// <returns>所有游戏配置项的名称。</returns>
- public string[] GetAllSettingNames()
- {
- if (m_SettingHelper == null)
- {
- throw new GameFrameworkException("Setting helper is invalid.");
- }
- return m_SettingHelper.GetAllSettingNames();
- }
- /// <summary>
- /// 获取所有游戏配置项的名称。
- /// </summary>
- /// <param name="results">所有游戏配置项的名称。</param>
- public void GetAllSettingNames(List<string> results)
- {
- if (m_SettingHelper == null)
- {
- throw new GameFrameworkException("Setting helper is invalid.");
- }
- m_SettingHelper.GetAllSettingNames(results);
- }
- /// <summary>
- /// 检查是否存在指定游戏配置项。
- /// </summary>
- /// <param name="settingName">要检查游戏配置项的名称。</param>
- /// <returns>指定的游戏配置项是否存在。</returns>
- 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);
- }
- /// <summary>
- /// 移除指定游戏配置项。
- /// </summary>
- /// <param name="settingName">要移除游戏配置项的名称。</param>
- /// <returns>是否移除指定游戏配置项成功。</returns>
- 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);
- }
- /// <summary>
- /// 清空所有游戏配置项。
- /// </summary>
- public void RemoveAllSettings()
- {
- if (m_SettingHelper == null)
- {
- throw new GameFrameworkException("Setting helper is invalid.");
- }
- m_SettingHelper.RemoveAllSettings();
- }
- /// <summary>
- /// 从指定游戏配置项中读取布尔值。
- /// </summary>
- /// <param name="settingName">要获取游戏配置项的名称。</param>
- /// <returns>读取的布尔值。</returns>
- 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);
- }
- /// <summary>
- /// 从指定游戏配置项中读取布尔值。
- /// </summary>
- /// <param name="settingName">要获取游戏配置项的名称。</param>
- /// <param name="defaultValue">当指定的游戏配置项不存在时,返回此默认值。</param>
- /// <returns>读取的布尔值。</returns>
- 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);
- }
- /// <summary>
- /// 向指定游戏配置项写入布尔值。
- /// </summary>
- /// <param name="settingName">要写入游戏配置项的名称。</param>
- /// <param name="value">要写入的布尔值。</param>
- 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);
- }
- /// <summary>
- /// 从指定游戏配置项中读取整数值。
- /// </summary>
- /// <param name="settingName">要获取游戏配置项的名称。</param>
- /// <returns>读取的整数值。</returns>
- 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);
- }
- /// <summary>
- /// 从指定游戏配置项中读取整数值。
- /// </summary>
- /// <param name="settingName">要获取游戏配置项的名称。</param>
- /// <param name="defaultValue">当指定的游戏配置项不存在时,返回此默认值。</param>
- /// <returns>读取的整数值。</returns>
- 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);
- }
- /// <summary>
- /// 向指定游戏配置项写入整数值。
- /// </summary>
- /// <param name="settingName">要写入游戏配置项的名称。</param>
- /// <param name="value">要写入的整数值。</param>
- 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);
- }
- /// <summary>
- /// 从指定游戏配置项中读取浮点数值。
- /// </summary>
- /// <param name="settingName">要获取游戏配置项的名称。</param>
- /// <returns>读取的浮点数值。</returns>
- 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);
- }
- /// <summary>
- /// 从指定游戏配置项中读取浮点数值。
- /// </summary>
- /// <param name="settingName">要获取游戏配置项的名称。</param>
- /// <param name="defaultValue">当指定的游戏配置项不存在时,返回此默认值。</param>
- /// <returns>读取的浮点数值。</returns>
- 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);
- }
- /// <summary>
- /// 向指定游戏配置项写入浮点数值。
- /// </summary>
- /// <param name="settingName">要写入游戏配置项的名称。</param>
- /// <param name="value">要写入的浮点数值。</param>
- 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);
- }
- /// <summary>
- /// 从指定游戏配置项中读取字符串值。
- /// </summary>
- /// <param name="settingName">要获取游戏配置项的名称。</param>
- /// <returns>读取的字符串值。</returns>
- 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);
- }
- /// <summary>
- /// 从指定游戏配置项中读取字符串值。
- /// </summary>
- /// <param name="settingName">要获取游戏配置项的名称。</param>
- /// <param name="defaultValue">当指定的游戏配置项不存在时,返回此默认值。</param>
- /// <returns>读取的字符串值。</returns>
- 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);
- }
- /// <summary>
- /// 向指定游戏配置项写入字符串值。
- /// </summary>
- /// <param name="settingName">要写入游戏配置项的名称。</param>
- /// <param name="value">要写入的字符串值。</param>
- 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);
- }
- /// <summary>
- /// 从指定游戏配置项中读取对象。
- /// </summary>
- /// <typeparam name="T">要读取对象的类型。</typeparam>
- /// <param name="settingName">要获取游戏配置项的名称。</param>
- /// <returns>读取的对象。</returns>
- public T GetObject<T>(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<T>(settingName);
- }
- /// <summary>
- /// 从指定游戏配置项中读取对象。
- /// </summary>
- /// <param name="objectType">要读取对象的类型。</param>
- /// <param name="settingName">要获取游戏配置项的名称。</param>
- /// <returns>读取的对象。</returns>
- 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);
- }
- /// <summary>
- /// 从指定游戏配置项中读取对象。
- /// </summary>
- /// <typeparam name="T">要读取对象的类型。</typeparam>
- /// <param name="settingName">要获取游戏配置项的名称。</param>
- /// <param name="defaultObj">当指定的游戏配置项不存在时,返回此默认对象。</param>
- /// <returns>读取的对象。</returns>
- public T GetObject<T>(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);
- }
- /// <summary>
- /// 从指定游戏配置项中读取对象。
- /// </summary>
- /// <param name="objectType">要读取对象的类型。</param>
- /// <param name="settingName">要获取游戏配置项的名称。</param>
- /// <param name="defaultObj">当指定的游戏配置项不存在时,返回此默认对象。</param>
- /// <returns>读取的对象。</returns>
- 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);
- }
- /// <summary>
- /// 向指定游戏配置项写入对象。
- /// </summary>
- /// <typeparam name="T">要写入对象的类型。</typeparam>
- /// <param name="settingName">要写入游戏配置项的名称。</param>
- /// <param name="obj">要写入的对象。</param>
- public void SetObject<T>(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);
- }
- /// <summary>
- /// 向指定游戏配置项写入对象。
- /// </summary>
- /// <param name="settingName">要写入游戏配置项的名称。</param>
- /// <param name="obj">要写入的对象。</param>
- 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);
- }
- }
- }
|