Toggle onValueChanged - Quest Journal

Announcements, support questions, and discussion for Quest Machine.
Post Reply
NicoMozes
Posts: 24
Joined: Sun Jun 05, 2022 4:18 am

Toggle onValueChanged - Quest Journal

Post by NicoMozes »

Hello Tony,

I hope you are very well.
I have been looking at how to use the onValueChanged event from the Quest Tracking system to toggle on/off markers from HUD Navigation System, but I have hit a wall.

I looked at the HNS example, but it doesn't seem to have the Quest Journal active.

Would you be able to point me in the right direction? The idea is activating some GameObjects that act as Hud Element Pivots during the quests. For example, if the quest needs you to go to a certain place, there will be an Hud element from the HUD navigation system becoming active.

However, when toggling off the tracking of that quest, the element should also be turned off... I just cant figure it out : (

Thanks in advance.
Nico
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Toggle onValueChanged - Quest Journal

Post by Tony Li »

Hi,

Which onValueChanged are you referring to?

If you're talking about the UnityUITrackToggleTemplate, try hooking into its onToggleChanged C# event instead.

Or, better yet, listen for the QuestTrackToggleChangedMessage.

The HUDNavigationTrackToggle component does this. Add it to a HUDNavigationElement and set the questID that it corresponds to. This is what the code looks like:

Code: Select all

using UnityEngine;
using SickscoreGames.HUDNavigationSystem;

namespace PixelCrushers.QuestMachine.HUDNavigationSystemSupport
{

    /// <summary>
    /// Shows or hides a HUDNavigationElement based on a quest's tracking state.
    /// </summary>
    [AddComponentMenu("Pixel Crushers/Quest Machine/Third Party Support/HUD Navigation System/HUD Navigation Track Toggle")]
    [RequireComponent(typeof(HUDNavigationElement))]
    public class HUDNavigationTrackToggle : MonoBehaviour, IMessageHandler
    {

        public StringField questID;

        private HUDNavigationElement element;

        protected virtual void Awake()
        {
            element = GetComponent<HUDNavigationElement>();
        }

        protected virtual void OnEnable()
        {
            MessageSystem.AddListener(this, QuestMachineMessages.QuestTrackToggleChangedMessage, string.Empty);
        }

        protected virtual void OnDisable()
        {
            MessageSystem.RemoveListener(this);
        }

        public virtual void OnMessage(MessageArgs messageArgs)
        {
            if (string.Equals(messageArgs.parameter, StringField.GetStringValue(questID)))
            {
                element.IsActive = (bool)messageArgs.firstValue;
            }
        }
    }
}
NicoMozes
Posts: 24
Joined: Sun Jun 05, 2022 4:18 am

Re: Toggle onValueChanged - Quest Journal

Post by NicoMozes »

Thanks! That was indeed what I needed. So easy!

Have a lovely day!
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Toggle onValueChanged - Quest Journal

Post by Tony Li »

Happy to help!
Post Reply