/// <summary> /// Update the track and play any newly triggered items. /// </summary> /// <param name="time">The new running time.</param> /// <param name="deltaTime">The deltaTime since the last update call.</param> public override void UpdateTrack(float time, float deltaTime) { float elapsedTime = base.elapsedTime; base.elapsedTime = time; foreach (TimelineItem item in GetTimelineItems()) { TimelineActionFixed cinemaAudio = item as TimelineActionFixed; 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(); } } } }
public static CutsceneWrapper CreateWrapper(Cutscene cutscene) { CutsceneWrapper wrapper = new CutsceneWrapper(cutscene); if (cutscene != null) { wrapper.RunningTime = cutscene.RunningTime; wrapper.Duration = cutscene.Duration; wrapper.IsPlaying = cutscene.State == Cutscene.CutsceneState.PreviewPlaying || cutscene.State == Cutscene.CutsceneState.Playing; foreach (TrackGroup tg in cutscene.TrackGroups) { TrackGroupWrapper tgWrapper = new TrackGroupWrapper(tg); tgWrapper.Ordinal = tg.Ordinal; wrapper.AddTrackGroup(tg, tgWrapper); foreach (TimelineTrack track in tg.GetTracks()) { TimelineTrackWrapper trackWrapper = new TimelineTrackWrapper(track); trackWrapper.Ordinal = track.Ordinal; tgWrapper.AddTrack(track, trackWrapper); foreach (TimelineItem item in track.GetTimelineItems()) { if (item.GetType().IsSubclassOf(typeof(CinemaClipCurve))) { CinemaClipCurve clip = item as CinemaClipCurve; CinemaClipCurveWrapper clipWrapper = new CinemaClipCurveWrapper(clip, clip.Firetime, clip.Duration); trackWrapper.AddItem(clip, clipWrapper); } else if (item.GetType().IsSubclassOf(typeof(CinemaTween))) { } else if (item.GetType().IsSubclassOf(typeof(TimelineActionFixed))) { TimelineActionFixed actionFixed = item as TimelineActionFixed; CinemaActionFixedWrapper actionFixedWrapper = new CinemaActionFixedWrapper(actionFixed, actionFixed.Firetime, actionFixed.Duration, actionFixed.InTime, actionFixed.OutTime, actionFixed.ItemLength); trackWrapper.AddItem(actionFixed, actionFixedWrapper); } else if (item.GetType().IsSubclassOf(typeof(TimelineAction))) { TimelineAction action = item as TimelineAction; CinemaActionWrapper itemWrapper = new CinemaActionWrapper(action, action.Firetime, action.Duration); trackWrapper.AddItem(action, itemWrapper); } else { TimelineItemWrapper itemWrapper = new TimelineItemWrapper(item, item.Firetime); trackWrapper.AddItem(item, itemWrapper); } } } } } return(wrapper); }
/// <summary> /// Pause all Audio Clips that are currently playing. /// </summary> public override void Pause() { foreach (TimelineItem item in GetTimelineItems()) { TimelineActionFixed cinemaAudio = item as TimelineActionFixed; if (cinemaAudio != null) { cinemaAudio.Pause(); } } }
/// <summary> /// Stop playback of all playing audio items. /// </summary> public override void Stop() { base.elapsedTime = 0f; foreach (TimelineItem item in GetTimelineItems()) { TimelineActionFixed cinemaAudio = item as TimelineActionFixed; if (cinemaAudio != null) { cinemaAudio.Stop(); } } }
/// <summary> /// Set the track to an arbitrary time. /// </summary> /// <param name="time">The new time.</param> public override void SetTime(float time) { foreach (TimelineItem item in GetTimelineItems()) { TimelineActionFixed cinemaAudio = item as TimelineActionFixed; if (cinemaAudio != null) { float audioTime = time - cinemaAudio.Firetime; cinemaAudio.SetTime(audioTime); } } }
/// <summary> /// Resume playing audio clips after calling a Pause. /// </summary> public override void Resume() { foreach (TimelineItem item in GetTimelineItems()) { TimelineActionFixed cinemaAudio = item as TimelineActionFixed; if (cinemaAudio != null) { if (((base.Cutscene.RunningTime > cinemaAudio.Firetime)) && (base.Cutscene.RunningTime < (cinemaAudio.Firetime + cinemaAudio.Duration))) { cinemaAudio.Resume(); } } } }
/// <summary> /// Create a new Timeline Item (Cutscene Item) /// </summary> /// <param name="timelineTrack">The track that this item will be attached to.</param> /// <param name="type">the type of the new item.</param> /// <param name="label">The name of the new item.</param> /// <returns>The newly created Cutscene Item. Reminder: Register an Undo.</returns> internal static TimelineItem CreateCutsceneItem(TimelineTrack timelineTrack, Type type, string label, float firetime) { GameObject itemGO = new GameObject(label, type); TimelineItem ti = itemGO.GetComponent <TimelineItem>(); ti.SetDefaults(); // Find an appropriate firetime/duration for it. if (type.IsSubclassOf(typeof(TimelineActionFixed))) { // The new timeline item is an action of fixed length. TimelineActionFixed newAction = ti as TimelineActionFixed; SortedDictionary <float, TimelineActionFixed> sortedClips = new SortedDictionary <float, TimelineActionFixed>(); foreach (TimelineItem current in timelineTrack.TimelineItems) { TimelineActionFixed action = current as TimelineActionFixed; if (action == null) { continue; } sortedClips.Add(action.Firetime, action); } float latestTime = firetime; float length = newAction.ItemLength; foreach (TimelineActionFixed a in sortedClips.Values) { if (!(latestTime < a.Firetime && latestTime + length <= a.Firetime)) { latestTime = a.Firetime + a.Duration; } } newAction.Firetime = latestTime; } else if (type.IsSubclassOf(typeof(TimelineAction))) { // The new timeline item is an action with arbitrary length. TimelineAction newAction = ti as TimelineAction; SortedDictionary <float, TimelineAction> sortedActions = new SortedDictionary <float, TimelineAction>(); foreach (TimelineItem current in timelineTrack.TimelineItems) { TimelineAction action = current as TimelineAction; if (action == null) { continue; } sortedActions.Add(action.Firetime, action); } float latestTime = firetime; float length = newAction.Duration; foreach (TimelineAction a in sortedActions.Values) { if (latestTime >= a.Firetime) { latestTime = Mathf.Max(latestTime, a.Firetime + a.Duration); } else { length = a.Firetime - latestTime; break; } } newAction.Firetime = latestTime; newAction.Duration = length; } else { ti.Firetime = firetime; } itemGO.transform.parent = timelineTrack.transform; return(ti); }
public static CutsceneWrapper UpdateWrapper(TimelineManager cutscene, CutsceneWrapper wrapper) { if (cutscene == null) { return(null); } if (wrapper == null || !cutscene.Equals(wrapper.Behaviour)) { return(CreateWrapper(cutscene)); } else { wrapper.Behaviour = cutscene; wrapper.Duration = cutscene.Duration; wrapper.IsPlaying = cutscene.State == TimelineManager.TimeLineState.PreviewPlaying || cutscene.State == TimelineManager.TimeLineState.Playing; wrapper.RunningTime = cutscene.RunningTime; List <Behaviour> itemsToRemove = new List <Behaviour>(); foreach (Behaviour behaviour in wrapper.Behaviours) { bool found = false; foreach (TrackGroup group in cutscene.TrackGroups) { if (behaviour.Equals(group)) { found = true; break; } } if (!found || behaviour == null) { itemsToRemove.Add(behaviour); } } foreach (Behaviour trackGroup in itemsToRemove) { wrapper.HasChanged = true; wrapper.RemoveTrackGroup(trackGroup); } foreach (TrackGroup tg in cutscene.TrackGroups) { TrackGroupWrapper tgWrapper = null; if (!wrapper.ContainsTrackGroup(tg, out tgWrapper)) { tgWrapper = new TrackGroupWrapper(tg); tgWrapper.Ordinal = tg.Ordinal; wrapper.AddTrackGroup(tg, tgWrapper); wrapper.HasChanged = true; } foreach (TimelineTrack track in tg.GetTracks()) { TimelineTrackWrapper trackWrapper = null; if (!tgWrapper.ContainsTrack(track, out trackWrapper)) { trackWrapper = new TimelineTrackWrapper(track); trackWrapper.Ordinal = track.Ordinal; tgWrapper.AddTrack(track, trackWrapper); tgWrapper.HasChanged = true; } foreach (TimelineItem item in track.GetTimelineItems()) { TimelineItemWrapper itemWrapper = null; if (!trackWrapper.ContainsItem(item, out itemWrapper)) { if (item.GetType().IsSubclassOf(typeof(ItemClipCurve))) { ItemClipCurve clip = item as ItemClipCurve; itemWrapper = new CinemaClipCurveWrapper(clip, clip.Firetime, clip.Duration); trackWrapper.AddItem(clip, itemWrapper); } else if (item.GetType().IsSubclassOf(typeof(TimelineActionFixed))) { TimelineActionFixed fixedAction = item as TimelineActionFixed; itemWrapper = new CinemaActionFixedWrapper(fixedAction, fixedAction.Firetime, fixedAction.Duration, fixedAction.InTime, fixedAction.OutTime, fixedAction.ItemLength); trackWrapper.AddItem(fixedAction, itemWrapper); } else if (item.GetType().IsSubclassOf(typeof(TimelineAction))) { TimelineAction action = item as TimelineAction; itemWrapper = new CinemaActionWrapper(action, action.Firetime, action.Duration); trackWrapper.AddItem(action, itemWrapper); } else { itemWrapper = new TimelineItemWrapper(item, item.Firetime); trackWrapper.AddItem(item, itemWrapper); } trackWrapper.HasChanged = true; } else { if (GUIUtility.hotControl == 0) { if (itemWrapper.GetType() == (typeof(CinemaClipCurveWrapper))) { ItemClipCurve clip = item as ItemClipCurve; CinemaClipCurveWrapper clipWrapper = itemWrapper as CinemaClipCurveWrapper; clipWrapper.Firetime = clip.Firetime; clipWrapper.Duration = clip.Duration; } else if (itemWrapper.GetType() == (typeof(CinemaTweenWrapper))) { } else if (itemWrapper.GetType() == (typeof(CinemaActionFixedWrapper))) { TimelineActionFixed actionFixed = item as TimelineActionFixed; CinemaActionFixedWrapper actionFixedWrapper = itemWrapper as CinemaActionFixedWrapper; actionFixedWrapper.Firetime = actionFixed.Firetime; actionFixedWrapper.Duration = actionFixed.Duration; actionFixedWrapper.InTime = actionFixed.InTime; actionFixedWrapper.OutTime = actionFixed.OutTime; actionFixedWrapper.ItemLength = actionFixed.ItemLength; } else if (itemWrapper.GetType() == (typeof(CinemaActionWrapper))) { TimelineAction action = item as TimelineAction; CinemaActionWrapper actionWrapper = itemWrapper as CinemaActionWrapper; actionWrapper.Firetime = action.Firetime; actionWrapper.Duration = action.Duration; } else { itemWrapper.Firetime = item.Firetime; } } } } // Remove missing track items List <Behaviour> itemRemovals = new List <Behaviour>(); foreach (Behaviour behaviour in trackWrapper.Behaviours) { bool found = false; foreach (TimelineItem item in track.GetTimelineItems()) { if (behaviour.Equals(item)) { found = true; break; } } if (!found || behaviour == null) { itemRemovals.Add(behaviour); } } foreach (Behaviour item in itemRemovals) { trackWrapper.HasChanged = true; trackWrapper.RemoveItem(item); } trackWrapper.IsLocked = track.lockedStatus; } // Remove missing tracks List <Behaviour> removals = new List <Behaviour>(); foreach (Behaviour behaviour in tgWrapper.Behaviours) { bool found = false; foreach (TimelineTrack track in tg.GetTracks()) { if (behaviour.Equals(track)) { found = true; break; } } if (!found || behaviour == null) { removals.Add(behaviour); } } foreach (Behaviour track in removals) { tgWrapper.HasChanged = true; tgWrapper.RemoveTrack(track); } } } return(wrapper); }
public static CutsceneWrapper CreateWrapper(Cutscene cutscene) { CutsceneWrapper wrapper = new CutsceneWrapper(cutscene); if (cutscene != null) { wrapper.RunningTime = cutscene.RunningTime; wrapper.Duration = cutscene.Duration; wrapper.IsPlaying = cutscene.State == Cutscene.CutsceneState.PreviewPlaying || cutscene.State == Cutscene.CutsceneState.Playing; { var __array5 = cutscene.TrackGroups; var __arrayLength5 = __array5.Length; for (int __i5 = 0; __i5 < __arrayLength5; ++__i5) { var tg = (TrackGroup)__array5[__i5]; { TrackGroupWrapper tgWrapper = new TrackGroupWrapper(tg); tgWrapper.Ordinal = tg.Ordinal; wrapper.AddTrackGroup(tg, tgWrapper); { // foreach(var track in tg.GetTracks()) var __enumerator25 = (tg.GetTracks()).GetEnumerator(); while (__enumerator25.MoveNext()) { var track = (TimelineTrack)__enumerator25.Current; { TimelineTrackWrapper trackWrapper = new TimelineTrackWrapper(track); trackWrapper.Ordinal = track.Ordinal; tgWrapper.AddTrack(track, trackWrapper); { // foreach(var item in track.GetTimelineItems()) var __enumerator33 = (track.GetTimelineItems()).GetEnumerator(); while (__enumerator33.MoveNext()) { var item = (TimelineItem)__enumerator33.Current; { if (item.GetType().IsSubclassOf(typeof(CinemaClipCurve))) { CinemaClipCurve clip = item as CinemaClipCurve; CinemaClipCurveWrapper clipWrapper = new CinemaClipCurveWrapper(clip, clip.Firetime, clip.Duration); trackWrapper.AddItem(clip, clipWrapper); } else if (item.GetType().IsSubclassOf(typeof(CinemaTween))) { } else if (item.GetType().IsSubclassOf(typeof(TimelineActionFixed))) { TimelineActionFixed actionFixed = item as TimelineActionFixed; CinemaActionFixedWrapper actionFixedWrapper = new CinemaActionFixedWrapper(actionFixed, actionFixed.Firetime, actionFixed.Duration, actionFixed.InTime, actionFixed.OutTime, actionFixed.ItemLength); trackWrapper.AddItem(actionFixed, actionFixedWrapper); } else if (item.GetType().IsSubclassOf(typeof(TimelineAction))) { TimelineAction action = item as TimelineAction; CinemaActionWrapper itemWrapper = new CinemaActionWrapper(action, action.Firetime, action.Duration); trackWrapper.AddItem(action, itemWrapper); } else { TimelineItemWrapper itemWrapper = new TimelineItemWrapper(item, item.Firetime); trackWrapper.AddItem(item, itemWrapper); } } } } } } } } } } } return(wrapper); }
public static CutsceneWrapper UpdateWrapper(Cutscene cutscene, CutsceneWrapper wrapper) { if (cutscene == null) { return(null); } if (wrapper == null || !cutscene.Equals(wrapper.Behaviour)) { return(CreateWrapper(cutscene)); } else { wrapper.Behaviour = cutscene; wrapper.Duration = cutscene.Duration; wrapper.IsPlaying = cutscene.State == Cutscene.CutsceneState.PreviewPlaying || cutscene.State == Cutscene.CutsceneState.Playing; wrapper.RunningTime = cutscene.RunningTime; List <Behaviour> itemsToRemove = new List <Behaviour>(); { // foreach(var behaviour in wrapper.Behaviours) var __enumerator1 = (wrapper.Behaviours).GetEnumerator(); while (__enumerator1.MoveNext()) { var behaviour = (Behaviour)__enumerator1.Current; { bool found = false; { // foreach(var group in cutscene.TrackGroups) var __enumerator14 = (cutscene.TrackGroups).GetEnumerator(); while (__enumerator14.MoveNext()) { var group = (TrackGroup)__enumerator14.Current; { if (behaviour.Equals(group)) { found = true; break; } } } } if (!found || behaviour == null) { itemsToRemove.Add(behaviour); } } } } { var __list2 = itemsToRemove; var __listCount2 = __list2.Count; for (int __i2 = 0; __i2 < __listCount2; ++__i2) { var trackGroup = (Behaviour)__list2[__i2]; { wrapper.HasChanged = true; wrapper.RemoveTrackGroup(trackGroup); } } } { var __array3 = cutscene.TrackGroups; var __arrayLength3 = __array3.Length; for (int __i3 = 0; __i3 < __arrayLength3; ++__i3) { var tg = (TrackGroup)__array3[__i3]; { TrackGroupWrapper tgWrapper = null; if (!wrapper.ContainsTrackGroup(tg, out tgWrapper)) { tgWrapper = new TrackGroupWrapper(tg); tgWrapper.Ordinal = tg.Ordinal; wrapper.AddTrackGroup(tg, tgWrapper); wrapper.HasChanged = true; } { // foreach(var track in tg.GetTracks()) var __enumerator19 = (tg.GetTracks()).GetEnumerator(); while (__enumerator19.MoveNext()) { var track = (TimelineTrack)__enumerator19.Current; { TimelineTrackWrapper trackWrapper = null; if (!tgWrapper.ContainsTrack(track, out trackWrapper)) { trackWrapper = new TimelineTrackWrapper(track); trackWrapper.Ordinal = track.Ordinal; tgWrapper.AddTrack(track, trackWrapper); tgWrapper.HasChanged = true; } { // foreach(var item in track.GetTimelineItems()) var __enumerator28 = (track.GetTimelineItems()).GetEnumerator(); while (__enumerator28.MoveNext()) { var item = (TimelineItem)__enumerator28.Current; { TimelineItemWrapper itemWrapper = null; if (!trackWrapper.ContainsItem(item, out itemWrapper)) { if (item.GetType().IsSubclassOf(typeof(CinemaClipCurve))) { CinemaClipCurve clip = item as CinemaClipCurve; itemWrapper = new CinemaClipCurveWrapper(clip, clip.Firetime, clip.Duration); trackWrapper.AddItem(clip, itemWrapper); } else if (item.GetType().IsSubclassOf(typeof(CinemaTween))) { CinemaTween tween = item as CinemaTween; itemWrapper = new CinemaTweenWrapper(tween, tween.Firetime, tween.Duration); trackWrapper.AddItem(tween, itemWrapper); } else if (item.GetType().IsSubclassOf(typeof(TimelineActionFixed))) { TimelineActionFixed fixedAction = item as TimelineActionFixed; itemWrapper = new CinemaActionFixedWrapper(fixedAction, fixedAction.Firetime, fixedAction.Duration, fixedAction.InTime, fixedAction.OutTime, fixedAction.ItemLength); trackWrapper.AddItem(fixedAction, itemWrapper); } else if (item.GetType().IsSubclassOf(typeof(TimelineAction))) { TimelineAction action = item as TimelineAction; itemWrapper = new CinemaActionWrapper(action, action.Firetime, action.Duration); trackWrapper.AddItem(action, itemWrapper); } else { itemWrapper = new TimelineItemWrapper(item, item.Firetime); trackWrapper.AddItem(item, itemWrapper); } trackWrapper.HasChanged = true; } else { if (GUIUtility.hotControl == 0) { if (itemWrapper.GetType() == (typeof(CinemaClipCurveWrapper))) { CinemaClipCurve clip = item as CinemaClipCurve; CinemaClipCurveWrapper clipWrapper = itemWrapper as CinemaClipCurveWrapper; clipWrapper.Firetime = clip.Firetime; clipWrapper.Duration = clip.Duration; } else if (itemWrapper.GetType() == (typeof(CinemaTweenWrapper))) { } else if (itemWrapper.GetType() == (typeof(CinemaActionFixedWrapper))) { TimelineActionFixed actionFixed = item as TimelineActionFixed; CinemaActionFixedWrapper actionFixedWrapper = itemWrapper as CinemaActionFixedWrapper; actionFixedWrapper.Firetime = actionFixed.Firetime; actionFixedWrapper.Duration = actionFixed.Duration; actionFixedWrapper.InTime = actionFixed.InTime; actionFixedWrapper.OutTime = actionFixed.OutTime; actionFixedWrapper.ItemLength = actionFixed.ItemLength; } else if (itemWrapper.GetType() == (typeof(CinemaActionWrapper))) { TimelineAction action = item as TimelineAction; CinemaActionWrapper actionWrapper = itemWrapper as CinemaActionWrapper; actionWrapper.Firetime = action.Firetime; actionWrapper.Duration = action.Duration; } else { itemWrapper.Firetime = item.Firetime; } } } } } } // Remove missing track items List <Behaviour> itemRemovals = new List <Behaviour>(); { // foreach(var behaviour in trackWrapper.Behaviours) var __enumerator30 = (trackWrapper.Behaviours).GetEnumerator(); while (__enumerator30.MoveNext()) { var behaviour = (Behaviour)__enumerator30.Current; { bool found = false; { var __array34 = track.GetTimelineItems(); var __arrayLength34 = __array34.Length; for (int __i34 = 0; __i34 < __arrayLength34; ++__i34) { var item = (TimelineItem)__array34[__i34]; { if (behaviour.Equals(item)) { found = true; break; } } } } if (!found || behaviour == null) { itemRemovals.Add(behaviour); } } } } { var __list31 = itemRemovals; var __listCount31 = __list31.Count; for (int __i31 = 0; __i31 < __listCount31; ++__i31) { var item = (Behaviour)__list31[__i31]; { trackWrapper.HasChanged = true; trackWrapper.RemoveItem(item); } } } } } } // Remove missing tracks List <Behaviour> removals = new List <Behaviour>(); { // foreach(var behaviour in tgWrapper.Behaviours) var __enumerator21 = (tgWrapper.Behaviours).GetEnumerator(); while (__enumerator21.MoveNext()) { var behaviour = (Behaviour)__enumerator21.Current; { bool found = false; { // foreach(var track in tg.GetTracks()) var __enumerator32 = (tg.GetTracks()).GetEnumerator(); while (__enumerator32.MoveNext()) { var track = (TimelineTrack)__enumerator32.Current; { if (behaviour.Equals(track)) { found = true; break; } } } } if (!found || behaviour == null) { removals.Add(behaviour); } } } } { var __list22 = removals; var __listCount22 = __list22.Count; for (int __i22 = 0; __i22 < __listCount22; ++__i22) { var track = (Behaviour)__list22[__i22]; { tgWrapper.HasChanged = true; tgWrapper.RemoveTrack(track); } } } } } } } return(wrapper); }