hellbound/Assets/Scripts/Game/Settings/GameSettings.cs

59 lines
1.6 KiB
C#
Raw Normal View History

2021-11-26 11:16:25 +03:00
using game;
using UnityEngine;
public static class GameSettings
{
public static LevelSettings Levels { get; private set; }
public static BuffSettings Buffs { get; private set; }
public static bool VibrationIsActive { get; private set; } = true;
public static bool SoundIsActive { get; private set; } = true;
private const string VIBRATION_KEY = "vibration_status";
private const string SOUND_KEY = "sound_status";
public static void Load(ConfGameLevels levelsConfig, ConfGameBuffs buffsConfig)
{
Levels = new LevelSettings(levelsConfig);
Buffs = new BuffSettings(buffsConfig);
LoadPlayerSettings();
}
private static void LoadPlayerSettings()
{
bool settingsExist = PlayerPrefs.HasKey(VIBRATION_KEY)
&& PlayerPrefs.HasKey(SOUND_KEY);
if (settingsExist == false)
{
VibrationIsActive = true;
SoundIsActive = true;
PlayerPrefs.SetInt(VIBRATION_KEY, 1);
PlayerPrefs.SetInt(SOUND_KEY, 1);
}
else
{
VibrationIsActive = PlayerPrefs.GetInt(VIBRATION_KEY) != 0;
SoundIsActive = PlayerPrefs.GetInt(SOUND_KEY) != 0;
}
}
public static void VibrationToggle()
{
VibrationIsActive = !VibrationIsActive;
PlayerPrefs.SetInt(VIBRATION_KEY, VibrationIsActive ? 1 : 0);
}
public static void SoundToggle()
{
SoundIsActive = !SoundIsActive;
PlayerPrefs.SetInt(SOUND_KEY, SoundIsActive ? 1 : 0);
if(SoundIsActive)
Sound.Unmute();
else
Sound.Mute();
}
}