void ConvertBeatToControlTrack(Beat beat, int index) { ControlTrack track = TimelineAsset.CreateTrack <ControlTrack>(null, "Collectible_" + index); TimelineAsset timelineAsset = CollectiblePrefab.GetComponent <PlayableDirector>().playableAsset as TimelineAsset; TimelineClip clip = track.CreateDefaultClip(); clip.start = beat.BeatStart * (60f / Track.BPM / ((float)Track.TrackSpeed / 4f)); float beatDuration = ((beat.BeatEnd - beat.BeatStart) * (60f / Track.BPM / ((float)Track.TrackSpeed / 4f))); float collectibleDuration = (float)timelineAsset.duration; clip.timeScale = timelineAsset.duration / beatDuration; clip.duration = beatDuration; ControlPlayableAsset controlPlayableAsset = clip.asset as ControlPlayableAsset; controlPlayableAsset.sourceGameObject.exposedName = UnityEditor.GUID.Generate().ToString(); switch (beat.BeatLocation) { case BeatLocation.Center: PlayableDirector.SetReferenceValue(controlPlayableAsset.sourceGameObject.exposedName, CenterZone); break; case BeatLocation.North: PlayableDirector.SetReferenceValue(controlPlayableAsset.sourceGameObject.exposedName, NorthZone); break; case BeatLocation.South: PlayableDirector.SetReferenceValue(controlPlayableAsset.sourceGameObject.exposedName, SouthZone); break; case BeatLocation.East: PlayableDirector.SetReferenceValue(controlPlayableAsset.sourceGameObject.exposedName, EastZone); break; case BeatLocation.West: PlayableDirector.SetReferenceValue(controlPlayableAsset.sourceGameObject.exposedName, WestZone); break; } controlPlayableAsset.prefabGameObject = CollectiblePrefab; controlPlayableAsset.updateParticle = false; controlPlayableAsset.updateITimeControl = false; controlPlayableAsset.updateDirector = true; }
public void BuildTimeline() { Debug.Log("Buidilng Timeline"); TimelineAsset timelineAsset = (TimelineAsset)timeline.playableAsset; //TODO: make it so that it deletes all tracks and rebuilds them every each time for (int i = 0; i < timelineAsset.rootTrackCount; i++) { timelineAsset.DeleteTrack(timelineAsset.GetRootTrack(0)); } for (int i = 0; i < timelineAsset.outputTrackCount; i++) { timelineAsset.DeleteTrack(timelineAsset.GetOutputTrack(0)); } ControlTrack controlTrack = (ControlTrack)timelineAsset.CreateTrack(typeof(ControlTrack), null, "Control Track"); clipToTime = new Dictionary <ClipSettings, double>(); // map all timeline clips first for (int i = 0; i < timelineClips.Count; i++) { TimelineClip tc = controlTrack.CreateDefaultClip(); ControlPlayableAsset cpa = tc.asset as ControlPlayableAsset; cpa.sourceGameObject.exposedName = UnityEditor.GUID.Generate().ToString(); timeline.SetReferenceValue(cpa.sourceGameObject.exposedName, timelineClips[i].timelineTrack.gameObject); if (i != 0) { tc.start = tc.start + 1; } clipToTime.Add(timelineClips[i], tc.start); tc.duration = timelineClips[i].timelineTrack.duration; } //map remix clips int j = 0; foreach (TimelineClip tc in controlTrack.GetClips()) { foreach (TriggerMapping triggerMapping in timelineClips[j].triggers) { TimeMachineTrack timeMachineTrack = (TimeMachineTrack)timelineAsset.CreateTrack(typeof(TimeMachineTrack), null, "Trigger Track"); if (triggerMapping.type == TriggerType.CONTINUOUS) { TimelineClip triggerCip = timeMachineTrack.CreateDefaultClip(); TimeMachineAsset tma = triggerCip.asset as TimeMachineAsset; tma.action = TimeMachineBehavior.TimeMachineAction.JumpToTime; tma.condition = TimeMachineBehavior.Condition.TriggerOff; tma.timeToJumpTo = (float)clipToTime[triggerMapping.targetTrack]; triggerCip.start = tc.start; triggerCip.duration = tc.duration; tma.trigger.exposedName = UnityEditor.GUID.Generate().ToString(); // tma.timeToJumpTo = triggerMapping.timeToJumpTo; timeline.SetReferenceValue(tma.trigger.exposedName, triggerMapping.trigger); } else { TimelineClip triggerCip = timeMachineTrack.CreateDefaultClip(); TimeMachineAsset tma = triggerCip.asset as TimeMachineAsset; tma.action = TimeMachineBehavior.TimeMachineAction.JumpToTime; tma.condition = TimeMachineBehavior.Condition.TriggerOff; tma.timeToJumpTo = (float)clipToTime[triggerMapping.targetTrack]; triggerCip.start = tc.end; triggerCip.duration = 1; tma.trigger.exposedName = UnityEditor.GUID.Generate().ToString(); timeline.SetReferenceValue(tma.trigger.exposedName, triggerMapping.trigger); } } j++; } Debug.Log("Finished"); }