コード例 #1
0
 public QueuedMusic(QueuedMusic _queueMusic)
 {
     trackID     = _queueMusic.trackID;
     trackLoop   = _queueMusic.trackLoop;
     fadeTime    = _queueMusic.fadeTime;
     isCrossfade = _queueMusic.isCrossfade;
     doResume    = false;
 }
コード例 #2
0
        public override void _Update()
        {
            float deltaTime = Time.deltaTime;

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

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

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

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

            if (queuedMusic.Count > 0 && delayAudioID < 0)
            {
                if (!audioSource.isPlaying)
                {
                    ClearMusicSample(queuedMusic[0].trackID);
                    queuedMusic.RemoveAt(0);
                    if (queuedMusic.Count > 0)
                    {
                        MusicStorage musicStorage = GetMusic(queuedMusic[0].trackID);
                        if (musicStorage != null && musicStorage.audioClip != null)
                        {
                            int nextTimeSamples = (queuedMusic[0].doResume) ? GetMusicSample(queuedMusic[0].trackID) : 0;

                            SetRelativeVolume(musicStorage.relativeVolume);
                            Play(musicStorage.audioClip, queuedMusic[0].trackLoop, nextTimeSamples);
                        }
                    }
                }
                else if (queuedMusic.Count > 1 && delayAudioID < 0)
                {
                    QueuedMusic nextMusic = queuedMusic[1];
                    if (nextMusic.fadeTime > 0f)
                    {
                        int nextTimeSamples = (nextMusic.doResume) ? GetMusicSample(nextMusic.trackID) : 0;

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

                        if (audioSource.timeSamples > thresholdSamples)
                        {
                            MusicStorage musicStorage = GetMusic(nextMusic.trackID);
                            ClearMusicSample(queuedMusic[0].trackID);
                            queuedMusic.RemoveAt(0);

                            if (nextMusic.isCrossfade)
                            {
                                if (musicCrossfade)
                                {
                                    musicCrossfade.FadeOut(audioSource, nextMusic.fadeTime);
                                }
                                audioSource.clip = musicStorage.audioClip;
                                SetRelativeVolume(musicStorage.relativeVolume);
                                FadeIn(nextMusic.fadeTime, nextMusic.trackLoop, nextTimeSamples);
                            }
                            else
                            {
                                FadeOutThenIn(musicStorage, nextMusic.fadeTime, nextMusic.trackLoop, nextMusic.doResume);
                            }
                        }
                    }
                }
            }

            base._Update();
        }