Exemplo n.º 1
0
    public void UpdateSound()
    {
        Sound2D.Adapt2DSound(audioSource);

        audioSource.maxDistance = maxDistance;
        audioSource.minDistance = minDistance;
    }
Exemplo n.º 2
0
 public void PlayRandomClip(Sound2D sound2D)
 {
     if (_sounds.TryGetValue(sound2D, out SoundGroup soundGroup))
     {
         soundGroup.PlayRandomClip();
     }
     else
     {
         Debug.LogWarningFormat("Audio Manager 2D : {0} is missing in _sounds field.", sound2D);
     }
 }
Exemplo n.º 3
0
 public void Play(AudioClip clip, float volume = 1f)
 {
     if (!audioSource)
     {
         audioSource = gameObject.AddComponent(typeof(AudioSource)) as AudioSource;
         Sound2D.Adapt2DSound(audioSource);
         audioSource.clip        = clip;
         audioSource.volume      = volume;
         audioSource.loop        = false;
         audioSource.maxDistance = 15f;
         audioSource.minDistance = 5f;
         audioSource.Play();
     }
 }
Exemplo n.º 4
0
    public void PlayEffect(string effectName, float volumeSound = -1f)
    {
        volumeSound = volumeSound == -1 ? volume : volumeSound;
        EffectElement found = foundEffect(effectName);

        if (found.name != null)
        {
            AudioSource newAudio = gameObject.AddComponent(typeof(AudioSource)) as AudioSource;
            Sound2D.Adapt2DSound(newAudio);
            newAudio.maxDistance = maxDistance;
            newAudio.minDistance = minDistance;
            newAudio.clip        = found.variants[Random.Range(0, found.variants.Count)];
            newAudio.volume      = volumeSound;
            newAudio.Play();
            newAudio.loop = false;
            allSourcesSoundsEffects.Add(newAudio);
        }
    }
Exemplo n.º 5
0
    public void PlaySound(string musicName, float speedTime = 10f)
    {
        SoundElement found = foundSound(musicName);

        if (found.name != null && found.name != currentName)
        {
            //We have found a sound
            currentName        = found.name;
            timeToTransition   = speedTime;
            currTimeTransition = timeToTransition;
            AudioSource newAudio = gameObject.AddComponent(typeof(AudioSource)) as AudioSource;
            Sound2D.Adapt2DSound(newAudio);
            newAudio.maxDistance = maxDistance;
            newAudio.minDistance = minDistance;
            newAudio.clip        = found.clip;
            newAudio.volume      = 0f;
            newAudio.Play();
            newAudio.loop = found.loop;
            allSources.Add(newAudio);

            InitVolumes();
        }
    }