IEnumerator FadeSoundOut(string name, float time) { Debug.Log("Fading out sound " + name + " in " + time); ArcticSound s = Array.Find(sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("Der Sound " + name + " wurde im AudioManager nicht gefunden."); } if (s.source == null) { Debug.Log("The sound " + name + " will be dynamically loaded."); LoadSoundSource(s); } for (int i = 0; i < time * 25; i++) { s.source.volume -= i / (time * 25); yield return(new WaitForSecondsRealtime(.04f)); } s.source.Stop(); Debug.Log("Sound " + name + " faded out"); s.source.volume = s.volume; }
void UnloadSoundSource(ArcticSound s) { if (s.source == null) { return; } Destroy(s.source); s.source = null; }
void LoadSoundSource(ArcticSound s) { if (s.source != null) { return; } s.source = gameObject.AddComponent <AudioSource>(); s.source.clip = s.clip; s.source.volume = s.volume; s.source.pitch = s.pitch; s.source.loop = s.loop; s.source.outputAudioMixerGroup = s.mixerGroup; }
public void UnPause(string name) { ArcticSound s = Array.Find(sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("Der Sound " + name + " wurde im AudioManager nicht gefunden."); return; } if (s.source == null) { Debug.Log("The sound " + name + " will be dynamically loaded."); LoadSoundSource(s); } s.source.UnPause(); }
IEnumerator PitchDown(string name, float downTo, float transitionDuration) { ArcticSound s = Array.Find(sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("Der Sound " + name + " wurde im AudioManager nicht gefunden."); } if (s.source == null) { Debug.Log("The sound " + name + " will be dynamically loaded."); LoadSoundSource(s); } for (int i = 0; i < transitionDuration * 25; i++) { s.source.pitch = Mathf.Lerp(s.pitch, downTo, i / transitionDuration * 25); yield return(new WaitForSecondsRealtime(.04f)); } }
public void Play(string name, bool onlyPlayIfNotAlreadyPlaying) { ArcticSound s = Array.Find(sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("The sound " + name + " has not been found."); return; } if (s.source == null) { Debug.Log("The sound " + name + " will be dynamically loaded."); LoadSoundSource(s); } if (onlyPlayIfNotAlreadyPlaying && !s.source.isPlaying) { s.source.Play(); } }
public void Play(string name) { ArcticSound s = Array.Find(sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("The sound " + name + " has not been found."); return; } if (s.source == null) { Debug.Log("The sound " + name + " will be dynamically loaded."); LoadSoundSource(s); } if (s.source == null) { Debug.LogError("The sound " + name + " could not be loaded."); return; } s.source.Play(); }