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
        }
Beispiel #2
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
        }