public void PlaySound(AudioClipNames clipName) { Sound sound = GetSound(clipName); if (sound == null) { Debug.LogWarning($"Audio with the name {clipName} not found"); return; } sound.Source.Play(); }
/// <summary> /// Unsynchronously plays the given audio clip /// </summary> /// <param name="clip">The audio clip to be played</param> public static void PlaySFX(AudioClipNames clip) { //Only play the sound if it was loaded was loaded audioClips.TryGetValue(clip, out var value); if (value == null) { return; } //Plays the sound audioSource_SoundEffects.PlayOneShot(value); }
/// <summary> /// Synchronously plays the given audio clips /// </summary> /// <param name="clip">The audio clip to be played</param> /// <param name="loop">Should the audio be looped</param> public static void PlayBGM(AudioClipNames clip, bool loop = true) { //Only play the music if it was loaded was loaded audioClips.TryGetValue(clip, out var value); if (value == null) { return; } //Plays the music audioSource_BackgroundMusic.clip = audioClips[clip]; audioSource_BackgroundMusic.loop = loop; audioSource_BackgroundMusic.Play(); }
/// <summary> /// Plays audio clip by given name, looping if appropriate /// </summary> /// <param name="soundName">name of sound effect</param> /// <param name="dontLoop">whether to loop sound</param> public static void Play(AudioClipNames soundName, bool dontLoop) { // if sound doesn't loop, simply play once if (dontLoop) { myAudioSource.PlayOneShot(audioClips[soundName]); } // TODO: otherwise, create separate, controllable audio source and play from there else { Debug.LogWarning("Warning: Loopable sounds not yet implemented."); } // write closed captioning if enabled and sound has captions if (ClosedCaptions.Instance.ccEnabled && soundsToCaptions.ContainsKey(soundName)) { ClosedCaptions.Instance.DisplayCaptions(soundsToCaptions[soundName]); } }
public void StopSound(AudioClipNames clipName) { Sound sound = GetSound(clipName); sound.Source.Stop(); }
private Sound GetSound(AudioClipNames clipName) { return((from s in sounds where s.ClipName == clipName select s).First()); }
/// <summary> /// Gets the length of a specific audio clip pre loaded /// </summary> /// <param name="name">The name of the audio clip</param> /// <returns></returns> public static float GetAudioClipLength(AudioClipNames name) { return(audioClips[name].length); }