Move settings to Settings.json and add master volume
Replace the former per-value PlayerPrefs storage with a shared human-readable Settings.json store (GameSettings). MouseSensitivity keeps its public .Multiplier API and only swaps its backing to the JSON store, so the camera controllers stay untouched. Add a MasterVolume facade that drives the AudioMixer's exposed "MasterVolume" parameter (loaded from Resources, linear<->dB mapping), applied at startup and on change, plus a MasterVolumeSlider binder. The default is the level currently authored on the mixer instead of an arbitrary constant. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
f586ef7a15
commit
ba7f3c2e89
9 files changed
+290
-27
No files matched your search
@@ -0,0 +1,37 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// Binds a UI Slider (and optional value label) to the global MasterVolume level.
|
||||
/// The slider's range is authored in the inspector (0 - 1); this only reads/writes
|
||||
/// the value so scene-side range edits are respected.
|
||||
public class MasterVolumeSlider : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Slider slider;
|
||||
[Tooltip("Optional TMP label showing the current volume as a percentage (e.g. \"80%\").")]
|
||||
[SerializeField] private TMP_Text valueLabel;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (!slider) return;
|
||||
slider.SetValueWithoutNotify(MasterVolume.Volume);
|
||||
UpdateLabel(MasterVolume.Volume);
|
||||
slider.onValueChanged.AddListener(OnSliderChanged);
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (slider) slider.onValueChanged.RemoveListener(OnSliderChanged);
|
||||
}
|
||||
|
||||
void OnSliderChanged(float value)
|
||||
{
|
||||
MasterVolume.Volume = value;
|
||||
UpdateLabel(value);
|
||||
}
|
||||
|
||||
void UpdateLabel(float value)
|
||||
{
|
||||
if (valueLabel) valueLabel.text = Mathf.RoundToInt(value * 100f) + "%";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user