Exemplo n.º 1
0
    public void PlayLongSoundClip(string name, AudioClip clip, bool pausable, float fadeTime)
    {
        if (_longSounds.ContainsKey(name))
        {
            StopLongSound(name);
        }

        AudioSource longSoundSource = gameObject.AddComponent<AudioSource>();
        longSoundSource.loop = true;
        longSoundSource.priority = 0;
        longSoundSource.playOnAwake = false;
        longSoundSource.mute = GameData.Instance.GameSoundSettings.GetSoundMuted();
        longSoundSource.ignoreListenerPause = !pausable;
        longSoundSource.clip = clip;
        longSoundSource.Play();

        longSoundSource.volume = 0;

        LongSound longSound = new LongSound();
        longSound.Source = longSoundSource;
        longSound.FadingIn = true;
        longSound.TargetVolume = GameData.Instance.GameSoundSettings.GetSoundVolume();
        longSound.Timer = 0;
        longSound.FadingTime = fadeTime;

        _longSounds.Add(name, longSound);
    }
Exemplo n.º 2
0
    public void PlayMusicClip(AudioClip musicClip, bool force = false)
    {
        if (_currentMusic != null && _currentMusic.Name == musicClip.name && force == false)
        {
            return;
        }

        StopMusic();

        AudioSource musicSource = gameObject.AddComponent<AudioSource>();
        musicSource.loop = true;
        musicSource.priority = 0;
        musicSource.playOnAwake = false;
        musicSource.mute = GameData.Instance.GameSoundSettings.GetMusicMuted();
        musicSource.ignoreListenerPause = true;
        musicSource.clip = musicClip;
        musicSource.Play();

        musicSource.volume = 0;

        _currentMusic = new LongSound();
        _currentMusic.Name = musicClip.name;
        _currentMusic.Source = musicSource;
        _currentMusic.FadingIn = true;
        _currentMusic.TargetVolume = GameData.Instance.GameSoundSettings.GetMusicVolume() * 0.8f;
        _currentMusic.Timer = 0;
        _currentMusic.FadingTime = GameData.Instance.GameSoundSettings.MusicFadeTime;
    }
Exemplo n.º 3
0
 public void StopMusic()
 {
     if (_currentMusic != null)
     {
         StartFadingOutMusic();
         _currentMusic = null;
     }
 }
Exemplo n.º 4
0
 void StartFadingOutLongSound(string name)
 {
     LongSoundFadingOut fader = new LongSoundFadingOut();
     LongSound sound = _longSounds[name];
     fader.Source = sound.Source;
     fader.FadingTime = sound.FadingTime;
     fader.Timer = 0;
     fader.StartVolume = sound.Source.volume;
     _longSoundFadingsOut.Add(fader);
 }
Exemplo n.º 5
0
 private void Awake()
 {
     _currentMusic = null;
 }