Page 1 of 1

Skip Button ending conversation, instead of stopping on last dialogue element

Posted: Fri Jan 19, 2024 3:39 pm
by need_verification
Hello I was following this post below on how to implement a skip button. How can I make it so it stop on the final dialogue element instead of auto-closing the conversation?

I want to implement this just in case the player presses skip by accident. Thank you Pixel Crushers!


https://www.pixelcrushers.com/phpbb/vie ... f=3&t=1196


I am using this script:

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;
    }
    void OnConversationEnd(Transform actor)
    {
        skip = false;
    }
}

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Posted: Fri Jan 19, 2024 4:25 pm
by Tony Li
Hi,

That post is close to 8 years old. You can use the Conversation Control component now. Add it to your Dialogue Manager or dialogue UI and configure a UI Button to call ConversationControl.SkipAll. If you want it to stop on the last line instead of skipping past it and ending the conversation, make a subclass that overrides OnConversationLine():

Code: Select all

public class MyConversationControl : ConversationControl
{
    public override void OnConversationLine(Subtitle subtitle)
    {
        if (!DialogueManager.currentConversationState.hasAnyResponses) return;
        base.OnConversationLine(subtitle);
    }
}

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Posted: Fri Jan 19, 2024 4:57 pm
by need_verification
Tony Li wrote: Fri Jan 19, 2024 4:25 pm Hi,

That post is close to 8 years old. You can use the Conversation Control component now. Add it to your Dialogue Manager or dialogue UI and configure a UI Button to call ConversationControl.SkipAll. If you want it to stop on the last line instead of skipping past it and ending the conversation, make a subclass that overrides OnConversationLine():

Code: Select all

public class MyConversationControl : ConversationControl
{
    public override void OnConversationLine(Subtitle subtitle)
    {
        if (!DialogueManager.currentConversationState.hasAnyResponses) return;
        base.OnConversationLine(subtitle);
    }
}
Thank you so much! It worked perfectly!

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Posted: Fri Jan 19, 2024 7:02 pm
by Tony Li
Glad to help!

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Posted: Tue Feb 06, 2024 10:08 am
by Saper
Hi Tony

I would like to add one more question to that subject. In ConversationControl.SkipAll code invoke sequences from all the Nodes, what I can do to run only sequneces in END Node?

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Posted: Tue Feb 06, 2024 10:17 am
by Tony Li
Hi,

First, use the current version of ConversationControl that will be in DS version 2.2.43:

DS_ConversationControl_2024-02-06.unitypackage

Then make a subclass of ConversationControl that skips all sequences except the final node's sequence if Skip All is set:

Code: Select all

public class MyConversationControl : ConversationControl
{
    public override void OnConversationLine(Subtitle subtitle)
    {
        if (skipAll && DialogueManager.currentConversationState.hasAnyResponses)
        {
            subtitle.sequence = "Continue()";
        }
        else
        {
            base.OnConversationLine(subtitle);
        }
     }
}

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Posted: Tue Feb 06, 2024 11:27 am
by Saper
Hi Tony

After importing the script I have error:
Assets\Plugins\Pixel Crushers\Dialogue System\Scripts\UI\Utility\ConversationControl.cs(39,35): error CS0117: 'GameObjectUtility' does not contain a definition for 'FindFirstObjectByType'

We have Unity ver 2020.3.38f1 and FindFirstObjectByType is not implemented in this version

Code: Select all

        protected virtual void Awake()
        {
            dialogueUI =
                GetComponent<AbstractDialogueUI>() ??
                (DialogueManager.standardDialogueUI as AbstractDialogueUI) ??
                GameObjectUtility.FindFirstObjectByType<AbstractDialogueUI>();
        }

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Posted: Tue Feb 06, 2024 11:59 am
by Tony Li
Hi,

Can you back up your project and update to DS version 2.2.42, then import this unitypackage?

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Posted: Wed Feb 07, 2024 3:50 am
by Saper
Hi Tony

after importing package we changed line 39 in ConversationControls.cs

From:

Code: Select all

 protected virtual void Awake()
        {
            dialogueUI =
                GetComponent<AbstractDialogueUI>() ??
                (DialogueManager.standardDialogueUI as AbstractDialogueUI) ??
                GameObjectUtility.FindFirstObjectByType<AbstractDialogueUI>();
        }
To:

Code: Select all

        protected virtual void Awake()
        {
            dialogueUI = 
				GetComponent<AbstractDialogueUI>() ?? 
				(DialogueManager.standardDialogueUI as AbstractDialogueUI) ??
				FindObjectOfType<AbstractDialogueUI>();
        }
Code compile without errors and in game "skip dialogue" workig properly without any issue in console.
Right now we can't allow ourself to update DS (because time, and chance of something going side ways after update).

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Posted: Wed Feb 07, 2024 8:29 am
by Tony Li
Hi,

That's absolutely fine. Unity 2023 will flag FindObjectOfType<T>() as being obsolete. That's why we introduced GameObjectUtility.FindFirstObjectByType<T>(). For earlier versions of Unity, FindObjectOfType<T>() works the same.