多轮审查和修复
This commit is contained in:
89
Assets/Scripts/Support/Accessibility/AccessibilityManager.cs
Normal file
89
Assets/Scripts/Support/Accessibility/AccessibilityManager.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using UnityEngine;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
namespace BaseGames.Support.Accessibility
|
||||
{
|
||||
/// <summary>
|
||||
/// 无障碍功能管理器(架构 16_SupportingModules §6.1)。
|
||||
/// 响应设置变更,广播色盲模式事件;提供 CanPlayScreenShake() 供 FeedbackSystem 查询。
|
||||
/// </summary>
|
||||
public class AccessibilityManager : MonoBehaviour
|
||||
{
|
||||
[Header("设置资产")]
|
||||
[SerializeField] private AccessibilitySettingsSO _settings;
|
||||
|
||||
[Header("事件频道(输出)")]
|
||||
[SerializeField] private ColorblindModeEventChannelSO _onColorblindModeChanged;
|
||||
[SerializeField] private BoolEventChannelSO _onScreenShakeChanged;
|
||||
|
||||
private static AccessibilityManager _instance;
|
||||
|
||||
// ── 静态查询接口(供 FeedbackSystem 使用) ───────────────────────────────
|
||||
public static bool CanPlayScreenShake()
|
||||
=> _instance == null || (_instance._settings != null && _instance._settings.ScreenShake);
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (_instance != null && _instance != this)
|
||||
{
|
||||
Debug.LogWarning("[AccessibilityManager] 已存在实例,请确保本组件仅放置在 Persistent 场景中。", this);
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
_instance = this;
|
||||
if (_settings != null)
|
||||
_settings.Load();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 初始化时广播当前色盲模式
|
||||
if (_settings != null)
|
||||
_onColorblindModeChanged?.Raise(_settings.ColorblindMode);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_instance == this) _instance = null;
|
||||
}
|
||||
|
||||
/// <summary>应用新的设置并持久化。</summary>
|
||||
public void Apply(AccessibilitySettingsSO newSettings)
|
||||
{
|
||||
_settings.ScreenShake = newSettings.ScreenShake;
|
||||
_settings.ReducedFlash = newSettings.ReducedFlash;
|
||||
_settings.LargeText = newSettings.LargeText;
|
||||
_settings.HighContrast = newSettings.HighContrast;
|
||||
_settings.UIScale = newSettings.UIScale;
|
||||
|
||||
bool colorblindChanged = _settings.ColorblindMode != newSettings.ColorblindMode;
|
||||
_settings.ColorblindMode = newSettings.ColorblindMode;
|
||||
|
||||
_settings.Save();
|
||||
|
||||
_onScreenShakeChanged?.Raise(_settings.ScreenShake);
|
||||
if (colorblindChanged)
|
||||
_onColorblindModeChanged?.Raise(_settings.ColorblindMode);
|
||||
}
|
||||
|
||||
/// <summary>直接设置色盲模式。</summary>
|
||||
public void SetColorblindMode(ColorblindMode mode)
|
||||
{
|
||||
if (_settings == null) return;
|
||||
_settings.ColorblindMode = mode;
|
||||
_settings.Save();
|
||||
_onColorblindModeChanged?.Raise(mode);
|
||||
}
|
||||
|
||||
/// <summary>直接设置屏幕抖动开关。</summary>
|
||||
public void SetScreenShake(bool enabled)
|
||||
{
|
||||
if (_settings == null) return;
|
||||
_settings.ScreenShake = enabled;
|
||||
_settings.Save();
|
||||
_onScreenShakeChanged?.Raise(enabled);
|
||||
}
|
||||
|
||||
public AccessibilitySettingsSO Settings => _settings;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user