public void PlayClips(SoundType type, AudioClip[] clips, OnSoundPlayEnd playEndCB = null, bool looplast = false, float channelvolume = 1, float currentFadeOutTime = 0, float delay = 0) { m_soundType = type; m_looplast = looplast; m_executeChannelVolume = channelvolume; onSoundPlayEnd = playEndCB; if (clips.Length == 0) { Stop(); return; } //check if the same clips bool sameclips = true; if (m_currentClips.Count == clips.Length) { for (int i = 0; i < m_currentClips.Count; i++) { if (m_currentClips[i] != clips[i]) { sameclips = false; break; } } } else { sameclips = false; } if (sameclips && IsPlaying) { return; } else { m_delay = delay; m_currentClips.Clear(); m_currentClipsScheduledDspTime.Clear(); m_currentClips.AddRange(clips); if (!IsPlaying || currentFadeOutTime <= 0) { ExecutePlayClips(); } else { TweenVolume(0, currentFadeOutTime, iTween.EaseType.linear, ExecutePlayClips); } } }
void Update() { if (m_tweenVolume) { m_tweenCurrentTime += Time.deltaTime; if (m_tweenTime <= 0) { ChannelVolume = m_tweenDestVolume; } else { ChannelVolume = iTween.GetEasingValue(m_tweenStartVolume, m_tweenDestVolume, m_tweenCurrentTime / m_tweenTime, m_tweenEaseType); } if (m_tweenCurrentTime >= m_tweenTime) { ChannelVolume = m_tweenDestVolume; m_tweenVolume = false; if (m_tweenEndCb != null) { m_tweenEndCb(); } } } AudioSourcesVolume = RealVolume; if (m_currentClipIndex < m_currentClipsScheduledDspTime.Count) { var nowDspTime = AudioSettings.dspTime; if (nowDspTime + 1.0 > m_currentClipsScheduledDspTime[m_currentClipIndex]) { m_audioSources[m_currentClipIndex].PlayScheduled(m_currentClipsScheduledDspTime[m_currentClipIndex]); m_currentClipIndex++; } } if (onSoundPlayEnd != null && !IsPlaying && !IsPaused) { onSoundPlayEnd(this); onSoundPlayEnd = null; } }
public void PlayClip(SoundType type, AudioClip clip, OnSoundPlayEnd playEndCB = null, bool loop = false, float channelvolume = 1, float currentFadeOutTime = 0, float delay = 0) { PlayClips(type, new AudioClip[] { clip }, playEndCB, loop, channelvolume, currentFadeOutTime, delay); }