Kursach_StealthAction/Assets/Scripts/GameSettings.cs
2026-10-19 20:14:24 +03:00

52 lines
2.0 KiB
C#

using UnityEngine;
public static class GameSettings
{
public const string KeyMasterVolume = "Settings_MasterVolume";
public const string KeyIsMuted = "Settings_IsMuted";
public const string KeyQualityLevel = "Settings_QualityLevel";
public const string KeyFullscreen = "Settings_Fullscreen";
public const string KeyResolutionWidth = "Settings_ResolutionWidth";
public const string KeyResolutionHeight = "Settings_ResolutionHeight";
public const string KeyResolutionRefresh = "Settings_ResolutionRefresh";
public const string KeyMouseSensitivity = "Settings_MouseSensitivity";
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void ApplyAllSettings()
{
// 1. Звук
float volume = PlayerPrefs.GetFloat(KeyMasterVolume, 1.0f);
bool isMuted = PlayerPrefs.GetInt(KeyIsMuted, 0) == 1;
AudioListener.volume = isMuted ? 0f : Mathf.Clamp01(volume);
// 2. Качество графики
if (PlayerPrefs.HasKey(KeyQualityLevel))
{
int quality = PlayerPrefs.GetInt(KeyQualityLevel);
if (quality >= 0 && quality < QualitySettings.names.Length)
{
QualitySettings.SetQualityLevel(quality, true);
}
}
// 3. Полноэкранный режим и разрешение
bool isFullscreen = PlayerPrefs.GetInt(KeyFullscreen, Screen.fullScreen ? 1 : 0) == 1;
int width = PlayerPrefs.GetInt(KeyResolutionWidth, Screen.currentResolution.width);
int height = PlayerPrefs.GetInt(KeyResolutionHeight, Screen.currentResolution.height);
if (width > 0 && height > 0)
{
Screen.SetResolution(width, height, isFullscreen ? FullScreenMode.FullScreenWindow : FullScreenMode.Windowed);
}
else
{
Screen.fullScreen = isFullscreen;
}
}
public static float GetMouseSensitivity()
{
return PlayerPrefs.GetFloat(KeyMouseSensitivity, 1.0f);
}
}