Quest Journal breaking between scenes
Re: Quest Journal breaking between scenes
You can put that code in a new script that's on a GameObject in the Quest Machine GameObject's hierarchy (such as the Quest Machine GameObject itself) or any GameObject that, like Quest Machine, is DontDestroyOnLoad.
Re: Quest Journal breaking between scenes
Done that heres the script:
I supposed this would be executed with the attached image On Click() event, but nothing seems to happen. No errors in the console. (I started off with Awake instead of Start but that gave me a nullref for var uiPanel). Is this how it should be executed?
Code: Select all
using UnityEngine;
using PixelCrushers.QuestMachine;
using PixelCrushers;
public class CloseJournalUI : MonoBehaviour
{
private void Start()
{
var journalUI = QuestMachine.defaultQuestJournalUI as UnityUIQuestJournalUI;
var uiPanel = journalUI.GetComponent<UIPanel>();
var uiManager = FindObjectOfType<UIManager>();
uiPanel.onOpen.AddListener(uiManager.ToggleJournal);
uiPanel.onClose.AddListener(uiManager.ToggleJournal);
}
}
- Attachments
-
- Screenshot_1.png (5.26 KiB) Viewed 1326 times
Re: Quest Journal breaking between scenes
The best way to open and close the journal UI is through the Quest Journal component. The Quest Journal component is usually on your player GameObject. Call QuestJournal.ShowJournal, HideJournal, or ToggleJournal.
It's also fine to call the UnityUIQuestJournalUI component's Hide method directly.
Both ways will implicitly call the journal UI's UIPanel.Close. You don't need to call it directly.
It's also fine to call the UnityUIQuestJournalUI component's Hide method directly.
Both ways will implicitly call the journal UI's UIPanel.Close. You don't need to call it directly.
Re: Quest Journal breaking between scenes
Awesome, everything's clear and working
Re: Quest Journal breaking between scenes
I have some things I would like to add to the function, such as unhiding the cursor, stop character from moving while the menu is open and so on.
Re: Quest Journal breaking between scenes
Hi,
When Quest Machine's journal UI opens, it sends the message "Pause Player" to Quest Machine's Message System. When the UIs close, they send "Unpause Player".
You can add a script that listens for these messages. Example:
public class PausePlayerWhenMenuIsOpen : MonoBehaviour, IMessageHandler
{
void OnEnable()
{
MessageSystem.AddListener(this, "Pause Player", string.Empty);
MessageSystem.AddListener(this, "Unpause Player", string.Empty);
}
void OnDisable()
{
MessageSystem.RemoveListener(this, "Pause Player", string.Empty);
MessageSystem.RemoveListener(this, "Unpause Player", string.Empty);
}
public void OnMessage(MessageArgs messageArgs)
{
switch (messageArgs.message)
{
case "Pause Player":
// Unhide cursor, stop character from moving, etc.
break;
case "Unpause Player":
// Hide cursor, etc.
break;
}
}
}[/code]
Or use a Message Events component:
If you want to do the same for when the dialogue UI opens or some other UI opens, you can configure the UI to send the same messages.
When Quest Machine's journal UI opens, it sends the message "Pause Player" to Quest Machine's Message System. When the UIs close, they send "Unpause Player".
You can add a script that listens for these messages. Example:
Spoiler
Code: Select all
{
void OnEnable()
{
MessageSystem.AddListener(this, "Pause Player", string.Empty);
MessageSystem.AddListener(this, "Unpause Player", string.Empty);
}
void OnDisable()
{
MessageSystem.RemoveListener(this, "Pause Player", string.Empty);
MessageSystem.RemoveListener(this, "Unpause Player", string.Empty);
}
public void OnMessage(MessageArgs messageArgs)
{
switch (messageArgs.message)
{
case "Pause Player":
// Unhide cursor, stop character from moving, etc.
break;
case "Unpause Player":
// Hide cursor, etc.
break;
}
}
}[/code]
If you want to do the same for when the dialogue UI opens or some other UI opens, you can configure the UI to send the same messages.