// !! CALL THIS TO SWITCH FROM PROLOGUE MUSIC TO MAIN MENU MUSIC !!
    public void StartMainMenuMusic()
    {
        if (isExitingPrologue)
        {
            return;
        }

        isExitingPrologue = true;

        float curPlayheadTime = prologueMusic.GetCurrentTime();
        int   nextBar         = Mathf.CeilToInt(curPlayheadTime / SECONDS_PER_BAR);
        float nextBarTime     = nextBar * SECONDS_PER_BAR;

        StartCoroutine(MenuMusicTransition(nextBarTime - curPlayheadTime));
    }
Пример #2
0
    /// <summary>
    /// Starts a transition (instantaneous if withFading = true) to the next track with aligned tempo and bars.
    /// </summary>
    /// <param name="withFading">Whether the transition involves fading.</param>
    /// <param name="track">The track to play. Setting track will force a transition to start.</param>
    /// <returns>returns -1 if no transition happened, 0 if it was instant, or the delay before the transition will start.</returns>
    public float StartTransition(bool withFading, CustomMusicLoopController track = null)
    {
        if (track != null)
        {
            //Attempt to forcibly set the next track
            if (!SetNextTrack(track, true) || isInTransition || track != nextMusic)
            {
                // failed to set a new track, abort
                return(-1);
            }
        }

        if (nextMusic == null)
        {
            return(-1);
        }
        else if (curMusic == null)
        {
            curMusic  = nextMusic;
            nextMusic = null;
            curMusic.StartTrack();
            return(0);
        }
        else if (nextMusic == curMusic)
        {
            nextMusic = null;
            return(-1);
        }

        if (!withFading)
        {
            if (nextMusic != null)
            {
                if (isInTransition)
                {
                    StopTransition();
                }

                curMusic.StopTrack();         //wait for main menu to start before stopping prologue
                curMusic.SetVolume(volume);
                Destroy(curMusic.gameObject); // not needed anymore

                curMusic  = nextMusic;
                nextMusic = null;

                curMusic.StartTrack();
                return(0);
            }
            return(-1);
        }

        if (isInTransition)
        {
            return(-1);
        }

        isInTransition = true;

        float curPlayheadTime = curMusic.GetCurrentTime();
        int   nextBar         = Mathf.CeilToInt(curPlayheadTime / SECONDS_PER_BAR);
        float nextBarTime     = nextBar * SECONDS_PER_BAR;

        transition = StartCoroutine(MusicTransition(nextBarTime - curPlayheadTime));
        return(nextBarTime - curPlayheadTime);
    }