Exemplo n.º 1
0
        /// <summary>
        /// Repeatedly trigger the one-off container based on the loop time.
        /// </summary>
        private IEnumerator PlayLoopingOneOffContainerCoroutine(ActiveEvent activeEvent)
        {
            int?currentIndex = null;

            while (!activeEvent.StopRequested)
            {
                UPlayable currentPlayable = null;

                if (!this.IsSimultaneous)
                {
                    currentIndex    = this.GenerateNextClipIndex(currentIndex);
                    currentPlayable = this.sounds[currentIndex.Value];
                }

                // Start coroutine (don't yield return) so that the wait time is accurate, since length includes delay.
                StartCoroutine(PlayOneOffContainerCoroutine(activeEvent, currentPlayable));

                float eventLoopTime = loopTime;

                // Protect against containers looping every frame by defaulting to the length of the audio clip.
                if (eventLoopTime == 0)
                {
                    if (!this.IsSimultaneous)
                    {
                        eventLoopTime = currentPlayable.GetLength();
                    }
                    else
                    {
                        eventLoopTime = this.GetLength();
                    }
                }

                yield return(new WaitForSeconds(eventLoopTime));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Coroutine for "continuous" containers that alternates between two sources to crossfade clips for continuous playlist looping.
        /// </summary>
        /// <returns>The coroutine.</returns>
        private IEnumerator PlayContinuousContainerCoroutine(ActiveEvent activeEvent)
        {
            float waitTime     = 0;
            int?  currentIndex = null;

            while (!activeEvent.StopRequested)
            {
                currentIndex = this.GenerateNextClipIndex(currentIndex);
                UPlayable tempClip = this.sounds[currentIndex.Value];

                if (tempClip.IsEmpty())
                {
                    Debug.LogErrorFormat(this, "Sound clip in event \"{0}\" is null!", activeEvent.audioEvent.name);
                    waitTime = 0;
                }
                else
                {
                    if (!activeEvent.IsPlayingSecondary)
                    {
                        activeEvent.volDest    = activeEvent.audioEvent.volumeCenter;
                        activeEvent.altVolDest = 0f;
                    }
                    else
                    {
                        activeEvent.volDest    = 0f;
                        activeEvent.altVolDest = activeEvent.audioEvent.volumeCenter;
                    }

                    activeEvent.CurrentAudioSource.volume = 0f;
                    activeEvent.currentFade = crossfadeTime;
                    yield return(PlayClipCoroutine(tempClip, activeEvent));

                    waitTime = tempClip.GetLength() - crossfadeTime;
                }

                // Alternate playing on primary / secondary audio sources.
                activeEvent.IsPlayingSecondary = !activeEvent.IsPlayingSecondary;

                yield return(new WaitForSeconds(waitTime));
            }
        }