Example #1
0
 public QueuedSoundtrack(QueuedSoundtrack _queuedSoundtrack)
 {
     trackID     = _queuedSoundtrack.trackID;
     trackLoop   = _queuedSoundtrack.trackLoop;
     fadeTime    = _queuedSoundtrack.fadeTime;
     isCrossfade = _queuedSoundtrack.isCrossfade;
     doResume    = false;
 }
Example #2
0
 public QueuedSoundtrack(QueuedSoundtrack _queuedSoundtrack)
 {
     trackID            = _queuedSoundtrack.trackID;
     trackLoop          = _queuedSoundtrack.trackLoop;
     fadeTime           = _queuedSoundtrack.fadeTime;
     isCrossfade        = _queuedSoundtrack.isCrossfade;
     doResume           = false;
     newTimeSamples     = 0;
     loopingOverlapTime = _queuedSoundtrack.loopingOverlapTime;
 }
Example #3
0
 public QueuedSoundtrack(QueuedSoundtrack _queuedSoundtrack)
 {
     trackID              = _queuedSoundtrack.trackID;
     trackLoop            = _queuedSoundtrack.trackLoop;
     fadeTime             = _queuedSoundtrack.fadeTime;
     isCrossfade          = _queuedSoundtrack.isCrossfade;
     doResume             = false;
     newTimeSamples       = 0;
     crossfadeWhenLooping = _queuedSoundtrack.crossfadeWhenLooping;
 }
Example #4
0
        public override void _Update()
        {
            float deltaTime = Time.deltaTime;

            if (KickStarter.stateHandler.gameState == GameState.Paused)
            {
                if (soundType == SoundType.Music && KickStarter.settingsManager.playMusicWhilePaused)
                {
                    deltaTime = Time.fixedDeltaTime;
                }
                else
                {
                    return;
                }
            }

            if (crossfade)
            {
                crossfade._Update();
            }

            if (delayAudioID >= 0 && delayTime > 0f)
            {
                delayTime -= deltaTime;

                if (delayTime <= 0f)
                {
                    AfterDelay();
                }
                base._Update();
            }

            if (queuedSoundtrack.Count > 0 && delayAudioID < 0)
            {
                if (!IsPlayingThisFrame)
                {
                    ClearSoundtrackSample(queuedSoundtrack[0].trackID);
                    queuedSoundtrack.RemoveAt(0);

                    if (queuedSoundtrack.Count > 0)
                    {
                        MusicStorage musicStorage = GetSoundtrack(queuedSoundtrack[0].trackID);
                        if (musicStorage != null && musicStorage.audioClip != null)
                        {
                            int nextTimeSamples = (queuedSoundtrack[0].doResume) ? GetSoundtrackSample(queuedSoundtrack[0].trackID) : queuedSoundtrack[0].newTimeSamples;

                            SetRelativeVolume(musicStorage.relativeVolume);
                            Play(musicStorage.audioClip, queuedSoundtrack[0].trackLoop, nextTimeSamples);
                        }
                    }
                }
                else if (queuedSoundtrack.Count > 1 && delayAudioID < 0)
                {
                    QueuedSoundtrack nextSoundtrack = queuedSoundtrack[1];
                    if (nextSoundtrack.fadeTime > 0f)
                    {
                        int nextTimeSamples = (nextSoundtrack.doResume) ? GetSoundtrackSample(nextSoundtrack.trackID) : nextSoundtrack.newTimeSamples;

                        // Need to pre-empt next track
                        float thresholdProportion = (audioSource.clip.length - nextSoundtrack.fadeTime) / audioSource.clip.length;
                        int   thresholdSamples    = (int)(thresholdProportion * (float)audioSource.clip.samples);

                        if (audioSource.timeSamples > thresholdSamples)
                        {
                            MusicStorage musicStorage = GetSoundtrack(nextSoundtrack.trackID);
                            ClearSoundtrackSample(queuedSoundtrack[0].trackID);
                            queuedSoundtrack.RemoveAt(0);

                            if (nextSoundtrack.isCrossfade)
                            {
                                if (crossfade)
                                {
                                    crossfade.FadeOut(audioSource, nextSoundtrack.fadeTime);
                                }
                                audioSource.clip = musicStorage.audioClip;
                                SetRelativeVolume(musicStorage.relativeVolume);
                                HandleFadeIn(nextSoundtrack.fadeTime, nextSoundtrack.trackLoop, nextTimeSamples);
                            }
                            else
                            {
                                FadeOutThenIn(musicStorage, nextSoundtrack.fadeTime, nextSoundtrack.trackLoop, nextSoundtrack.doResume, nextSoundtrack.newTimeSamples);
                            }
                        }
                    }
                }
            }

            base._Update();

            if (!KickStarter.stateHandler.IsPaused() || playWhilePaused)
            {
                if (!audioSource.isPlaying && wasPlayingLastFrame)
                {
                    KickStarter.eventManager.Call_OnStopSoundtrack(IsMusic, 0f);
                }
                wasPlayingLastFrame = audioSource.isPlaying;
            }
        }