[HOWTO] How To: Auto Play / Skip To Player Response

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

[HOWTO] How To: Auto Play / Skip To Player Response

Post by Tony Li »

To add "Auto Play" and/or "Skip All" buttons that advances the current conversation:

1. Add the script below to your project, and add it to the dialogue UI. NOTE: This script is now included in the Dialogue System asset itself.

2. Add Auto Play and/or Skip All buttons to your subtitle panel(s). Configure their OnClick() events to call the dialogue UI's ConversationControl.ToggleAutoPlay and/or ConversationControl.SkipAll methods.

ToggleAutoPlay toggles between requiring continue button clicks or auto-advancing without waiting for the player to click a continue button.

SkipAll fast-forwards through all lines until the conversation reaches a player response menu or the end of the conversation.


Example scene: (includes script below)

DS_SkipAllExample_2021-04-04a.unitypackage
ConversationControl.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

/// <summary>
/// Provides AutoPlay and SkipAll functionality.
/// </summary>
[RequireComponent(typeof(AbstractDialogueUI))]
public class ConversationControl : MonoBehaviour // Add to dialogue UI. Connect to Skip All and Auto Play buttons.
{
    public bool skipAll;

    private AbstractDialogueUI dialogueUI;

    private void Awake()
    {
        dialogueUI = GetComponent<AbstractDialogueUI>();
    }

    public void ToggleAutoPlay()
    {
        var mode = DialogueManager.displaySettings.subtitleSettings.continueButton;
        var newMode = (mode == DisplaySettings.SubtitleSettings.ContinueButtonMode.Never) ? DisplaySettings.SubtitleSettings.ContinueButtonMode.Always : DisplaySettings.SubtitleSettings.ContinueButtonMode.Never;
        DialogueManager.displaySettings.subtitleSettings.continueButton = newMode;
        if (newMode == DisplaySettings.SubtitleSettings.ContinueButtonMode.Never) dialogueUI.OnContinueConversation();
    }

    public void SkipAll()
    {
        skipAll = true;
        dialogueUI.OnContinueConversation();
    }

    void OnConversationStart(Transform actor)
    {
        skipAll = false;
    }

    void OnConversationLine(Subtitle subtitle)
    {
        if (skipAll)
        {
            subtitle.sequence = "Continue()";
        }
    }

    void OnConversationResponseMenu(Response[] responses)
    {
        if (skipAll)
        {
            skipAll = false;
            dialogueUI.ShowSubtitle(DialogueManager.currentConversationState.subtitle);
        }
    }
}
Post Reply