Esempio n. 1
0
        private void DrawPlaylistTrack(ReorderableList list, Rect rect, int index, bool isActive, bool isFocused)
        {
            PlaylistTrack track = (PlaylistTrack)list.list[index];

            rect.height = EditorGUIUtility.singleLineHeight;
            rect.width /= 2;
            track.Clip  = (AudioClip)EditorGUI.ObjectField(rect, track.Clip, typeof(AudioClip), false);

            rect.x      += rect.width + 4;
            rect.width  -= 4;
            track.Volume = EditorGUI.Slider(rect, track.Volume, 0.0f, 1.0f);
        }
Esempio n. 2
0
        private void Crossfade(PlaylistTrack track, float fade)
        {
            for (int i = 0; i < usedMixers.Count; i++)
            {
                TrackMixer mixer = usedMixers[i];
                mixer.fader.FadeOut(fade);
            }

            TrackMixer targetMixer = FetchMixer(track);

            if (targetMixer != null)
            {
                targetMixer.fader.FadeIn(fade);
            }
        }
Esempio n. 3
0
        internal PlaylistTrack Seek(string name)
        {
            int numTracks = playlist.Tracks.Count;

            for (int i = 0; i < numTracks; i++)
            {
                int           index = shuffleOrder[i];
                PlaylistTrack track = playlist.Tracks[index];
                if (track.Name == name)
                {
                    shuffleIndex = i;
                    return(GetTrack());
                }
            }
            return(null);
        }
Esempio n. 4
0
        internal void Update(float dt)
        {
            if (!isPlaying)
            {
                return;
            }

            playbackFader.Update(dt);

            bool audible = player.Audible;

            for (int i = usedMixers.Count - 1; i >= 0; i--)
            {
                TrackMixer    mixer  = usedMixers[i];
                AudioSource   source = mixer.source;
                PlaylistTrack track  = mixer.track;
                Fader         fader  = mixer.fader;

                fader.Update(dt);
                if (fader.Volume == 0.0f)
                {
                    ReleaseUsedMixer(i);
                }

                source.volume = playbackFader.Volume * fader.Volume * player.Volume * track.Volume;
                source.mute   = !audible;
            }

            if (advancer == null)
            {
                return;
            }

            TrackMixer currentMixer = GetUsedMixer(advancer.GetTrack());

            if (currentMixer == null)
            {
                return;
            }

            bool needToSwitch = (currentMixer.source.time + player.Fade >= currentMixer.source.clip.length);

            if (player.AutoAdvance && needToSwitch)
            {
                Crossfade(advancer.Next(), player.Fade);
            }
        }
Esempio n. 5
0
        private TrackMixer GetUsedMixer(PlaylistTrack track)
        {
            if (track == null)
            {
                return(null);
            }

            for (int i = 0; i < usedMixers.Count; i++)
            {
                TrackMixer mixer = usedMixers[i];
                if (mixer.track == track)
                {
                    return(mixer);
                }
            }

            return(null);
        }
Esempio n. 6
0
        private TrackMixer FetchMixer(PlaylistTrack track)
        {
            if (track == null)
            {
                return(null);
            }

            TrackMixer mixer = GetUsedMixer(track);

            if (mixer != null)
            {
                return(mixer);
            }

            if (freeMixers.Count > 0)
            {
                mixer = freeMixers[freeMixers.Count - 1];
                freeMixers.RemoveAt(freeMixers.Count - 1);
            }

            if (mixer == null)
            {
                mixer        = new TrackMixer();
                mixer.source = root.AddComponent <AudioSource>();
            }

            mixer.track                        = track;
            mixer.source.clip                  = track.Clip;
            mixer.source.timeSamples           = 0;
            mixer.source.outputAudioMixerGroup = player.MixerGroup;
            mixer.source.loop                  = player.Loop;

            if (isPlaying)
            {
                mixer.source.Play();
            }

            usedMixers.Add(mixer);
            return(mixer);
        }