Ejemplo n.º 1
0
        public AudioUnit Play(string audioUnitPrefixName = null)
        {
            // Initialization
            AudioUnit audioSource = AudioPool.GetFromPool();

            // Setup Paramaters
            audioSource.playOnAwake           = false;
            audioSource.loop                  = loopType == AudioLoopType.Normal;
            audioSource.loopType              = loopType;
            audioSource.timeBetweenLoop       = timeBetweenLoop;
            audioSource.outputAudioMixerGroup = mixerGroup;

            audioSource.clip          = isUsingClips ? clips.Random() : clip;
            audioSource.clips         = isUsingClips ? clips : null;
            audioSource.pitch         = isPitchModified ? 1f - pitchMaxVariation.RandomValue : 1f;
            audioSource.isGoingToStop = autoDestroy != AudioStopType.No;

            if (audioSource.clip == null)
            {
                Debug.LogWarning($"An audio unit is created without a clip.");

                AudioPool.ReturnToPool(audioSource);
            }
            else
            {
                if (audioUnitPrefixName != null)
                {
                    audioSource.gameObject.name = audioUnitPrefixName;
                }

                audioSource.gameObject.name += audioSource.clip.name;

                // Auto Destroy
                switch (autoDestroy)
                {
                case AudioStopType.StopAfterDuration:
                    audioSource.duration = multiplier;
                    break;

                case AudioStopType.StopAfterPlays:
                    audioSource.duration = audioSource.clip.length * (multiplier - 1);
                    break;
                }

                // Play Sound
                audioSource.Play();
            }

            return(audioSource);
        }
Ejemplo n.º 2
0
        private IEnumerator ReturnToPoolAfterDuration(float duration)
        {
            yield return(new WaitForSeconds(duration));

            AudioPool.ReturnToPool(this);
        }
Ejemplo n.º 3
0
 public void StopAndReturnToPool()
 {
     audioSource.Stop();
     AudioPool.ReturnToPool(this);
 }
Ejemplo n.º 4
0
        private IEnumerator WaitBeforeReturningToPool()
        {
            yield return(new WaitForSeconds(audioSource.clip.length));

            AudioPool.ReturnToPool(this);
        }