public void PlayOnce(AudioClipLink clipLink, SoundType type, float volumeScale = 1) { clipLink.Load(clip => { if (clip == null) { return; } if (WasPlayedThisFrame(clip)) { return; } GetChannel(type).PlayOneShot(clip, volumeScale); AddToHistory(clip); }); }
public void StopLoop(AudioClipLink clipLink) { clipLink.Load(clip => { if (IsValid(clip) == false) { return; } if (activeLoops.ContainsKey(clip) == false) { return; } activeLoops[clip].Stop(); activeLoops.Remove(clip); }); }
public void PlayOncePitched(AudioClipLink clipLink, float pitch, float volumeScale = 1) { clipLink.Load(clip => { if (clip == null) { return; } if (WasPlayedThisFrame(clip)) { return; } var channel = GetChannel(SoundType.SFX); channel.PlayOneShot(clip, volumeScale); channel.SetPitch(pitch); AddToHistory(clip); }); }
public void PlayLoop(AudioClipLink clipLink, float volumeScale) { clipLink.Load(clip => { if (activeLoops.ContainsKey(clip)) { Debug.LogWarning($"Clip {clip} already playing!"); return; } AudioSource freePlayer = GetFreePlayer(); if (freePlayer == null) { Debug.LogWarning($"Can't get free audio player! Players count: {players.Count}!"); return; } freePlayer.clip = clip; freePlayer.volume = volumeScale; freePlayer.loop = true; freePlayer.Play(); activeLoops.Add(clip, freePlayer); }); }