Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- using UnityEngine.UI;
- public class SettingsController : MonoBehaviour {
- public const string MUTE_INT = "mute";
- public const string TEXT_F = "text";
- public GameObject sound;
- public Text text;
- public Image image;
- public void RestorePreferences()
- {
- SetMuted(GetIsMuted());
- SetText(GetIsText());
- }
- public void SetText(bool texted)
- {
- PlayerPrefs.SetString(TEXT_F, texted ? : 0);
- }
- public void SetMuted(bool muted)
- {
- PlayerPrefs.SetInt(MUTE_INT, muted ? 1 : 0);
- AudioListener.pause = muted;
- if (DEBUG_ON)
- Debug.LogFormat("SetMuted({0})", muted);
- }
- public bool GetIsMuted()
- {
- return PlayerPrefs.GetInt(MUTE_INT, 0) == 1;
- }
- public bool GetIsText()
- {
- return PlayerPrefs.GetInt(MUTE_INT, 0) == 1;
- }
- public void Toggle_Changed(bool newValue)
- {
- sound.SetActive(newValue);
- }
- public void DoSoundToggle()
- {
- if (AudioListener.volume > 0)
- {
- SoundOn();
- }
- else
- {
- SoundOff();
- }
- }
- private void SoundOff()
- {
- AudioListener.volume = 1;
- }
- private void SoundOn()
- {
- AudioListener.volume = 0;
- }
- /* public void SetVolume(float volume)
- {
- volume = Mathf.Clamp(volume, 0, 1);
- PlayerPrefs.SetFloat(VOLUME_F, volume);
- AudioListener.volume = volume;
- }
- public float GetVolume()
- {
- return Mathf.Clamp(PlayerPrefs.GetFloat(VOLUME_F, 1), 0, 1);
- }*/
- [System.Serializable]
- public class Position
- {
- private bool DEBUG_ON = true;
- }
- public void Save()
- {
- Position position = new Position();
- if (Directory.Exists(Application.dataPath + "/saves"))
- {
- Directory.CreateDirectory(Application.dataPath + "/saves");
- FileStream fs = new FileStream(Application.dataPath + "/saves/save.sv", FileMode.Create);
- BinaryFormatter formatter = new BinaryFormatter();
- formatter.Serialize(fs, formatter);
- fs.Close();
- }
- }
- public void Load()
- {
- if (Application.isPlaying)
- {
- if (File.Exists(Application.dataPath + "/saves/save.sv"))
- {
- FileStream fs = new FileStream(Application.dataPath + "/saves/save.sv", FileMode.Open);
- BinaryFormatter formatter = new BinaryFormatter();
- try
- {
- Position position = (Position)formatter.Deserialize(fs);
- }
- catch (System.Exception e)
- {
- Debug.Log(e.Message);
- }
- finally
- {
- fs.Close();
- }
- }
- else
- {
- Application.LoadLevel(0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement