Page 1 of 1

Toggle onValueChanged - Quest Journal

Posted: Mon Aug 15, 2022 5:01 pm
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

Re: Toggle onValueChanged - Quest Journal

Posted: Mon Aug 15, 2022 7:57 pm
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;
            }
        }
    }
}

Re: Toggle onValueChanged - Quest Journal

Posted: Tue Aug 16, 2022 10:20 am
by NicoMozes
Thanks! That was indeed what I needed. So easy!

Have a lovely day!

Re: Toggle onValueChanged - Quest Journal

Posted: Tue Aug 16, 2022 10:24 am
by Tony Li
Happy to help!