コード例 #1
0
 public void Play(MusicStackEntry musicStackEntry)
 {
     Clear();
     musicStack.Add(musicStackEntry);
     fadeSpeed  = 0;
     fadeVolume = 0;
 }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        var entry     = musicStackEntryCurrent;
        var entryPrev = musicStackEntryPrev;

        var entryDone = (
            (audioSourceIntro.clip != null) &&
            (audioSourceLoop.clip == null) &&
            !audioSourceIntro.isPlaying
            );

        if (entryDone)
        {
            if (entry.fadeInAfter)
            {
                FadeIn();
            }
            musicStack.Remove(entry);
            audioSourceIntro.Stop();
            audioSourceLoop.Stop();
            audioSourceIntro.clip = null;
            audioSourceLoop.clip  = null;
            return;
        }

        mixer.SetFloat("Music Pitch", tempo);
        mixer.SetFloat("Music Pitch Shift", 1F / tempo);
        mixer.SetFloat("Music Volume", fadeVolume);
        fadeVolume = Mathf.Max(
            -40,
            Mathf.Min(
                0,
                fadeVolume + fadeSpeed
                )
            );

        if (entry != null)
        {
            mixer.SetFloat("SFX Volume", entry.disableSfx ? -40 : 0);
        }

        if (entry == entryPrev)
        {
            return;
        }
        if (entry == null)
        {
            return;
        }
        musicStackEntryPrev = entry;

        entry.Init();

        audioSourceIntro.Stop();
        audioSourceLoop.Stop();
        audioSourceIntro.clip = null;
        audioSourceLoop.clip  = null;

        audioSourceIntro.outputAudioMixerGroup = mixerGroup;
        audioSourceLoop.outputAudioMixerGroup  = mixerGroup;

        var dspTime = AudioSettings.dspTime;

        if (entry.introClip != null)
        {
            audioSourceIntro.clip = entry.introClip;
            audioSourceIntro.PlayScheduled(dspTime + 0.1);
        }

        if (entry.loopClip == null)
        {
            return;
        }
        audioSourceLoop.clip = entry.loopClip;
        if (entry.introClip != null)
        {
            var clipDuration = (double)audioSourceIntro.clip.samples / audioSourceIntro.clip.frequency;
            audioSourceLoop.PlayScheduled(dspTime + 0.1 + clipDuration);
        }
        else
        {
            audioSourceLoop.Play();
        }
    }
コード例 #3
0
 public void Remove(MusicStackEntry musicStackEntry)
 {
     musicStack.Remove(musicStackEntry);
 }
コード例 #4
0
 public void Add(MusicStackEntry musicStackEntry)
 {
     musicStack.Add(musicStackEntry);
 }