Ejemplo n.º 1
0
    public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
    {
        var scriptPlayable = ScriptPlayable <TimeMachineMixer> .Create(graph, inputCount);

        TimeMachineMixer b = scriptPlayable.GetBehaviour();

        b.markerClips = new System.Collections.Generic.Dictionary <string, double>();


        //This foreach will rename clips based on what they do, and collect the markers and put them into a dictionary
        //Since this happens when you enter Preview or Play mode, the object holding the Timeline must be enabled or you won't see any change in names
        foreach (var c in GetClips())
        {
            TimeMachineAsset clip     = (TimeMachineAsset)c.asset;
            string           clipName = c.displayName;

            switch (clip.action)
            {
            case TimeMachineBehavior.TimeMachineAction.Pause:
                clipName = "||";
                break;

            case TimeMachineBehavior.TimeMachineAction.Marker:
                clipName = "● " + clip.markerLabel.ToString();

                //Insert the marker clip into the Dictionary of markers
                if (!b.markerClips.ContainsKey(clip.markerLabel))     //happens when you duplicate a clip and it has the same markerLabel
                {
                    b.markerClips.Add(clip.markerLabel, (double)c.start);
                }
                break;

            case TimeMachineBehavior.TimeMachineAction.JumpToMarker:
                clipName = "↩︎  " + clip.markerToJumpTo.ToString();
                break;

            case TimeMachineBehavior.TimeMachineAction.JumpToTime:
                clipName = "↩ " + clip.timeToJumpTo.ToString();
                break;
            }

            c.displayName = clipName;
        }

        return(scriptPlayable);
    }
Ejemplo n.º 2
0
    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");
    }