//--------------------------------------------------------------------- public void play(AudioSource audio_src) { bool is_silence = false; if (PlayerPrefs.HasKey(SoundMgr.SoundIsSilenceKey)) { bool.TryParse(PlayerPrefs.GetString(SoundMgr.SoundIsSilenceKey), out is_silence); } // 同名最多10个 int count = 0; foreach (var i in mListAudioPlaying) { if (audio_src.name == i.name) { count++; if (count >= 10) { break; } } } float music_value = 0f; if (!PlayerPrefs.HasKey(SoundMgr.SoundKey)) { music_value = SoundMgr.DefaultSoundVolume; } else { music_value = PlayerPrefs.GetFloat(SoundMgr.SoundKey); } if (count < 10) { if (is_silence) { music_value = 0; } audio_src.volume = music_value; audio_src.loop = false; audio_src.Play(); mListAudioPlaying.Add(audio_src); } else { audio_src.Stop(); mSoundMgr.FreeAudioSource(audio_src); } }
//--------------------------------------------------------------------- public void play(AudioSource audio_src) { bool is_silence = false; if (PlayerPrefs.HasKey(SoundMgr.SoundIsSilenceKey)) { bool.TryParse(PlayerPrefs.GetString(SoundMgr.SoundIsSilenceKey), out is_silence); } if (mMapAudioPlaying.ContainsKey(audio_src.name)) { // 同名替换 mMapAudioPlaying[audio_src.name].Stop(); mMapAudioPlaying[audio_src.name].Play(); audio_src.Stop(); mSoundMgr.FreeAudioSource(audio_src); } else { // 不同名重叠 float music_value = 0f; if (!PlayerPrefs.HasKey(SoundMgr.SoundKey)) { music_value = SoundMgr.DefaultSoundVolume; } else { music_value = PlayerPrefs.GetFloat(SoundMgr.SoundKey); } if (is_silence) { music_value = 0; } audio_src.volume = music_value; audio_src.loop = false; audio_src.Play(); mMapAudioPlaying[audio_src.name] = audio_src; } }
//--------------------------------------------------------------------- public void destroy() { foreach (var i in mListAudioPlaying) { if (i == null) { continue; } i.Stop(); mSoundMgr.FreeAudioSource(i); } mListAudioPlaying.Clear(); }
//--------------------------------------------------------------------- public void play(AudioSource audio_src) { bool is_silence = false; if (PlayerPrefs.HasKey(SoundMgr.SoundIsSilenceKey)) { bool.TryParse(PlayerPrefs.GetString(SoundMgr.SoundIsSilenceKey), out is_silence); } if (mAudioPlaying == null) { float music_value = 0f; if (!PlayerPrefs.HasKey(SoundMgr.SoundKey)) { music_value = SoundMgr.DefaultSoundVolume; } else { music_value = PlayerPrefs.GetFloat(SoundMgr.SoundKey); } if (is_silence) { music_value = 0; } audio_src.volume = music_value; audio_src.loop = false; audio_src.Play(); mAudioPlaying = audio_src; } else { mSoundMgr.FreeAudioSource(audio_src); } }
//--------------------------------------------------------------------- public void FreeAudioSource(AudioSource audio_src) { SoundMgr.FreeAudioSource(audio_src); }