Esempio n. 1
0
        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);
            });
        }
Esempio n. 2
0
            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);
                });
            }
Esempio n. 3
0
        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);
            });
        }
Esempio n. 4
0
            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);
                });
            }