/// <summary> /// Gets whether this AudioTrack is finished and ready to be destroyed /// </summary> /// <returns>True if this track can no longer play</returns> public bool IsFinished(bool destroy = false) { bool ret = (RawClipData == null || RawClipData.Length == 0) || (m_fadeTarget <= 0f && CurFade <= 0f) || (IsPlayOnce && isDelaying); if (ret && destroy) { if (m_outputSource != null) { //Debug.Log("IsFinished() removing AudioSource"); Object.Destroy(m_outputSource.gameObject); m_outputSource = null; } if (MySyncGroup != null) { MySyncGroup.Remove(this); } } return(ret); }
/// <summary> Updates clip list if it changed. (Call from within Update() function) </summary> public void UpdateClips() { if (m_sequence == null) { return; } List <AudioClip> allClips = new List <AudioClip>(m_sequence.Clips.Length); foreach (Sequence.ClipData clip in m_sequence.Clips) { if (clip.m_clip != null) { allClips.Add(clip.m_clip); } } if (allClips.Count == 0) { Debug.LogWarning("No audio clips found in Sequence '" + m_name + "'!"); } bool changed = false; if (allClips.Count != DirectClipData.Length) { //length changed so it definitly changed. changed = true; } else { for (int c = 0; c < DirectClipData.Length; ++c) { if (DirectClipData[c] != allClips[c]) { changed = true; break; } } } if (changed) //update current raw clip list then select our current track if it still exists. { RawAudioData[] newRawClipData = new RawAudioData[allClips.Count]; AudioClip curClip = m_isOutputDirect ? DirectClipData[currentClipIdx] : RawClipData[currentClipIdx].BaseClip; int newClipIdx = -1; for (int c = 0; c < allClips.Count; ++c) { if (allClips[c] == curClip) { newClipIdx = c; } newRawClipData[c] = AmbienceManager.GetAudioData(allClips[c]); } NextClipIdx = -1; if (newClipIdx < 0) { PlayToFade = RawClipData[currentClipIdx]; RawClipData = newRawClipData; newClipIdx = NextClipIdx; DirectFadeOut = true; } else { RawClipData = newRawClipData; } currentClipIdx = newClipIdx; DirectClipData = allClips.ToArray(); if (m_sequence.RandomizeVolume) { curVolumeMod = Helpers.GetRandom(m_sequence.MinMaxVolume); } else { curVolumeMod = 1f; } if (!isSynced && m_sequence.RandomizePlaybackSpeed) { curPlaybackSpeedMod = Helpers.GetRandom(m_sequence.MinMaxPlaybackSpeed); } else { curPlaybackSpeedMod = 1f; } if (MySyncGroup != null) { MySyncGroup.UpdateLength(); } } }