Delay after Response Menu submitted

Announcements, support questions, and discussion for the Dialogue System.
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Delay after Response Menu submitted

Post by fkkcloud »

Hi,

This is how I actually put it in, it does not do the delay for me. Anything that I am missing?

Code: Select all

public class DelayOnContinue : MonoBehaviour
{    
    public void ContinueAfterDelay(float delay)
    {
        StartCoroutine(ContinueAfterDelayCoroutine(delay));
    }
    
    IEnumerator ContinueAfterDelayCoroutine(float delay)
    {
        yield return new WaitForSeconds(delay);
        GetComponentInParent<PixelCrushers.DialogueSystem.AbstractDialogueUI>().OnContinueConversation();
    }
}
화면 캡처 2020-11-25 071028.png
화면 캡처 2020-11-25 071028.png (26.96 KiB) Viewed 660 times
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: Delay after Response Menu submitted

Post by Tony Li »

Remove the second event handler (StandardUIContinueButtonFastForward.OnFastForward).

If you want the fast-forward functionality, copy that part of the StandardUIContinueButtonFastForward script into your DelayOnContinue script.
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Delay after Response Menu submitted

Post by fkkcloud »

Now, it is kind of doing Continue() twice each time.

Code: Select all

public class ContinueButtonDelay : MonoBehaviour
{
    public PixelCrushers.DialogueSystem.StandardUIContinueButtonFastForward buttonFastForward;

    public void ContinueAfterDelay(float delay)
    {
        StartCoroutine(ContinueAfterDelayCoroutine(delay));
    }
    
    IEnumerator ContinueAfterDelayCoroutine(float delay)
    {
        yield return new WaitForSeconds(delay);

        
        GetComponentInParent<PixelCrushers.DialogueSystem.AbstractDialogueUI>().OnContinueConversation();
        buttonFastForward.OnFastForward();
    }

}
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: Delay after Response Menu submitted

Post by Tony Li »

