//As implied, stops all sounds that are currently playing. public void StopAllSound() { if (m_arAttachedAudioSource != null) { foreach (AudioSource audioSource in m_arAttachedAudioSource) { if (audioSource != null && audioSource.isPlaying) { CAudioSystem.StopSound(audioSource); } } m_arAttachedAudioSource.Clear(); } }
//If there is relevant information set, this function will fade out sounds over time, then stop them. public void FadeOut() { if (m_fFadeOutTimeList.Length > 0 && m_arAttachedAudioSource != null) { for (int i = 0; i < m_arAttachedAudioSource.Count; i++) { if (m_arAttachedAudioSource[i] != null && m_arAttachedAudioSource[i].isPlaying && i < m_fFadeOutTimeList.Length) { CAudioSystem.FadeOut(m_arAttachedAudioSource[i], m_fFadeOutTimeList[i]); } else if (m_arAttachedAudioSource[i] != null && m_arAttachedAudioSource[i].isPlaying) { //If the correct fadeout information cannot be found, simply stop the sound. CAudioSystem.StopSound(m_arAttachedAudioSource[i]); } } m_arAttachedAudioSource.Clear(); } else { StopAllSound(); } }