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));
}
}
}
}