[HOWTO] How To: Auto-Open Quest Journal When Accepting Quest

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: Auto-Open Quest Journal When Accepting Quest

Post by Tony Li »

Add this script to the scene (e.g., Player) to auto-open the quest journal UI when a quest goes active.

AutoOpenJournalOnNewQuest.cs

Code: Select all

using UnityEngine;
using PixelCrushers;
using PixelCrushers.QuestMachine;

public class AutoOpenJournalOnNewQuest : MonoBehaviour, IMessageHandler
{
    private void OnEnable()
    {
        MessageSystem.AddListener(this, QuestMachineMessages.QuestStateChangedMessage, string.Empty);
    }

    private void OnDisable()
    {
        MessageSystem.RemoveListener(this);
    }

    public void OnMessage(MessageArgs messageArgs)
    {
        string questID = messageArgs.parameter;
        bool isMainQuestState = (messageArgs.values[0] == null);
        if (isMainQuestState)
        {
            QuestState questState = (QuestState)messageArgs.values[1];
            if (questState == QuestState.Active)
            {
                var journal = QuestMachine.GetQuestJournal();
                journal.ShowJournalUI();
                var journalUI = journal.questJournalUI as UnityUIQuestJournalUI;
                if (journalUI != null) journalUI.SelectQuest(journal.FindQuest(questID));
            }
        }
    }
}
Edit: Updated to show quest that was just activated.
User avatar
CamperJohn
Posts: 14
Joined: Sun Apr 05, 2020 7:01 pm
Contact:

Re: [HOWTO] How To: Auto-Open Quest Journal When Accepting Quest

Post by CamperJohn »

This works like a top...thanks for sharing. :D
Post Reply