public void RemoveSource(AudioPoolSource src) { if (_pool.Contains(src)) { _pool.Remove(src); // Debug.Log("Added to the pool. Pool items: " + _pool.Count); } }
public void PutSource(AudioPoolSource src) { if (!_pool.Contains(src)) { _pool.Add(src); // Debug.Log("Added to the pool. Pool items: " + _pool.Count); } }
public AudioPoolSource PlayAll(float msDelay, Transform parent = null) { AudioPoolSource src = AudioController.Instance.GetSource(); for (int i = 0; i < clips.Count; i++) { src.PlayAfter((msDelay / clips.Count) * i, clips[i], pitch, volume, spatialBlend, loop, music, parent); } return(src); }
private IEnumerator PlaySound(AudioObject audioToPlay, int tempIndex) { PlayerController.Instance.SetPlayerLockInPlace(true); AudioPoolSource aps = audioToPlay.Play(); yield return(null); while (aps.isPlaying) { yield return(null); } PlayerController.Instance.SetPlayerLockInPlace(false); if (cutsceneSequence[tempIndex].waitUntilActionFinishes) { moveToNextAction = true; } }
public AudioPoolSource GetSource() { AudioPoolSource output = null; if (_pool.Count > 0) // grab a source and return it { output = _pool[0]; _pool.RemoveAt(0); // Debug.Log("Removed from the pool. Pool items: " + _pool.Count); return(output); } else { // Debug.Log("Pool is empty, adding an audio source GameObject"); GameObject go = new GameObject("Audio Source"); go.tag = "Audio"; return(go.AddComponent <AudioPoolSource>()); } }
// returns the name of the last track that played or null if there wasn't one public string StopMusic(string nextTrack = null) { string lastTrack = null; foreach (GameObject go in GameObject.FindGameObjectsWithTag("Audio")) { AudioPoolSource aps = go.GetComponent <AudioPoolSource>(); if (nextTrack == aps.clipName && aps.isPlaying) { lastTrack = nextTrack; continue; } if (aps.playsMusic && aps.isPlaying) { aps.Stop(); return(aps.clipName); } } return(lastTrack); }