Skip/Auto Button Help

Announcements, support questions, and discussion for the Dialogue System.
User avatar
HawkX
Posts: 147
Joined: Mon Feb 27, 2017 1:50 pm
Location: Quebec
Contact:

Skip/Auto Button Help

Post by HawkX »

Hi Tony!

Hope you are doing well!

This time, I'm trying to create two "toggle" buttons... Auto and Skip...

I did do a search on your forums first and came upon a 2015 thread about someone wanting to do something "similar"... I was tempted to necro it but the original author might not have appreciated the hijack so i made a new one ;)
Here is the thread if you want to see what I already read through :
viewtopic.php?f=3&t=337&p=1894

at the very end, you write this line of code :

Code: Select all

DialogueManager.DisplaySettings.subtitleSettings.continueButton = DisplaySettings.SubtitleSettings.ContinueButtonMode.Never; 
I tried entering that line in my project, but it does not recognize "subtitleSettings" in DialogueManager.DisplaySettings...
is there an aditional "using PixelCrushers.DialogueSystem;" line that needs to be added to manage settings?

I only want a button that "toggle on/off" the need for the continue button...


ALSO, I am looking for an actual skip button... that just skip the conversation altogether... without any check...

Would it be appropriate to simply use DialogueManager.StopConversation(); mapped on a separate button that i put in the canvas ui of the dialogue? That seems to be the easiest way to do it...

EDIT : I just made a button that did just that... and so far it seems to work perfectly :)
so only need the answer for the "auto/continue - toggle" button now


Thank you as always for your time and have a nice day!
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip/Auto Button Help

Post by Tony Li »

Hi,

Here's an example that toggles the continue button mode on and off:

ToggleContinueModeExample_2017-03-14.unitypackage

It uses a small script that I added to the Dialogue Manager:

ToggleContinue.cs

Code: Select all

using UnityEngine;
using System.Reflection;
using PixelCrushers.DialogueSystem;

// To add a button to toggle continue button mode, add this script to the 
// Dialogue Manager. Then connect the button's OnClick() event to 
// ToggleContinue.ToggleContinueMode.
public class ToggleContinue : MonoBehaviour {

    public void ToggleContinueButtonMode()
    {
        // Toggle modes:
        var oldMode = DialogueManager.DisplaySettings.subtitleSettings.continueButton;
        var newMode = (oldMode == DisplaySettings.SubtitleSettings.ContinueButtonMode.Always) ? DisplaySettings.SubtitleSettings.ContinueButtonMode.Never
            : DisplaySettings.SubtitleSettings.ContinueButtonMode.Always;
        DialogueManager.DisplaySettings.subtitleSettings.continueButton = newMode;
        if (DialogueManager.ConversationView != null) DialogueManager.ConversationView.SetupContinueButton();

        // If turning continue mode off and the sequence is already done, auto-continue.
        if (DialogueManager.IsConversationActive && newMode == DisplaySettings.SubtitleSettings.ContinueButtonMode.Never)
        {
            var sequencer = typeof(ConversationView).GetField("sequencer", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(DialogueManager.ConversationView) as Sequencer;
            if (!sequencer.IsPlaying) DialogueManager.Instance.BroadcastMessage("OnContinue", SendMessageOptions.DontRequireReceiver);
        }
    }
}
The on/off UI button calls this script's ToggleContinueButtonMode() method.

[EDITS: Updated script to accommodate issue noted below, and to check if conversation is active.]

The example also has a Stop Conversation button that works exactly the same way as you described.
User avatar
HawkX
Posts: 147
Joined: Mon Feb 27, 2017 1:50 pm
Location: Quebec
Contact:

Re: Skip/Auto Button Help

Post by HawkX »

Awesome thanks again for a perfect answer! :)

You really did not have to go through the trouble of making a unitypackage for me though! Just the code worked perfectly! :)

Quick question now ;) hehe...

Is there a way to manage (increase/decrease) the time it waits until it continue to the next line? (seeing as I dont have voice over, some lines finished writing and skipped directly to the next one... I would have liked a 1 or 2 sec buffer for the player to finish reading before it auto skipped to the next)
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip/Auto Button Help

Post by Tony Li »

Hi,

Set the Dialogue Manager's Subtitle Settings > Min Subtitle Seconds and Subtitle Chars Per Second.

When continue button mode is off, the subtitle is guaranteed to stay onscreen for at least Min Subtitle Seconds.

If the subtitle text is long, though, it will use Subtitle Chars Per Second. For example, if the text is 90 characters and Subtitle Chars Per Second is 30, the subtitle will be onscreen for 90 / 30 = 3 seconds.
User avatar
HawkX
Posts: 147
Joined: Mon Feb 27, 2017 1:50 pm
Location: Quebec
Contact:

Re: Skip/Auto Button Help

