60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using UnityEngine;
|
|
|
|
namespace Ashwild.Settings
|
|
{
|
|
/// <summary>
|
|
/// Binds the control widgets (sensitivity, invert-Y, crosshair) to the <see cref="SettingsManager"/>,
|
|
/// configuring the sensitivity slider from the authored <see cref="SettingsDefinition"/>.
|
|
/// </summary>
|
|
public class ControlsSettingsSubPanel : SettingsSubPanel
|
|
{
|
|
#region Serialized Fields
|
|
|
|
[Header("Widgets")]
|
|
[SerializeField] private SettingSliderWidget sensitivitySlider;
|
|
[SerializeField] private SettingToggleWidget invertYToggle;
|
|
[SerializeField] private SettingToggleWidget crosshairToggle;
|
|
|
|
#endregion
|
|
|
|
#region Unity Lifecycle
|
|
|
|
/// <summary>
|
|
/// Initializes each control widget from the definition with its apply action.
|
|
/// </summary>
|
|
private void Awake()
|
|
{
|
|
SettingsManager s = SettingsManager.Instance;
|
|
if (s == null || s.Definition == null)
|
|
{
|
|
Debug.LogError($"[ControlsSettingsSubPanel] SettingsManager/Definition unavailable on '{name}'.", this);
|
|
return;
|
|
}
|
|
SettingsDefinition def = s.Definition;
|
|
|
|
sensitivitySlider.Init(def.Sensitivity.Min, def.Sensitivity.Max, def.Sensitivity.LabelScale, def.Sensitivity.LabelFormat, v => s.SetSensitivity(v));
|
|
invertYToggle.Init(v => s.SetInvertY(v));
|
|
crosshairToggle.Init(v => s.SetCrosshairEnabled(v));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public API
|
|
|
|
/// <summary>
|
|
/// Pushes the manager's current control values into the widgets.
|
|
/// </summary>
|
|
public override void Refresh()
|
|
{
|
|
SettingsManager s = SettingsManager.Instance;
|
|
if (s == null) return;
|
|
|
|
sensitivitySlider.SetValue(s.Sensitivity);
|
|
invertYToggle.SetValue(s.InvertY);
|
|
crosshairToggle.SetValue(s.CrosshairEnabled);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|