public void FadeInOut(AudioClipEx clip, float durationIn, float durationOut) { if (clip.clip == _source.clip) { return; } StartCoroutine(CoFadeInOut(clip, durationIn, durationOut)); }
public void FadeInSound(AudioClipEx clip, float duration) { if (clip.clip == _source.clip) { return; } StartCoroutine(CoFadeInSound(clip, duration)); }
public void PopInSound(AudioClipEx clip) { if (clip.clip == _source.clip) { return; } _source.Stop(); _source.SetClipDetails(clip); _source.Play(); }
public void FadeInSound(AudioClipEx clip, float duration) { if (source.isPlaying && clip.clip == source.clip) { return; } SetClipDetails(source, clip); source.volume = 0f; source.Play(); source.DOFade(clip.volume, duration).Play(); }
private void SetClipDetails(AudioSource source, AudioClipEx clip) { source.clip = clip.clip ?? source.clip; source.volume = clip.volume; source.outputAudioMixerGroup = clip.mixer ?? source.outputAudioMixerGroup; source.loop = clip.Loop; if (clip.VaryPitch) { var factor = RandomEx.Range(clip.PitchFactor); source.pitch = factor; } else { source.pitch = 1; } }
public void CorssfadeToSound(AudioClipEx clip, float durationIn, float durationOut) { if (source.isPlaying && clip.clip == source.clip) { return; } Sequence seq = DOTween.Sequence().Append(source.DOFade(0, durationOut).OnComplete(() => { source.Stop(); SetClipDetails(source, clip); source.volume = 0; source.Play(); })).Append(source.DOFade(clip.volume, durationIn)); seq.Play(); }
private IEnumerator CoFadeInSound(AudioClipEx clip, float duration) { _source.SetClipDetails(clip); _source.volume = 0f; _source.Play(); var start = Time.time; var end = start + duration; while (Time.time < end) { _source.volume = Tween.Lerp(0, clip.volume, (Time.time - start) / duration); yield return(null); } _source.volume = clip.volume; }
public static void SetClipDetails(this AudioSource source, AudioClipEx clipEx) { source.clip = clipEx.clip ?? source.clip; source.volume = clipEx.volume; source.outputAudioMixerGroup = clipEx.mixer ?? source.outputAudioMixerGroup; }
public void PopInSound(AudioClipEx clip) { source.Stop(); SetClipDetails(source, clip); source.Play(); }
private IEnumerator CoFadeInOut(AudioClipEx clip, float durationIn, float durationOut) { yield return(StartCoroutine(CoFadeOutSound(durationOut))); yield return(StartCoroutine(CoFadeInSound(clip, durationIn))); }