Ejemplo n.º 1
0
    public void Play()
    {
        AudioManager audioManager = (AudioManager)target;

        ExtSound extSound = Array.Find(audioManager.ExternalSoundsCollection, findExtSound => findExtSound.Name.ToLower() == _soundName.ToLower());

        if (extSound != null)
        {
            int randomNumber = UnityEngine.Random.Range(0, extSound.GeneralWeight);

            foreach (Sound sound in extSound.SoundCollection)
            {
                if (randomNumber < sound.Weight)
                {
                    AudioSource audioSource = ((AudioManager)target).gameObject.GetComponent <AudioSource>();
                    if (audioSource == null)
                    {
                        audioSource = ((AudioManager)target).gameObject.AddComponent <AudioSource>();
                    }
                    audioSource.clip   = sound.Сlip;
                    audioSource.volume = sound.Volume;
                    audioSource.pitch  = sound.Pitch;
                    audioSource.loop   = sound.Loop;
                    audioSource.Play();
                    return;
                }
                randomNumber = randomNumber - sound.Weight;
            }
        }
        else
        {
            Debug.LogWarning("Editor: Can't find clip '" + _soundName + "'");
        }
    }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        _audioManager = AudioManager.Instance;
        _extSound     = _audioManager.GetExtSound(SoundName);

        AudioManager.Instance.OnSoundPlayed  += Play;
        AudioManager.Instance.OnSoundStopped += Stop;
    }
Ejemplo n.º 3
0
    public ExtSound GetExtSound(string soundName)
    {
        ExtSound extSound = _externalSoundsNamedCollection[soundName];

        if (extSound != null)
        {
            return(extSound);
        }
        else
        {
            //Debug.LogWarning("Warning[AudioManager]>GetExtSound(): Can't find clip '" + soundName + "'");
        }
        return(null);
    }
Ejemplo n.º 4
0
    public void Stop(string soundName)
    {
        ExtSound extSound = _externalSoundsNamedCollection[soundName];

        if (extSound != null)
        {
            foreach (Sound sound in extSound.SoundCollection)
            {
                sound.Source.Stop();
            }
        }
        else
        {
            //Debug.LogWarning("Warning[AudioManager]>Reset(): Can't find clip '" + soundName + "'");
        }
    }
Ejemplo n.º 5
0
    public Sound GetSound(string soundName)
    {
        ExtSound extSound = _externalSoundsNamedCollection[soundName];

        if (extSound != null)
        {
            int randomNumber = Random.Range(0, extSound.GeneralWeight);

            foreach (Sound sound in extSound.SoundCollection)
            {
                if (randomNumber < sound.Weight)
                {
                    return(sound);
                }
                randomNumber = randomNumber - sound.Weight;
            }
        }
        else
        {
            //Debug.LogWarning("Warning[AudioManager]>GetSound(): Can't find clip '" + soundName + "'");
        }
        return(null);
    }