Files
chameleon/Assets/Scripts/MouseSensitivity.cs
T
adminandClaude Opus 4.8 2a6fc163b1 Add persistent global mouse sensitivity setting with slider
MouseSensitivity is a static, PlayerPrefs-backed multiplier (default 1,
clamped 0.1-4.0) that scales the mouse-look delta in the FreeCam,
FirstPerson and ThirdPerson controllers. Writes flush immediately so the
value survives a hard build exit. MouseSensitivitySlider binds the
Settings-panel slider to it (range read from the inspector) and mirrors
the value into its label, syncing on panel open via OnEnable.

Main.unity now contains the session-manager canvas directly (the
Online Session Manager prefab was unpacked) and wires the slider binder.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 13:55:53 +02:00

47 lines
1.4 KiB
C#

using System;
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.
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;
/// Fires whenever the multiplier changes (UI may run before the avatar spawns).
public static event Action<float> Changed;
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();
Changed?.Invoke(v);
}
}
}