mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 19:03:29 +08:00
- 移除 SettingsResetEvent 中的旧设置属性,改为仅保存新设置 - 删除 SettingsPersistence 中的重置方法,统一通过命令模式处理 - 在 SettingsSystem 中添加 ResetAsync 方法并集成命令模式 - 为 AudioSettings 和 GraphicsSettings 添加 Reset 方法实现 - 扩展 ISettingsData 接口添加 Reset 方法定义 - 从接口中移除重置相关方法定义 - 在 ISettingsSystem 中添加重置相关的异步方法声明 - 为 AudioBusMapSettings 添加 Reset 方法实现 - 新增 ResetSettingsCommand 和 ResetSettingsInput 实现命令模式 - 添加 SettingsData 抽象基类提供默认的 Reset 实现 - [skip ci]
36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
using System;
|
|
using System.Reflection;
|
|
|
|
namespace GFramework.Game.Abstractions.setting;
|
|
|
|
/// <summary>
|
|
/// 设置数据抽象基类,提供默认的 Reset() 实现
|
|
/// </summary>
|
|
public abstract class SettingsData : ISettingsData
|
|
{
|
|
/// <summary>
|
|
/// 重置设置为默认值
|
|
/// 使用反射将所有属性重置为它们的默认值
|
|
/// </summary>
|
|
public virtual void Reset()
|
|
{
|
|
var properties = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
|
foreach (var prop in properties)
|
|
{
|
|
if (!prop.CanWrite || !prop.CanRead) continue;
|
|
|
|
var defaultValue = GetDefaultValue(prop.PropertyType);
|
|
prop.SetValue(this, defaultValue);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取指定类型的默认值
|
|
/// </summary>
|
|
/// <param name="type">要获取默认值的类型</param>
|
|
/// <returns>类型的默认值</returns>
|
|
private static object? GetDefaultValue(Type type)
|
|
{
|
|
return type.IsValueType ? Activator.CreateInstance(type) : null;
|
|
}
|
|
} |