[HOWTO] How To: "Conversation Ended" Quest Condition

Announcements, support questions, and discussion for Quest Machine.
Post Reply
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: "Conversation Ended" Quest Condition

Post by Tony Li »

This post contains a custom Quest Machine condition that becomes true when a Dialogue System conversation ends. You can use it if a quest needs to wait until a conversation is over. For example, you could add it as a condition to the "End Conversation" node in the quest below:

endConversationNode.png
endConversationNode.png (18.74 KiB) Viewed 770 times

ConversationEndQuestCondition.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

namespace PixelCrushers.QuestMachine
{
    /// <summary>
    /// Condition that becomes true when the active conversation ends.
    /// </summary>
    public class ConversationEndQuestCondition : QuestCondition
    {
        public override string GetEditorName()
        {
            return "Dialogue System Conversation Has Ended";
        }

        public override void StartChecking(System.Action trueAction)
        {
            base.StartChecking(trueAction);
            DialogueManager.instance.conversationEnded += OnConversationEnded;
        }

        public override void StopChecking()
        {
            base.StopChecking();
            DialogueManager.instance.conversationEnded -= OnConversationEnded;
        }

        private void OnConversationEnded(Transform actor)
        {
            SetTrue();
        }
    }
}
Post Reply