Esempio n. 1
0
        public static void SaveAudio(float _sfxVol, float _musicVol)
        {
            BinaryFormatter _bf = new BinaryFormatter();
            FileStream _file = File.Create(_audioDataPath);

            AudioData _data = new AudioData();
            _data.SFXVol = _sfxVol;
            _data.MusicVol = _musicVol;

            _bf.Serialize(_file, _data);
            _file.Close();
        }
Esempio n. 2
0
        public static void SaveAudio(float _sfxVol, float _musicVol)
        {
            #if UNITY_WEBPLAYER
            PlayerPrefs.SetFloat(_audioHash + 0, _sfxVol);
            PlayerPrefs.SetFloat(_audioHash + 1, _musicVol);
            #else
            BinaryFormatter _bf = new BinaryFormatter();
            FileStream _file = File.Create(_audioDataPath);

            AudioData _data = new AudioData(_sfxVol, _musicVol);

            _bf.Serialize(_file, _data);
            _file.Close();
            #endif
        }
        /// <summary>
        /// Saves the audio settings for this game
        /// </summary>
        /// <param name="data">The data to be saved</param>
		public static void SaveAudio(AudioData data)
		{
#if UNITY_WEBPLAYER
            // Set appropriate hash values
			PlayerPrefs.SetFloat(audioHash + 0, data.SFXVol);
			PlayerPrefs.SetFloat(audioHash + 1, data.MusicVol);
            PlayerPrefs.SetFloat(audioHash + 2, data.VoiceVol);
#else
            // Create a new save file
			BinaryFormatter bf = new BinaryFormatter();
			FileStream file = File.Create(audioDataPath);

			bf.Serialize(file, data);
			file.Close();
#endif
		}
Esempio n. 4
0
        /// <summary>
        /// Loads the audio data for this game
        /// </summary>
        /// <returns>The audio settings saved to disk or player prefs</returns>
		public static AudioData LoadAudio()
		{
            // Get a default audiodata in case none exists
			AudioData data = new AudioData();
#if UNITY_WEBPLAYER
            // If there is data related to audio, get those values
			if(PlayerPrefs.HasKey(audioHash + 0))
			{
				data.SFXVol = PlayerPrefs.GetFloat(audioHash + 0);
				data.MusicVol = PlayerPrefs.GetFloat(audioHash + 1);
                data.VoiceVol = PlayerPrefs.GetFloat(audioHash + 2);
			}
            // Otherwise save the default data
			else
			{
				SaveManager.SaveAudio(new AudioData());
			}
			return data;
#else
            // If a file exists
            if (File.Exists(audioDataPath))
			{
                // Open the file and get all the data from the file to load
				BinaryFormatter bf = new BinaryFormatter();
				FileStream file = File.Open(audioDataPath, FileMode.Open);

				data = (AudioData)bf.Deserialize(file);

				file.Close();

				return data;
			}
            // No file exists, so save the default data
			else
			{
				SaveManager.SaveAudio(data);
				return data;
			}
#endif
		}
Esempio n. 5
0
        public static AudioData LoadAudio()
        {
            AudioData _data = new AudioData();
            #if UNITY_WEBPLAYER

            if(PlayerPrefs.HasKey(_audioHash + 0))
            {
                _data.SFXVol = PlayerPrefs.GetFloat(_audioHash + 0);
                _data.MusicVol = PlayerPrefs.GetFloat(_audioHash + 1);
            }
            else
            {
                SaveManager.SaveAudio(1f, 1f);
            }
            return _data;
            #else

            if(File.Exists(_audioDataPath))
            {
                BinaryFormatter _bf = new BinaryFormatter();
                FileStream _file = File.Open(_audioDataPath, FileMode.Open);

                _data = (AudioData)_bf.Deserialize(_file);

                _file.Close();

                return _data;
            }
            else
            {
                AudioData _newData = new AudioData();
                SaveManager.SaveAudio(1f, 1f);
                return _newData;
            }
            #endif
        }