Post by HawkX »

awww that really sucks (no offense)...

that was the exact scenario i wanted to avoid...

having a "minimum" 3sec is good when you have short lines... but when you have a much longer line and it goes over that threshold, its really bad that it skips ahead as soon as the final character is typed... it should have a minimum wait time instead of a minimum subtitle time...
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip/Auto Button Help

Post by Tony Li »

Easy enough to do!

Min Subtitle Seconds and Subtitle Chars Per Second actually just set the value of a keyword "{{end}}" that you can use in sequences. For example, the basic Dialogue Manager prefab's Default Sequence is:

Code: Select all

Delay({{end}})
This waits for a duration based on the length of the subtitle text. You can just as easily specify an absolute time, such as:

Code: Select all

Delay(5)
It's important to note that the Dialogue Manager's Subtitle Chars Per Second is separate from the typewriter effect's Chars Per Second. You can set the typewriter to, say, 50 characters per second, and the Dialogue Manager's Subtitle Chars Per Second to 30 (slower). This means the typewriter will always finish before the subtitle duration is over.

Here's an example:
  • Let's say your text is 120 characters.
  • Subtitle Chars Per Second is 30. This means {{end}} will be 120/30 = 4 seconds.
  • The typewriter effect's Chars Per Second is 60. This means the typewriter will finish in 120/60 = 2 seconds.
So the completely typed-out text will be visible for 2 seconds after the typewriter finishes. However, this scales based on the length of the text. For example:
  • Let's say your text is 240 characters.
  • Subtitle Chars Per Second is 30. This means {{end}} will be 240/30 = 8 seconds.
  • The typewriter effect's Chars Per Second is 60. This means the typewriter will finish in 240/60 = 4 seconds.
In this case, the completely typed-out text will be visible for 4 seconds. (Note: This assumes you're not waiting for a continue button click. The timing of the continue button is entirely up to how long the player waits before clicking it.)

This scaled delay may be exactly what you want. However, if you always want to wait, say, 3 seconds after the typewriter, use this sequence instead:

Code: Select all

Delay(3)@{{end}}
And set the typewriter's Chars Per Second to the same value as the Dialogue Manager's Subtitle Chars Per Second.

The "@" format tells a sequencer command to run at a specified time -- in this case, at the end of the chars per second / typewriter value. The Delay command kicks off at that time and delays for 3 more second.
User avatar
HawkX
Posts: 147
Joined: Mon Feb 27, 2017 1:50 pm
Location: Quebec
Contact:

Re: Skip/Auto Button Help

Post by HawkX »

OH WOW! that was exactly what i wanted! :)

(that very last 3 sec always part)

my only question for that last part is : Where do i enter that line? :) hehe... sorry still learning!
Delay(3)@{{end}}


Also, while implementing the "auto" button, i noticed that "IF" the {{end}} is already passed when auto is activated, it wont ever skip to the next text and the continue button vanish (which is fine), but it would be nice to add a little condition if end is passed to do a single "continue" when clicking auto... ;)


Once more, THANK you for being so amazing!! I mean it... you surprise me every time! :) I wish all consumer service/help were as great!
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip/Auto Button Help

Post by Tony Li »

My pleasure!

And good catch! I updated the script in my post above to handle the case you described, and I also updated the example scene.
User avatar
HawkX
Posts: 147
Joined: Mon Feb 27, 2017 1:50 pm
Location: Quebec
Contact:

Re: Skip/Auto Button Help

Post by HawkX »

I keep being impressed by how quick and efficient you are! ;)

at first I thought you might have made a mistake in your update... I just tested it and it works! Its the way the comment is written...
// If turning continue mode off and the sequence is already done, auto-continue.
I might be easier to understand with "If turning auto mode "on"" instead of turning continue off... ;)

However, when i tested it, I noticed when clicking the auto mode on, for about 2 frames I saw the next line fully typed before it went away for the typewriter effect to start... anyway to prevent that?


On another subject, the other day, I was reading unity answers for something else, saw a really great answer, kept reading on... and the post right below was "Thanks Tony"... I immediately scrolled up and saw it was your answer I had just been reading! Quite funny :)
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip/Auto Button Help

Post by Tony Li »

HawkX wrote:...I noticed when clicking the auto mode on, for about 2 frames I saw the next line fully typed before it went away for the typewriter effect to start... anyway to prevent that?
I'll look into it. It may take me a couple days to straighten it out.
HawkX wrote:On another subject, the other day, I was reading unity answers for something else, saw a really great answer, kept reading on... and the post right below was "Thanks Tony"... I immediately scrolled up and saw it was your answer I had just been reading! Quite funny :)
I leaned on Unity Answers so much when first getting to grips with Unity. I'm glad when I can help return the favors, although many of my answers are probably quite outdated by now.
Post Reply