[HOWTO] How To: Pause Timeline While Waiting For Continue Button

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 23102
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Pause Timeline While Waiting For Continue Button

Post by Tony Li »

To make the timeline pause while it waits for a continue button click and then resume the timeline after clicking continue, you'll need to replace the StandardUIContinueButtonFastForward component on your continue button with a subclass:

ContinueButtonResumeTimeline.cs

Code: Select all

using UnityEngine;
using UnityEngine.Playables;
using PixelCrushers.DialogueSystem;

public class ContinueButtonResumeTimeline : StandardUIContinueButtonFastForward
{

    public override void OnFastForward()
    {
        if ((typewriterEffect != null) && typewriterEffect.isPlaying)
        {
            typewriterEffect.Stop();
        }
        else
        {
            ResumeTimeline();
        }
    }

    private void ResumeTimeline()
    {
        // Assumes current line's Sequence start with "Timeline(speed, TIMELINENAME, 0)"
        // where "TIMELINENAME" is the name of a PlayableDirector GameObject.
        var sequence = DialogueManager.currentConversationState.subtitle.sequence;
        if (sequence.Contains("Timeline(speed"))
        {
            // Get the timeline name:
            var pos = sequence.IndexOf(',');
            var s = sequence.Substring(pos + 1);
            pos = s.IndexOf(',');
            s = s.Substring(0, pos).Trim();
            // Resume the timeline:
            var subject = SequencerTools.FindSpecifier(s);
            var playableDirector = (subject != null) ? subject.GetComponent<PlayableDirector>() : null;
            if (playableDirector != null)
            {
                if (DialogueDebug.logInfo) Debug.Log($"Dialogue System: Resuming timeline {playableDirector}", playableDirector);
                playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(1);
                //---DialogueManager.standardDialogueUI.HideSubtitle(DialogueManager.currentConversationState.subtitle);
                return;
            }
        }
        // If we don't resume the timeline, just advance the conversation:
        base.OnFastForward();
    }

}
Hook up the continue button's OnClick() to this script's OnFastForward() method.

This subclass checks the current dialogue entry's Sequence for a command "Timeline(speed, TIMELINENAME..." where TIMELINENAME is the name of the timeline/playable director. It then resumes the timeline instead of continuing the conversation immediately.

You can leave your dialogue entries' Sequence fields blank. Instead, inspect the conversation's properties (Menu > Conversation Properties) and tick Override Display Settings > Camera Settings. Set Sequence to:

Code: Select all

Timeline(speed, TIMELINENAME 0)
where TIMELINENAME is the name of your timeline.

Add Continue Conversation clips when you'd like the conversation to continue.

If you also want to hide the current subtitle text when the player clicks continue, you can uncomment the line in the script that's commented out with "//---".
Post Reply