Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- public class SettingsSaveData {
- public static SettingsSaveData CurrentAppliedSettings {
- get {
- return new SettingsSaveData (AudioListener.volume, SoundManager.MusicVolume, SoundManager.IsMuted, QualitySettings.vSyncCount > 0,
- Screen.currentResolution.width, Screen.currentResolution.height, Screen.fullScreen);
- }
- }
- public static SettingsSaveData DefaultSettings {
- get {
- var resolutions = Screen.resolutions;
- var topResolution = resolutions[resolutions.Length -1];
- return new SettingsSaveData (1, 1, false, true, topResolution.width, topResolution.height, true);
- }
- }
- // ============================= CONSTRUCTION =============================
- private readonly float masterVolume;
- private readonly float musicVolume;
- private readonly bool muted;
- private readonly bool vSync;
- private readonly int resolutionWidth;
- private readonly int resolutionHeight;
- private readonly bool fullScreen;
- public SettingsSaveData (float masterVolume, float musicVolume, bool muted, bool vSync, int resolutionWidth, int resolutionHeight, bool fullScreen) {
- this.masterVolume = Mathf.Clamp (masterVolume, 0, 1);
- this.musicVolume = Mathf.Clamp (musicVolume, 0, 1);
- this.muted = muted;
- this.vSync = vSync;
- this.resolutionWidth = resolutionWidth;
- this.resolutionHeight = resolutionHeight;
- this.fullScreen = fullScreen;
- }
- // ============================= READ / WRITE =============================
- public static SettingsSaveData ReadFrom (BinaryReader reader) {
- var masterVolume = reader.ReadSingle ();
- var musicVolume = reader.ReadSingle ();
- var muted = reader.ReadBoolean ();
- var vSync = reader.ReadBoolean ();
- var resolutionWidth = reader.ReadInt32 ();
- var resolutionHeight = reader.ReadInt32 ();
- var fullScreen = reader.ReadBoolean ();
- return new SettingsSaveData (masterVolume, musicVolume, muted, vSync, resolutionWidth, resolutionHeight, fullScreen);
- }
- public void WriteTo (BinaryWriter writer) {
- writer.Write (masterVolume);
- writer.Write (musicVolume);
- writer.Write (muted);
- writer.Write (vSync);
- writer.Write (resolutionWidth);
- writer.Write (resolutionHeight);
- writer.Write (fullScreen);
- }
- // ============================= APPLICATION =============================
- public void Apply () {
- AudioListener.volume = masterVolume;
- SoundManager.SetMusicVolume (musicVolume);
- SoundManager.SetMuted (muted);
- QualitySettings.vSyncCount = vSync ? 1 : 0;
- Screen.SetResolution (resolutionWidth, resolutionHeight, fullScreen);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment