public AudioSource PlaySFX(SFXName sfxName, float timeDelay = 0.0f, int index = -1, bool playImmediate = true) { if (sfxName == SFXName.NONE) { return(null); } SFXAudioObj audioObj = m_sfxAudioObjs[(int)sfxName]; if (audioObj.m_clips.Count == 0) { Debug.LogError("No Clips in SFX: " + sfxName.ToString()); return(null); } AudioSource audioSource = gameObject.AddComponent <AudioSource>(); if (index == -1) { // Random AudioClip audioSource.clip = audioObj.m_clips[Random.Range(0, audioObj.m_clips.Count - 1)]; } else { // AudioClip By Index audioSource.clip = audioObj.m_clips[index]; } audioSource.volume = audioObj.m_volume * m_globalSFXVolume; audioSource.loop = audioObj.m_loop; if (playImmediate) { audioSource.PlayDelayed(timeDelay); } m_currentAudioSources.Add(audioSource); return(audioSource); }
public void PlaySFX(SFXName name) { if (!soundEffects.ContainsKey(name)) { return; } AudioSource audioSource = gameObject.AddComponent <AudioSource>(); audioSource.clip = soundEffects[name].audioClip; audioSource.loop = false; audioSource.volume = soundEffects[name].volume; audioSource.Play(); Destroy(audioSource, audioSource.clip.length); }
public SoundEffect GetSFX(SFXName effect) { if (_sfxMap == null) { this.InitializeDictionary(); } SoundEffect sfx; if (_sfxMap.TryGetValue(effect, out sfx)) { return(sfx); } else { Debug.LogError("Sound Effect not found for effect type " + effect); return(null); } }
public SFXAudioObj GetSFXAudioObj(SFXName sfxName) { return(m_sfxAudioObjs[(int)sfxName]); }