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 + "'"); } }
// 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; }
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); }
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 + "'"); } }
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); }