Set up UI for a given node, preferably in edit mode?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Aki Kanerva
Posts: 2
Joined: Wed Oct 11, 2023 10:23 am

Set up UI for a given node, preferably in edit mode?

Post by Aki Kanerva »

Hi there!

I'm working on automation for taking screenshots of every single conversation node. My aim is to write an automation script that goes through all nodes in a conversation and renders the relevant UI as it would appear in-game.

I have two related questions:

1. How do I tell Dialogue System to jump to a specific node without progressing through the entire tree? There are some cases where nodes have dependencies to a previous node, eg. a previously-set background, but they aren't game-spanning and it should be possible to collapse them.

2. How would I go about rendering StandardDialogueUI (ie. building the canvas) in Edit Mode? This would significantly speed up automation compared to running in Play Mode.

Edit: I'm happy to edit the source code if necessary, though if this can be avoided, it'll make maintenance easier.

Thanks!
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set up UI for a given node, preferably in edit mode?

Post by Tony Li »

Hi,

You can't render StandardDialogueUI in edit mode. It depends on runtime values. However, you can write a runtime (not editor) script to run through all lines of dialogue in a conversation and take screenshots. Note that if you're using [var=variable] or [lua(code)] markup tags in your dialogue text, they may not show proper values if you aren't playing through the conversation the intended way.

To run through all entries in all conversations, do something like:

Code: Select all

using System.Collections;
using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ScreenshotConversations : MonoBehaviour
{
    IEnumerator Start()
    {
        foreach (var conversation in DialogueManager.masterDatabase.conversations)
        {
            DialogueManager.StartConversation(conversation.Title);
            foreach (var entry in conversation.dialogueEntries)
            {
                if (entry.id == 0 || entry.isGroup) continue; // Skip <START> and group entries.
                var state = DialogueManager.conversationModel.GetState(entry);
                state.subtitle.sequence = "WaitForMessage(Forever)"; // Don't play entry's regular sequence.
                DialogueManager.conversationController.GotoState(state);
                yield return null;
                DialogueManager.standardDialogueUI.conversationUIElements.defaultNPCSubtitlePanel.GetTypewriter().Stop();
                // Take your screenshot here
                yield return new WaitForSeconds(0.2f); // Wait a bit so you can see what's going on.
            }
            DialogueManager.StopConversation();
        }
    }
}
Aki Kanerva
Posts: 2
Joined: Wed Oct 11, 2023 10:23 am

Re: Set up UI for a given node, preferably in edit mode?

Post by Aki Kanerva »

Thank you, Tony! This looks like a great starting point.

There are some {(if:variable=true)text} segments in the dialogue text, so we'll need to figure out 1) how to detect variables in a given node and 2) how to pass each value to the conversation controller. But that sounds like it should be doable.
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set up UI for a given node, preferably in edit mode?

Post by Tony Li »

Hi,

If you use [lua(Conditional(variable, text))] in your text, the code above will automatically take care of it. If variable is true, it will include text. Otherwise it won't.
Post Reply