コード例 #1
0
        void Play(MusicZone zone)
        {
            if (debug)
            {
                Debug.Log("Attempting a play of " + zone.name);
            }

            if (currentTrackSource)
            {
                // Pause the currently playing audio source if it's playing a different track than the requested zone
                if (zone.musicTrack != currentTrackSource.MyTrack)
                {
                    currentTrackSource.Pause(CurrentTrackFadeOutTime());
                }
            }

            TrackAudioSource newTrackAudioSource = null;

            // If an audio source stack has already been built for the
            // music track of this zone, just change zones on it.
            if (trackSources.TryGetValue(zone.musicTrack, out newTrackAudioSource))
            {
                newTrackAudioSource.ChangeZones(zone, zone.fadeInTime);
                newTrackAudioSource.Play(zone.fadeInTime);
                currentTrackSource = newTrackAudioSource;
                return;
            }

            // if we don't have an audio source stack for this track yet,
            // build one and set it as the new current track
            newTrackAudioSource = BuildNewTrackAudioSource(zone);
            currentTrackSource  = newTrackAudioSource;
        }
コード例 #2
0
        TrackAudioSource BuildNewTrackAudioSource(MusicZone newZone)
        {
            GameObject newGO = new GameObject();

            newGO.name                    = "track source: " + newZone.musicTrack.name;
            newGO.transform.parent        = transform;
            newGO.transform.localPosition = Vector3.zero;
            TrackAudioSource newTrack = newGO.AddComponent <TrackAudioSource>();

            newTrack.BuildAudioSources(newZone, mixerGroup);

            trackSources.Add(newZone.musicTrack, newTrack);
            return(newTrack);
        }
コード例 #3
0
        public void LoopTrack(MusicZone musicZone)
        {
            // remove the old one from the dictionary
            var t = musicZone.musicTrack;

            trackSources.Remove(t);

            // re-create it
            var newTrackSource = BuildNewTrackAudioSource(musicZone);

            // if the looping track was the current playing, carryover that status
            if (currentTrackSource.musicZone == musicZone)
            {
                currentTrackSource = newTrackSource;
            }
        }