Escape to continue and skip typewriter effect

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
hipsterdufus
Posts: 97
Joined: Thu Aug 12, 2021 6:39 pm

Escape to continue and skip typewriter effect

Post by hipsterdufus »

Hi, I'm just wondering if there may be a simple way to do this - if not, it's nothing to worry about.

In my game the player has to click the continue button to progress the conversation to the next node at which point the typewriter effect starts printing out the contents. If the user clicks again, it will finish the typewriter effect. That's working fine but I was wondering if I could map the escape key to progress to the next node AND immediately finish the typewriter effect in the next node. I notice that the escape key is already tied to cancel conversation which for my game behaves almost exactly like clicking the continue button as far as I can tell - which is fine but I was wondering if I could somehow tweak it to also skip the typewriter immediately instead of having to press escape 2x per node.

Can you point me in the right general direction? Thank you for your time.
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Escape to continue and skip typewriter effect

Post by Tony Li »

Hi,

Making sure I understand. Let's say you have these two nodes:
  • Entry 1: "AAAAAAAA"
  • Entry 2: "BBBBBBBB"
If the conversation is currently typing out "AAAAAAAA" and the player presses Escape, you want it to immediately progress to Entry 2: "BBBBBBBB" and skip the typewriter to the end of "BBBBBBBB"?

If so, you can add a script like this to your Dialogue Manager:

DoubleSkipOnEscape.cs

Code: Select all

using System.Collections;
using UnityEngine;
using PixelCrushers;
using PixelCrushers.DialogueSystem;

public class DoubleSkipOnEscape : MonoBehaviour
{
    private bool fastForwardNextLineTypewriter = false;

    private void Update()
    {
        if (!DialogueManager.isConversationActive) return;
        if (DialogueManager.standardDialogueUI.conversationUIElements.defaultMenuPanel.hasFocus) return;
        if (InputDeviceManager.IsKeyDown(KeyCode.Escape))
        {
            fastForwardNextLineTypewriter = true;
            DialogueManager.standardDialogueUI.OnContinueConversation();
        }
    }

    void OnConversationLine(Subtitle subtitle)
    {
        if (fastForwardNextLineTypewriter)
        {
            fastForwardNextLineTypewriter = false;
            StartCoroutine(FastForwardTypewriterAtEndOfFrame());
        }
    }

    IEnumerator FastForwardTypewriterAtEndOfFrame()
    {
        yield return new WaitForEndOfFrame(); // Wait until next line has started typing.
        foreach (var subtitlePanel in DialogueManager.standardDialogueUI.conversationUIElements.subtitlePanels)
        {
            if (!subtitlePanel.hasFocus) continue;
            TypewriterUtility.GetTypewriter(subtitlePanel.subtitleText).Stop();
        }
    }

    void OnConversationEnd(Transform actor)
    {
        fastForwardNextLineTypewriter = false;
    }

}
hipsterdufus
Posts: 97
Joined: Thu Aug 12, 2021 6:39 pm

Re: Escape to continue and skip typewriter effect

Post by hipsterdufus »

Thanks, I was able to get it working - I had to do it a little differently because I'm using TextAnimator typewriter but the coroutine to skip at the next frame seems to work.

Just to document exactly what I did -

I just get a reference to the typewriter at the start of the game and have a script that checks if it's in progress when esc is pushed, if so - finish it, if it's already finished call OnContinueConversation and start the coroutine to skip the typewriter next frame.

I also had a UIButtonKeyTrigger component on my continue button that was mapped to escape that I had to disable so that escape would not continue the conversation twice.
Post Reply