public static void Aplysettings(GameSettinngs gameSettinngs) { try { Screen.SetResolution(Resolutions[gameSettinngs.resolutionIndex].width, Resolutions[gameSettinngs.resolutionIndex].height, Screen.fullScreen); } catch (Exception) { gameSettinngs.resolutionIndex = 0; Screen.SetResolution(Resolutions[gameSettinngs.resolutionIndex].width, Resolutions[gameSettinngs.resolutionIndex].height, Screen.fullScreen); } Screen.fullScreen = gameSettinngs.fullScreen; QualitySettings.masterTextureLimit = gameSettinngs.quality; QualitySettings.antiAliasing = (int)Mathf.Pow(2, gameSettinngs.antialiasing); QualitySettings.vSyncCount = gameSettinngs.vSync; GameSettinngs = gameSettinngs; }
public static void LoadSettings() { GameSettinngs gameSettinngs; if (File.Exists(Application.persistentDataPath + "/gamesettings.json")) { gameSettinngs = JsonUtility.FromJson <GameSettinngs>(File.ReadAllText(Application.persistentDataPath + "/gamesettings.json")); } else { gameSettinngs = new GameSettinngs { mouseSensitivity = 0.5f, audioVolume = 1f }; SaveSettings(gameSettinngs); } Aplysettings(gameSettinngs); }
void OnEnable() { _gameSettinngs = SettingManager.GameSettinngs ?? new GameSettinngs(); if (FullscreenToggle && ResolutionDropdown && QualityDropdown && AntialiasingDropdown && VSyncDropdown && AudioVolumeSlider && MouseSensitivitySlider && ApplyButton) { FullscreenToggle.onValueChanged.AddListener(delegate { OnFullscreenToggle(); }); ResolutionDropdown.onValueChanged.AddListener(delegate { OnResolutionChange(); }); QualityDropdown.onValueChanged.AddListener(delegate { OnQualityChange(); }); AntialiasingDropdown.onValueChanged.AddListener(delegate { OnAntialiasingChange(); }); VSyncDropdown.onValueChanged.AddListener(delegate { OnVsyncChange(); }); AudioVolumeSlider.onValueChanged.AddListener(delegate { OnAudioVolumeChange(); }); MouseSensitivitySlider.onValueChanged.AddListener(delegate { OnSensitivitChange(); }); ApplyButton.onClick.AddListener(OnApplyButtonClick); } _resolutions = SettingManager.Resolutions; foreach (var resolution in _resolutions) { ResolutionDropdown.options.Add(new Dropdown.OptionData(resolution.ToString())); } LoadInputs(); }
public static void SaveSettings(GameSettinngs gameSettinngs) { var jsonData = JsonUtility.ToJson(gameSettinngs, true); File.WriteAllText(Application.persistentDataPath + "/gamesettings.json", jsonData); }