private void OnGUI() { GUILayout.BeginHorizontal(); if (GUILayout.Button("Play 2D Sound")) { AudioPool.Play2D(ClipCollection.GetClip(), pitchVariance: PitchVariance); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Play 3D Sound")) { AudioPool.Play3D(ClipCollection.GetClip(), transform.position, pitchVariance: PitchVariance); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical("Box"); GUILayout.Label("Pitch Variance: " + PitchVariance); PitchVariance = GUILayout.HorizontalSlider(PitchVariance, 0f, 1f); GUILayout.EndVertical(); GUILayout.EndVertical(); }
public void PlayCollection(AudioClipCollection clipCollection, float volume = 1f) { if (volume <= 0f) { Debug.LogError("[PersistentBackgroundMusic] Volume must be higher than 0f."); return; } _currentSource.loop = false; ClipCollection = clipCollection; var clip = clipCollection.GetClip(); if (CrossFade) { CrossFadeClip(clip, volume); return; } _currentSource.clip = clip; if (FadeIn) { _currentSource.FadeIn(FadeInDuration, volume); } else { _currentSource.volume = volume; _currentSource.Play(); } }
private void OnSourceStop(AudioSource source) { if (!ClipCollection.IsEmpty) { source.clip = ClipCollection.GetClip(); if (FadeIn && FadeOut || AlwaysFadeIn) { source.FadeIn(FadeInDuration, source.volume); } else { source.Play(); } } }
/// <summary> /// Plays a collection of AudioClips /// </summary> /// <param name="clipCollection">collection to play</param> /// <param name="volume">volume to play the clips at.</param> public void PlayCollection(AudioClipCollection clipCollection, float volume = 1f) { if (volume <= 0f) { Debug.LogError("[PersistentBackgroundMusic] Volume must be higher than 0f."); return; } _currentSource.loop = Looping; ClipCollection = clipCollection; var clip = clipCollection.GetClip(); PlayClip(clip, volume); }
/// <summary> /// Immediately starts the next clip, respecting fade settings. /// </summary> public void StartNextClip() { PlayClip(ClipCollection.GetClip(), _primarySource.volume); }