Page 1 of 2
Skip button
Posted: Thu Dec 21, 2017 4:51 am
by davidsibya08
It's been a long time since my last post.
It's good to be back.
Sir Tony Li,
I know it would be possible so I would just like to ask on how
would I make a skip button?
I would prefer it to be like when a conversation starts, aside from the continue button
there would be a skip button that allows me to skip what the NPC is saying. Upon skipping, I want to
be stopped on choosing choices only (if there is need). Then, back the NPC dialogue and
another skip and continue button (just a loop).
As along as there is a choice that I could skip what the NPC is saying.
Thanks in advance sir Tony!
Re: Skip button
Posted: Thu Dec 21, 2017 3:29 pm
by Tony Li
Hi David!
Here's an example scene:
SkipButtonExample_2017-12-21.unitypackage
It uses a script named SkipButton. Add this script to your Dialogue Manager. Then create a Skip button, and set the button's OnClick() event to SkipButton.SkipToResponseMenu.
The script is below, too:
SkipButton.cs
Code: Select all
using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;
public class SkipButton : MonoBehaviour
{
public bool skip;
private AbstractDialogueUI dialogueUI;
private void Awake()
{
dialogueUI = GetComponentInChildren<AbstractDialogueUI>();
}
public void SkipToResponseMenu()
{
skip = true;
dialogueUI.OnContinue();
}
void OnConversationLine(Subtitle subtitle)
{
if (skip) StartCoroutine(ContinueAtEndOfFrame());
}
IEnumerator ContinueAtEndOfFrame()
{
yield return new WaitForEndOfFrame();
dialogueUI.OnContinue();
}
void OnConversationResponseMenu(Response[] responses)
{
skip = false;
}
}
Re: Skip button
Posted: Thu Dec 21, 2017 3:30 pm
by Tony Li
Now that I think about it, you'll probably want to add this method to the script:
Code: Select all
void OnConversationEnd(Transform actor)
{
skip = false;
}
This turns off the skip when the conversation ends, so it doesn't skip when you start a new conversation.
Re: Skip button
Posted: Tue Dec 26, 2017 10:51 pm
by davidsibya08
Alright! Thanks sir Tony! I'll try this sooner or later when I'm back home.
Still in a vacation! Hope your having a great holiday!
Thanks again!
Re: Skip button
Posted: Wed Dec 27, 2017 8:17 am
by Tony Li
Sounds good. Enjoy your vacation!
Re: Skip button
Posted: Wed Dec 27, 2017 10:04 am
by Abelius
Sorry for highjacking the thread, but I've stolen this little nice script for my new VN-style project, he he...
And yes, it's working beautifully!
I have one question though, to further "enhance" the feature.
How could a little delay be added, so instead of skipping blazingly fast, every frame, it sends DialogueUI.OnContinue() after a configurable amount of time?
What I'd like to see is the dialogue skipping very fast, but not so fast that the next thing I see after clicking the button is the next Response panel.
Could this be easily added to the script? Or it would be going too far?
Re: Skip button
Posted: Wed Dec 27, 2017 10:30 am
by Tony Li
You could change the ContinueAfterOneFrame method to ContinueAfterShortDelay, something like:
Code: Select all
IEnumerator ContinueAfterShortDelay()
{
yield return new WaitForSeconds(1); // Skip ahead after a 1-second delay.
dialogueUI.OnContinue();
}
However, a few other devs have implemented a fast-forward instead. To do this, they set the subtitle line's typewriter effect to a really fast value, like 200 characters per second, and set the Dialogue Manager's Subtitle Settings to skip ahead quickly. Something like:
Code: Select all
using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;
public class SkipButton : MonoBehaviour
{
private float minSubtitleSeconds = 2;
private float subtitleCharsPerSec = 30;
private float typewriterCharsPerSec = 50;
private UnityUIDialogueUI dialogueUI;
private UnityUITypewriterEffect typewriter;
private void Awake()
{
dialogueUI = GetComponentInChildren<UnityUIDialogueUI>();
typewriter = dialogueUI.dialogue.npcSubtitle.line.GetComponent<UnityUITypewriterEffect>();
}
public void SkipToResponseMenu()
{
skip = true;
// Save original values:
minSubtitleSeconds = DialogueManager.DisplaySettings.subtitleSettings.minSubtitleSeconds;
subtitleCharsPerSec = DialogueManager.DisplaySettings.subtitleSettings.subtitleCharsPerSeconds;
typewriterCharsPerSec = typewriter.charactersPerSecond;
// Set values to fast forward:
typewriter.charactersPerSecond = 200;
DialogueManager.DisplaySettings.subtitleSettings.subtitleCharsPerSecond = 200;
DialogueManager.DisplaySettings.subtitleSettings.minSubtitleSeconds = 0;
DialogueManager.DisplaySettings.subtitleSettings.continueButton = ContinueButtonMode.Never;
// Skip this line:
dialogueUI.OnContinue();
}
void OnConversationResponseMenu(Response[] responses)
{
// Set original values:
typewriter.charactersPerSecond = typewriterCharsPerSec;
DialogueManager.DisplaySettings.subtitleSettings.subtitleCharsPerSecond = subtitleCharsPerSec;
DialogueManager.DisplaySettings.subtitleSettings.minSubtitleSeconds = minSubtitleSeconds;
DialogueManager.DisplaySettings.subtitleSettings.continueButton = ContinueButtonMode.Always;
}
}
This script plays the typewriter at 200 characters per second, automatically skipping ahead as soon as the typewriter finishes. When it gets to a response menu, it reverts to the original subtitle settings.
Re: Skip button
Posted: Fri Dec 29, 2017 8:35 am
by Abelius
Nice! I like the simplicity of the first solution, and it's working exactly as I envisioned so, thanks!
Re: Skip button
Posted: Fri Dec 29, 2017 10:17 am
by Tony Li
Glad to help!
Re: Skip button
Posted: Sun Jan 07, 2018 10:23 am
by davidsibya08
Good day Sir Tony.
Now, for my new question.
I believe there is a way to have a previous button for the conversations.
So, I would like to ask how would I do it?
I just wanted to have a previous button so that user
can review the previous dialogue that the user
might have continued accidentally.
Thank you sir!