If you only want the continue button to continue after a delay, don't call OnFastForward at all. Remove the StandardUIContinueButtonFastForward component. By calling OnContinueConversation() and then calling OnFastForward(), you're continuing twice. Change the script to this: (I also added a safeguard to prevent the player from clicking the continue button again while it's delaying.)
ContinueButtonDelay.cs

Code: Select all

public class ContinueButtonDelay : MonoBehaviour
{
    private Coroutine currentCoroutine = null;
    
    public void ContinueAfterDelay(float delay)
    {
        if (currentCoroutine == null)
        {
            currentCoroutine = StartCoroutine(ContinueAfterDelayCoroutine(delay));
        }
    }
    
    IEnumerator ContinueAfterDelayCoroutine(float delay)
    {
        yield return new WaitForSeconds(delay);
        currentCoroutine = null;
        GetComponentInParent<PixelCrushers.DialogueSystem.AbstractDialogueUI>().OnContinueConversation();
    }
}
If you want to fast forward the typewriter and then delay, change the script to:
ContinueButtonDelay.cs

Code: Select all

public class ContinueButtonDelay : MonoBehaviour
{
    public AbstractTypewriterEffect typewriterEffect; //<-- ASSIGN IN INSPECTOR.
    
    private Coroutine currentCoroutine = null;
    
    public void ContinueAfterDelay(float delay)
    {
        if (currentCoroutine == null)
        {
            currentCoroutine = StartCoroutine(ContinueAfterDelayCoroutine(delay));
        }
    }
    
    IEnumerator ContinueAfterDelayCoroutine(float delay)
    {
        if ((typewriterEffect != null) && typewriterEffect.isPlaying) typewriterEffect.Stop();
        yield return new WaitForSeconds(delay);
        currentCoroutine = null;
        GetComponentInParent<PixelCrushers.DialogueSystem.AbstractDialogueUI>().OnContinueConversation();
    }
}
If you want to only fast forward the first time the player clicks the continue button, and then delay on the second time the player clicks the button, change the script to the version below, and configure the button's OnClick() event to call its OnFastForward() method. Also assign the subtitle text.
CustomContinueButtonFastForward.cs

Code: Select all

public class CustomContinueButtonFastForward : StandardUIContinueButtonFastForward
{
    private Coroutine currentCoroutine = null;
    
    public override void OnFastForward()
    {
        if ((typewriterEffect != null) && typewriterEffect.isPlaying)
        {
            base.OnFastForward(); // Just fast forward typewriter.
        }
        else
        {
            if (currentCoroutine == null)
            {
                currentCoroutine = StartCoroutine(ContinueAfterDelayCoroutine(delay));
            }
        }
    }
    
    IEnumerator ContinueAfterDelayCoroutine(float delay)
    {
        yield return new WaitForSeconds(delay);
        currentCoroutine = null;
        GetComponentInParent<PixelCrushers.DialogueSystem.AbstractDialogueUI>().OnContinueConversation();
    }
}
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Delay after Response Menu submitted

Post by fkkcloud »

Last one seems like the most right fit for me but it would not dismiss the subtitle of the Player during the delay, right?
Ultimately, what I need is:

first click
- fast forward the typewriter effect
second click
- committing continue
- player subtitle dismiss right away at this point
- delay of X second here
-after X second, NPC subtitle continues (or any other next node)
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: Delay after Response Menu submitted

Post by Tony Li »

In that case, you could check if the current subtitle is PC or NPC. If it's PC, continue immediately. If it's NPC, delay then continue.
CustomContinueButtonFastForward.cs

Code: Select all

public class CustomContinueButtonFastForward : StandardUIContinueButtonFastForward
{
    private Coroutine currentCoroutine = null;
    
    public override void OnFastForward()
    {
        if ((typewriterEffect != null) && typewriterEffect.isPlaying)
        {
            base.OnFastForward(); // Just fast forward typewriter.
        }
        else
        {
            if (DialogueManager.currentConversationState.subtitle.speakerInfo.isPlayer)
            {
                GetComponentInParent<PixelCrushers.DialogueSystem.AbstractDialogueUI>().OnContinueConversation();
            }
            else if (currentCoroutine == null)
            {
                currentCoroutine = StartCoroutine(ContinueAfterDelayCoroutine(delay));
            }
        }
    }
    
    IEnumerator ContinueAfterDelayCoroutine(float delay)
    {
        yield return new WaitForSeconds(delay);
        currentCoroutine = null;
        GetComponentInParent<PixelCrushers.DialogueSystem.AbstractDialogueUI>().OnContinueConversation();
    }
}
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Delay after Response Menu submitted

Post by fkkcloud »

I modified your code to this below, but still missing one thing.

Code: Select all

public class CustomContinueButtonFastForward : StandardUIContinueButtonFastForward
{
    private Coroutine currentCoroutine = null;

    public float delay;
    
    public override void OnFastForward()
    {
        if ((typewriterEffect != null) && typewriterEffect.isPlaying)
        {
            base.OnFastForward(); // Just fast forward typewriter.
        }
        else
        {
            if (DialogueManager.currentConversationState.subtitle.speakerInfo.isPlayer)
            {
                if (currentCoroutine == null)
                {
                    currentCoroutine = StartCoroutine(ContinueAfterDelayCoroutine(delay));
                }
            }
        }
    }
    

    IEnumerator ContinueAfterDelayCoroutine(float delay)
    {
        yield return new WaitForSeconds(delay);
        currentCoroutine = null;
        GetComponentInParent<PixelCrushers.DialogueSystem.AbstractDialogueUI>().OnContinueConversation();
    }
}
I want the delay to happen after the Player DIalogue is dismissed.
it seems like

Code: Select all

 GetComponentInParent<PixelCrushers.DialogueSystem.AbstractDialogueUI>().OnContinueConversation();
is in charge of dismissing Player dialogue which is making player dialogue to dismiss after the delay - (make it looks like its not interacted during the delay even though player pressed the button for Continue button)

Would it be possible to

Code: Select all

    IEnumerator ContinueAfterDelayCoroutine(float delay)
    {
    	//Dismiss PlayerDialgoue here
        yield return new WaitForSeconds(delay);
        currentCoroutine = null;
        //NPC Dialogue Start here after above delay
    }
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: Delay after Response Menu submitted

Post by Tony Li »

Hi,

For your player subtitle panel, make a subclass of StandardUIContinueButtonFastForward. Override OnFastForward. Hide the panel, wait a duration, then continue. Example:

Code: Select all

public class MyFastForwardButton : StandardUIContinueButtonFastForward
{
    public StandardUISubtitlePanel playerPanel; // <--Assign in inspector or in code.
    
    public override void OnFastForward()
    {
        if ((typewriterEffect != null) && typewriterEffect.isPlaying)
        {
            typewriterEffect.Stop();
        }
        else
        {
            StartCoroutine(DelayThenContinue());
        }
    }
    IEnumerator DelayThenContinue()
    {
        if (hideContinueButtonOnContinue && continueButton != null) continueButton.gameObject.SetActive(false);
        playerPanel.Close();
        yield return new WaitForSeconds(5); // Delay value here.
        runtimeDialogueUI.OnContinueConversation();
    }
}
Post Reply