67 lines
2.4 KiB
C#
67 lines
2.4 KiB
C#
using UnityEngine;
|
|
|
|
namespace Ashwild.Settings
|
|
{
|
|
/// <summary>
|
|
/// Binds the graphics widgets (quality, vsync, FPS cap, FOV) to the <see cref="SettingsManager"/>.
|
|
/// The panel is the only layer that knows what each widget means: it reads the authored
|
|
/// configuration from the manager's <see cref="SettingsDefinition"/> and initializes each widget
|
|
/// with its data and apply action, then pushes the current value on refresh. The widgets stay
|
|
/// pure UI.
|
|
/// </summary>
|
|
public class GraphicsSettingsSubPanel : SettingsSubPanel
|
|
{
|
|
#region Serialized Fields
|
|
|
|
[Header("Widgets")]
|
|
[SerializeField] private SettingDropdownWidget qualityDropdown;
|
|
[SerializeField] private SettingToggleWidget vsyncToggle;
|
|
[SerializeField] private SettingStepperWidget targetFpsStepper;
|
|
[SerializeField] private SettingSliderWidget fovSlider;
|
|
|
|
#endregion
|
|
|
|
#region Unity Lifecycle
|
|
|
|
/// <summary>
|
|
/// Initializes each widget from the definition with the action to apply to the manager.
|
|
/// </summary>
|
|
private void Awake()
|
|
{
|
|
SettingsManager s = SettingsManager.Instance;
|
|
if (s == null || s.Definition == null)
|
|
{
|
|
Debug.LogError($"[GraphicsSettingsSubPanel] SettingsManager/Definition unavailable on '{name}'.", this);
|
|
return;
|
|
}
|
|
SettingsDefinition def = s.Definition;
|
|
|
|
qualityDropdown.Init(v => s.SetQualityLevel(v));
|
|
vsyncToggle.Init(v => s.SetVSync(v));
|
|
targetFpsStepper.Init(def.TargetFps.ToWidgetPresets(), false, v => s.SetTargetFps(v));
|
|
fovSlider.Init(def.Fov.Min, def.Fov.Max, def.Fov.LabelScale, def.Fov.LabelFormat, v => s.SetFov(v));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public API
|
|
|
|
/// <summary>
|
|
/// Pushes the manager's current graphics values into the widgets.
|
|
/// </summary>
|
|
public override void Refresh()
|
|
{
|
|
SettingsManager s = SettingsManager.Instance;
|
|
if (s == null) return;
|
|
|
|
qualityDropdown.SetOptions(QualitySettings.names);
|
|
qualityDropdown.SetValue(s.QualityLevel);
|
|
vsyncToggle.SetValue(s.VSync);
|
|
targetFpsStepper.SetValue(s.TargetFps);
|
|
fovSlider.SetValue(s.Fov);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|