public static void Play(this AudioSource source, AudioClipInfo info) { source.volume = info.volume; source.pitch = info.pitch; source.loop = info.loop; source.clip = info.audioClip; source.Play(); }
//private void CreateAudioSourcePool() //{ // _audioSources = new AudioSource[GeneralSettingsManager.instance.settings.reserveAudioSources]; // _audioSourceGameObject = new GameObject("_AudioSources"); // _audioSourceGameObject.transform.SetParent(transform); // _audioSourceGameObject.transform.localPosition = Vector3.zero; // for (int i = 0; i < _audioSources.Length; i++) // { // _audioSources[i] = _audioSourceGameObject.AddComponent<AudioSource>(); // _audioSources[i].outputAudioMixerGroup = GeneralSettingsManager.instance.settings.audioMixerGroup; // } //} //private static AudioSource GetNextAudioSource() //{ // foreach (var audioSource in _audioSources) // { // if (audioSource.isPlaying == false) // return audioSource; // } // DevdogLogger.LogWarning("All sources taken, can't play audio clip..."); // return null; //} public AudioClipInfo FindClip(string name) { AudioClipInfo s = Array.Find(sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("Audio clip " + name + " not found."); return(null); } return(s); }
/// <summary> /// Plays an audio clip, only use this for the UI, it is not pooled so performance isn't superb. /// </summary> public static void AudioPlayOneShot(AudioClipInfo clip) { if (clip == null || clip.audioClip == null) { return; } if (Instance == null) { DevdogLogger.LogWarning("AudioManager not found, yet trying to play an audio clip...."); } }
/// <summary> /// Plays an audio clip, only use this for the UI, it is not pooled so performance isn't superb. /// </summary> public static void AudioPlayOneShot(AudioClipInfo clip) { if (clip == null || clip.audioClip == null) { return; } if (instance == null) { DevdogLogger.LogWarning("AudioManager not found, yet trying to play an audio clip...."); } if (_audioQueue.Any(o => o.audioClip == clip.audioClip) == false) { _audioQueue.Enqueue(clip); } }