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
@@ -2,40 +2,16 @@ using UnityEngine;
|
||||
|
||||
/// Global mouse look-around sensitivity multiplier, shared by every camera
|
||||
/// controller (FreeCam, FirstPerson, ThirdPersonOrbit). 1 = unchanged baseline.
|
||||
/// Persisted per-machine via PlayerPrefs so the setting survives restarts.
|
||||
/// Persisted via GameSettings (Settings.json) so the setting survives restarts.
|
||||
public static class MouseSensitivity
|
||||
{
|
||||
public const float Default = 1f;
|
||||
public const float Min = 0.1f;
|
||||
public const float Max = 4f;
|
||||
|
||||
const string PrefKey = "Settings.MouseSensitivity";
|
||||
|
||||
static bool _loaded;
|
||||
static float _multiplier = Default;
|
||||
|
||||
public static float Multiplier
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_loaded)
|
||||
{
|
||||
_loaded = true;
|
||||
_multiplier = Mathf.Clamp(PlayerPrefs.GetFloat(PrefKey, Default), Min, Max);
|
||||
}
|
||||
return _multiplier;
|
||||
}
|
||||
set
|
||||
{
|
||||
float v = Mathf.Clamp(value, Min, Max);
|
||||
_loaded = true;
|
||||
if (Mathf.Approximately(v, _multiplier)) return;
|
||||
_multiplier = v;
|
||||
PlayerPrefs.SetFloat(PrefKey, v);
|
||||
// Flush to disk now so the setting survives a hard kill (build), not
|
||||
// only a clean quit. Settings changes are rare user actions, so the
|
||||
// extra write is negligible.
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
get => Mathf.Clamp(GameSettings.MouseSensitivity, Min, Max);
|
||||
set => GameSettings.MouseSensitivity = Mathf.Clamp(value, Min, Max);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user