public void PlayAudioClip(AudioSourceName audioSourceName, AudioClip audioClip, bool overwriteActualAudio) { GetRequestedAudioSource(audioSourceName, out AudioSource actualSrc); if (overwriteActualAudio || !actualSrc.isPlaying) { actualSrc.clip = audioClip; actualSrc.Play(); } }
protected AudioSourceName FindSoundWithName(string name) { AudioSourceName asn = audioSourceNames.Find(item => item.name == name); if (asn == null) { Debug.LogWarning("Sound: " + name + " not found."); return(null); } return(asn); }
public void Play(string name) { AudioSourceName asn = FindSoundWithName(name); if (asn == null) { return; } if (asn.randomizePitch) { asn.source.pitch = asn.originalPitch + UnityEngine.Random.Range(-randomizePitchWindow, randomizePitchWindow); } asn.source.Play(); }
// public void DetermineAudioVolume () private void GetRequestedAudioSource(AudioSourceName audioSourceName, out AudioSource actualSrc) { switch (audioSourceName) { case AudioSourceName.MusicSource: actualSrc = musicSource; break; case AudioSourceName.SfxSource: actualSrc = sfxSource; break; default: actualSrc = musicSource; break; } }
public void UpdateAudioSourceVolume(AudioSourceName audioSourceName, float newVolume) { GetRequestedAudioSource(audioSourceName, out AudioSource actualSrc); actualSrc.volume = newVolume; }
public void StopAudio(AudioSourceName audioSourceName) { GetRequestedAudioSource(audioSourceName, out AudioSource actualSrc); actualSrc.Stop(); }
public void ResumeAudio(AudioSourceName audioSourceName) { GetRequestedAudioSource(audioSourceName, out AudioSource actualSrc); actualSrc.Play(); }