/// <summary> /// Plays the looping background music. In the game, only one background music can be played at a time. /// When invoked, it will attempt to fade out the previous audio, and fade in the current /// audio requested. /// </summary> /// <example> /// <<playAudio audioName>> /// </example> /// <param name="parameters"></param> private void PlayAudio(string[] parameters) { if (parameters.Length != 1) { return; } string searchTerm = parameters[0].ToUpper(); foreach (var audioItem in audioList) { if (!audioItem.name.ToUpper().Equals(searchTerm)) { continue; } if (audioItem.audioClip == null) { Debug.LogWarning($"playAudio: {audioItem.name} has no clip"); return; } if (_lastAudio != null) { _lastAudio.FadeOut(); } _lastAudio = GetNewAudio(); _lastAudio.FadeIn(audioItem.audioClip, this); _lastAudioName = audioItem.name; return; } Debug.LogWarning($"Audio name not found: {searchTerm}"); }
/// <summary> /// Receives an unused audio to be put back into the pool /// </summary> /// <param name="fadedAudio"></param> public void ReturnAudio(FadedAudio fadedAudio) { Pool.Push(fadedAudio); }