/// <summary> /// Plays the sound effect for the specified SFX type. Can be played in 2D or 3D. /// </summary> /// <param name="sfxType">The type of Sound Effect to play</param> /// <param name="emitterPosition">The location to emit the sound from</param> private void PlaySoundEffect(SfxType sfxType, Vector3?emitterPosition = null) { if (!soundEffects.ContainsKey(sfxType)) { Debug.WriteLine("No Sound for the key" + sfxType.ToString("G") + " found!"); return; } SoundEffect sfx = soundEffects[sfxType]; if (sfx != null) { SoundEffectInstance sei = sfx.CreateInstance(); float volumeToApply = currentSfxVolume; if (emitterPosition != null) { emitter.Position = (Vector3)emitterPosition; listener.Position = listenerTransform.Translation; sei.Apply3D(listener, emitter); } sei.Volume = volumeToApply; sei.Play(); sfxInstances.Add(sei); } }
public void Play(SfxType type) { if (clips.ContainsKey(type) == false) { Debug.LogError("Sfx not loaded, type : " + type.ToString()); return; } source.PlayOneShot(clips[type], source.volume); }
public void Initialize() { if (IsInitialized == true) { return; } IsInitialized = true; for (int i = (int)SfxType.Undefined + 1; i < (int)SfxType.End_Of_Sfx; ++i) { SfxType type = (SfxType)i; clips.Add(type, Resources.Load <AudioClip>("Sounds/Sfx/" + type.ToString())); } Debug.Log("SfxManager Load end."); }
public void PlayLoop(SfxType type) { if (clips.ContainsKey(type) == false) { Debug.LogError("Sfx not loaded, type : " + type.ToString()); return; } if (loopSourcesPool.RemainCount == 0) { AddLoopSource(); } AudioSource loopSource = loopSourcesPool.Get(); loopSource.volume = SoundManager.Instance.SfxVolume; loopSource.clip = clips[type]; loopSource.loop = true; loopSource.Play(); loopingSources.Add(new KeyValuePair <SfxType, AudioSource>(type, loopSource)); }
public void PlaySE(SfxType audio, float delay = 0.0f) { PlaySE(audio.ToString(), delay); }