Esempio n. 1
0
    /// <summary>Switches the Edition of the track to be played.</summary>
    /// <param name="DesiredEdition">The desired Edition to switch to.</param>
    /// <param name="FadeOverride">The duration of the crossfade effect.</param>
    public void SwitchEdition(Edition DesiredEdition, float FadeOverride)
    {
        if (CurrentEdition != DesiredEdition)
        {
            AudioObject NewEditionAudio = null;

            //Fade Length
            float OriginalFade = DesiredEdition.FadeLength;
            DesiredEdition.FadeLength = FadeOverride;

            //If there is already an Edition playing
            if (!CurrentEdition.IsNull)
            {
                //Plays transition
                DesiredEdition.PlayTransition();

                //Retains playback time
                if (DesiredEdition.KeepPlaybackTime)
                {
                    NewEditionAudio = DesiredEdition.Play(CurrentEdition.Audio.Source.time);
                    ActiveAudio.Add(NewEditionAudio);
                }

                //Stops previous Edition
                if (DesiredEdition.FadeLength > 0)
                {
                    MusicManager.Main.FadeAudio(CurrentEdition.Audio, DesiredEdition.FadeLength, 0f); ActiveAudio.Remove(CurrentEdition.Audio);
                }
                else
                {
                    Stop(CurrentEdition.Audio);
                }
            }

            //Starts Edition without retaining playback time
            if (!DesiredEdition.KeepPlaybackTime || CurrentEdition.IsNull)
            {
                NewEditionAudio = DesiredEdition.Play();
                ActiveAudio.Add(NewEditionAudio);
            }

            //Sequences end if its a one shot
            if (IsOneShot && NewEditionAudio != null)
            {
                NewEditionAudio.Source.loop = false;
                MusicManager.Main.SequenceEnd(this, NewEditionAudio.length - NewEditionAudio.Source.time);
            }

            CurrentEdition            = DesiredEdition;
            CurrentEdition.FadeLength = OriginalFade;
        }
    }