namespace CinemaDirector { /// /// A track designed specifically to hold audio items. /// [TimelineTrackAttribute("Audio Track", TimelineTrackGenre.GlobalTrack, CutsceneItemGenre.AudioClipItem)] public class AudioTrack : TimelineTrack { /// /// Set the track to an arbitrary time. /// /// The new time. public override void SetTime(float time) { foreach (CinemaAudio cinemaAudio in AudioClips) { float audioTime = time - cinemaAudio.Firetime; cinemaAudio.SetTime(audioTime); } } /// /// Pause all Audio Clips that are currently playing. /// public override void Pause() { foreach (CinemaAudio cinemaAudio in AudioClips) { cinemaAudio.Pause(); } } /// /// Update the track and play any newly triggered items. /// /// The new running time. /// The deltaTime since the last update call. public override void UpdateTrack(float time, float deltaTime) { float elapsedTime = base.elapsedTime; base.elapsedTime = time; foreach (CinemaAudio cinemaAudio in AudioClips) { if (cinemaAudio != null) { if (((elapsedTime < cinemaAudio.Firetime) || (elapsedTime <= 0f)) && (((base.elapsedTime >= cinemaAudio.Firetime)))) { cinemaAudio.Trigger(); } if ((base.elapsedTime > cinemaAudio.Firetime) && (base.elapsedTime <= (cinemaAudio.Firetime + cinemaAudio.Duration))) { float audioTime = time - cinemaAudio.Firetime; cinemaAudio.UpdateTime(audioTime, deltaTime); } if (((elapsedTime <= (cinemaAudio.Firetime + cinemaAudio.Duration)) && (base.elapsedTime > (cinemaAudio.Firetime + cinemaAudio.Duration)))) { cinemaAudio.End(); } } } } /// /// Resume playing audio clips after calling a Pause. /// public override void Resume() { foreach (CinemaAudio cinemaAudio in this.AudioClips) { if (((base.Cutscene.RunningTime > cinemaAudio.Firetime)) && (base.Cutscene.RunningTime < (cinemaAudio.Firetime + cinemaAudio.Duration))) { cinemaAudio.Resume(); } } } /// /// Stop playback of all playing audio items. /// public override void Stop() { base.elapsedTime = 0f; foreach (CinemaAudio cinemaAudio in AudioClips) { cinemaAudio.Stop(); } } /// /// Get all cinema audio objects associated with this audio track /// public CinemaAudio[] AudioClips { get { return GetComponentsInChildren(); } } } }