Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Advance Time to end of clip

Discussion in 'Timeline' started by Backroll, Sep 26, 2018.

  1. Backroll

    Backroll

    Joined:
    Aug 10, 2012
    Posts:
    6
    I have a cutscene dialog system set up using a modified version of the TMPTextSwitcher clip. Lines of dialog are set up sequentially in the timeline.

    Problem: When the user taps, I want to advance the timeline to the end of the currently playing clip and pause the timeline at that point. I can't figure out how to calculate the endpoint for the currently displaying clip at runtime.

    Thanks for any help!
     
  2. Backroll

    Backroll

    Joined:
    Aug 10, 2012
    Posts:
    6
    Figured out how to do this

    In TrackAsset subclass, stash the timing info into a singleton before playing:
    Code (CSharp):
    1. public class TMPTextSwitcherTrack : TrackAsset {
    2.   public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount) {
    3.     CutsceneManager.Inst.clipTimings = GetClips().Select(c => new Tuple<double, double>(c.start, c.end)).ToArray();
    4.     return ScriptPlayable<TMPTextSwitcherMixerBehaviour>.Create(graph, inputCount);
    5.   }
    6. ...
    In my singleton manager class, run through the timing infos and advance to that point
    Code (CSharp):
    1.   public static void Click() {
    2.     switch (Inst.Mode) {
    3.       case CutsceneManagerMode.Playing:
    4.         var t = Inst.Director.time;
    5.         foreach (var timing in Inst.clipTimings) {
    6.           if (t >= timing.Item1 && t < timing.Item2) {
    7.             Inst.Director.time = timing.Item2;
    8.             PauseTimeline();
    9.             break;
    10.           }
    11.         }
    12.         break;
    13. ...