Пример #1
0
        public void BuildAudioSources(MusicZone newMusicZone, AudioMixerGroup mixerGroup)
        {
            musicZone    = newMusicZone;
            track        = musicZone.musicTrack;
            trackVolumes = trackVolumesOutput = newMusicZone.GenerateVolumes();

            // Create an audio source for each layer
            for (int i = 0; i < musicZone.layers.Count; i++)
            {
                var layer = musicZone.layers[i];

                // instantiate a source
                var newAudioSource = gameObject.AddComponent <AudioSource>();
                newAudioSource.spatialBlend          = 0;
                newAudioSource.clip                  = layer.clip;
                newAudioSource.loop                  = false;
                newAudioSource.volume                = 0;
                newAudioSource.playOnAwake           = false;
                newAudioSource.outputAudioMixerGroup = mixerGroup;

                sources.Add(newAudioSource);
            }

            Play(musicZone.fadeInTime);
        }
Пример #2
0
        /// <summary>
        /// Change the music zone I'm playing for.
        /// This ONLY supports swapping between zones that share the same track!
        /// </summary>
        public void ChangeZones(MusicZone newMusicZone, float newFadeTime = 1)
        {
            if (newMusicZone == musicZone)
            {
                return;
            }

            string oldName = musicZone ? musicZone.name : "null";

            Debug.Log("Track " + MyTrack.name + " is changing zones from " + oldName + " to " + newMusicZone.name);
            if (newMusicZone.musicTrack != MyTrack)
            {
                Debug.LogError(name + " trying to change music zones, but the current and new zones don't " +
                               "have the same tracks.", gameObject);
                return;
            }

            musicZone    = newMusicZone;
            trackVolumes = newMusicZone.GenerateVolumes();
            fadeInTime   = newFadeTime;
        }