コード例 #1
0
        /**
         * <summary>Fades out a new AudioSource</summary>
         * <param name = "audioSourceToCopy">The AudioSource to copy clip and volume data from</param>
         * <param name = "_fadeTime">The duration, in seconds, of the fade effect</param>
         */
        public static MusicCrossfade FadeOut(Soundtrack soundtrack, AudioSource audioSourceToCopy, float _fadeTime)
        {
            if (soundtrack == null || audioSourceToCopy == null || audioSourceToCopy.clip == null || _fadeTime <= 0f)
            {
                return(null);
            }

            GameObject newOb = new GameObject(soundtrack.soundType.ToString() + " crossfade");

            newOb.transform.parent        = soundtrack.transform;
            newOb.transform.localPosition = Vector3.zero;

            AudioSource newAudioSource = newOb.AddComponent <AudioSource>();

            newAudioSource.spatialBlend        = 0f;
            newAudioSource.playOnAwake         = false;
            newAudioSource.ignoreListenerPause = soundtrack.playWhilePaused;

            MusicCrossfade newCrossfade = newOb.AddComponent <MusicCrossfade>();

            newCrossfade._audioSource = newAudioSource;

            newAudioSource.clip = audioSourceToCopy.clip;
            newAudioSource.outputAudioMixerGroup = audioSourceToCopy.outputAudioMixerGroup;
            newAudioSource.volume      = audioSourceToCopy.volume;
            newAudioSource.timeSamples = audioSourceToCopy.timeSamples;
            newAudioSource.loop        = audioSourceToCopy.loop;
            newAudioSource.Play();

            newCrossfade.originalFadeTime = _fadeTime;
            newCrossfade.originalVolume   = audioSourceToCopy.volume;
            newCrossfade.fadeTime         = _fadeTime;

            return(newCrossfade);
        }
コード例 #2
0
ファイル: Soundtrack.cs プロジェクト: Keraunic-Tonic/GJ2021
        protected void CreateNewCrossfade(float fadeTime)
        {
            MusicCrossfade newCrossfade = MusicCrossfade.FadeOut(this, audioSource, fadeTime);

            if (newCrossfade)
            {
                crossfades.Add(newCrossfade);
            }
        }
コード例 #3
0
        private void Awake()
        {
            musicCrossfade     = GetComponentInChildren <MusicCrossfade>();
            playWhilePaused    = KickStarter.settingsManager.playMusicWhilePaused;
            surviveSceneChange = true;
            soundType          = SoundType.Music;
            Initialise();

            queuedMusic.Clear();

            if (musicCrossfade == null)
            {
                ACDebug.LogWarning("The 'Music' script requires a 'MusicCrossfade' component to be attached as a child component.");
            }
        }
コード例 #4
0
ファイル: Soundtrack.cs プロジェクト: katuokite/TTLY
        protected void Awake()
        {
            crossfade          = GetComponentInChildren <MusicCrossfade>();
            surviveSceneChange = true;
            Initialise();

            queuedSoundtrack.Clear();
            lastQueuedSoundtrack.Clear();

            if (crossfade == null)
            {
                ACDebug.LogWarning("The " + gameObject.name + " requires a 'MusicCrossfade' component to be attached as a child component.\r\nOne has been added automatically, but you should update the source prefab.", gameObject);
                GameObject crossfadeOb = new GameObject("Crossfader");
                crossfadeOb.AddComponent <AudioSource>();
                crossfade = crossfadeOb.AddComponent <MusicCrossfade>();
                crossfadeOb.transform.position = transform.position;
                crossfadeOb.transform.parent   = transform;
            }
        }
コード例 #5
0
        private void Awake()
        {
            musicCrossfade     = GetComponentInChildren <MusicCrossfade>();
            playWhilePaused    = KickStarter.settingsManager.playMusicWhilePaused;
            surviveSceneChange = true;
            soundType          = SoundType.Music;
            Initialise();

            queuedMusic.Clear();
            lastQueuedMusic.Clear();

            if (musicCrossfade == null)
            {
                ACDebug.LogWarning("The " + gameObject.name + " requires a 'MusicCrossfade' component to be attached as a child component.\r\nOne has been added automatically, but you should update the source prefab.", gameObject);
                GameObject crossfadeOb = new GameObject("Crossfader");
                crossfadeOb.AddComponent <AudioSource>();
                musicCrossfade = crossfadeOb.AddComponent <MusicCrossfade>();
                crossfadeOb.transform.position = transform.position;
                crossfadeOb.transform.parent   = transform;
            }
        }