Page 1 of 1

OnVisualizeQuest

Posted: Fri Apr 16, 2021 5:58 am
by Fax
Hi everybody.
I want to know if there is a way to catch when a quest is visualize.
When a player is asking for a quest (which is waiting to start), just before the player accept the quest.
I want to play some audio clip on top of the text.

Thanks a lot if someone can help me.

Re: OnVisualizeQuest

Posted: Fri Apr 16, 2021 8:07 am
by Fax
I'm getting a headache...
I search for a way to get current quest and current node which is display.

I can script over QuestMachine code but, dunno where i'm suppose to get these informations cause of the specific structure of QuestMachine.

Re: OnVisualizeQuest

Posted: Fri Apr 16, 2021 8:15 am
by Tony Li
Hi,

What if you add Audio Quest Content to the quest's Offer Text?

offerTextAudio.png
offerTextAudio.png (32.71 KiB) Viewed 918 times

Re: OnVisualizeQuest

Posted: Fri Apr 16, 2021 8:23 am
by Fax
I can't because i use Localization for sounds (an a Manager for that).

I want to trigger a scene event at the same place as your audio clip is triggered.

Edit : Like a "Offer Action".

Re: OnVisualizeQuest

Posted: Fri Apr 16, 2021 8:45 am
by Tony Li
Hi,

You can write a custom quest content script. Duplicate QuestContentTemplate.cs and rename it something like LocalizedAudioQuestContent.cs. Then fill in your code where the comments indicate. Quest Machine will automatically recognize your script and make it available in dropdown menus.

Re: OnVisualizeQuest

Posted: Fri Apr 16, 2021 8:52 am
by Fax
I'll try it in couple of minutes and let you know after.
Thanks a lot again for your help.

Re: OnVisualizeQuest

Posted: Fri Apr 16, 2021 9:41 am
by Fax
I don't understand where i have to put my code.
The template show us 6 possibilities to uncomment, but no one is triggered when i open the offer quest.
I am missing something somewhere but dunno what and where.
2021-04-16_15h40_19.png
2021-04-16_15h40_19.png (34.42 KiB) Viewed 913 times

Re: OnVisualizeQuest

Posted: Fri Apr 16, 2021 10:44 am
by Fax
Finally found a solution.
First there is my custom QuestContent :
2021-04-16_16h40_10.png
2021-04-16_16h40_10.png (6.28 KiB) Viewed 913 times
In second time, i had to add this condition to trigger my QuestContent at the right moment (in UnityUIBaseUI.cs) :
2021-04-16_16h40_24.png
2021-04-16_16h40_24.png (26.46 KiB) Viewed 913 times
Finally, i create in UnityUIBaseUI.cs a method to redirect to my custom QuestContent :
2021-04-16_16h40_50.png
2021-04-16_16h40_50.png (5.3 KiB) Viewed 913 times
Don't know if this is the cleaner way but it works for my purpose.
Thanks again for your help.

Re: OnVisualizeQuest

Posted: Fri Apr 16, 2021 11:00 am
by Tony Li
Hi,

That will work. If you have directly modified UnityUIBaseUI.cs, I recommend making a subclass instead. Example:

Code: Select all

public class MyQuestDialogueUI : UnityUIQuestDialogueUI
{
    protected virtual void AddContent(QuestContent content)
    {
        if (content is LocalizsedAudioQuestContent)
        {
            AddLocalizedAudioContent(content as LocalizedAudioQuestContent)
        }
        else
        {
            base.AddContent(content);
        }   
    }
    
    protected virtual void AddLocalizedAudioQuestContent(LocalizedAudioQuestContent localizedAudioQuestContent)
    {
        if (localizedAudioQuestContent == null || localizedAudioQuestContent.index == -1) return;
        localizedAudioQuestContent.Play();
    }
}
Then use MyQuestDialogueUI on your quest dialogue UI instead of UnityUIQuestDialogueUI. To replace the script in-place, change the Inspector view to Debug, and then drag your MyQuestDialogueUI script into the UnityUIQuestDialogueUI component's Script field.