public void Mute(AudioType audioType) { foreach (AudioSource aSource in m_ActiveSound) { AudioManagerClip amc = aSource.GetComponent <AudioManagerClip> (); if (amc != null) { if (amc.audioType == audioType) { amc.Mute(); } } } }
public GameObject Play(string soundName, bool isLoop, float volume, float fadingTime, bool once) { if (m_IsPause) { return(null); } //get the Particle info from dictionary AudioPool audioPool; if (m_AudioDictionary.TryGetValue(soundName, out audioPool)) { //get the list from the pool dictionary List <AudioSource> pool; GameObject spawnObject = null; if (m_AudioPool.TryGetValue(soundName, out pool)) { //search the inactive game object bool found = false; int i = 0; while (!found && i < pool.Count) { GameObject currentGameObject = pool[i].gameObject; if (!currentGameObject.activeInHierarchy) { spawnObject = currentGameObject; found = true; } else { // check it's active but being silent AudioManagerClip amClip = currentGameObject.GetComponent <AudioManagerClip>(); // Don't play at all if it's once and found someone playing if (once) { if (amClip.GetVolume() > 0f || !amClip.GetAudioSource().mute) { return(null); } } if (amClip.GetVolume() <= 0f || amClip.GetAudioSource().mute) { spawnObject = currentGameObject; found = true; } } i++; } //check the game object available if (spawnObject != null) { // find other playing audio if it's only once if (once) { //search the inactive game object bool foundPlaying = false; int itPlaying = 0; while (!foundPlaying && itPlaying < pool.Count) { GameObject currentGameObject = pool[itPlaying].gameObject; // check it's active but being silent AudioManagerClip playingClip = currentGameObject.GetComponent <AudioManagerClip>(); if (playingClip.GetVolume() <= 0f || playingClip.GetAudioSource().mute) { foundPlaying = true; } itPlaying++; } if (foundPlaying) { return(null); } } AudioManagerClip amClip = spawnObject.GetComponent <AudioManagerClip>(); // if it's BGM, check the BGM play and // if it's SFX, check the SFX play if ((amClip.audioType == AudioType.BGM && IsBgmPlay) || (amClip.audioType == AudioType.SFX && IsSfxPlay)) { AudioSource audioSource = spawnObject.GetComponent <AudioSource>(); //set the GameObject active spawnObject.SetActive(true); audioSource.Play(); // check muted if (amClip.audioType == AudioType.BGM) { if (GameSaveManager.Instance.IsBGMPlay()) { amClip.Unmute(); } else { amClip.Mute(); } } if (amClip.audioType == AudioType.SFX) { if (GameSaveManager.Instance.IsSFXPlay()) { amClip.Unmute(); } else { amClip.Mute(); } } if (fadingTime > 0) { amClip.Fade(volume, fadingTime); } else { amClip.SetVolume(volume); } audioSource.loop = isLoop; //add the spawned object to our active list m_ActiveSound.Add(audioSource); } //return the succeedly found object. YAY! return(spawnObject); } else { //create new object for particle pool if (audioPool.isExpanding) { GameObject go = SpawnForPool(audioPool, pool); return(go); } else { Debug.LogWarning("No inactive gameobjects for " + soundName); return(null); } } } else { Debug.LogWarning("No prefabs called " + soundName + " in particle pool dictionary"); return(null); } } else { Debug.LogWarning("No prefabs called " + soundName + " in dictionary"); return(null); } }