Multiple NPC dialogue UI

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
hellraider
Posts: 1
Joined: Fri Sep 27, 2019 6:57 am

Multiple NPC dialogue UI

Post by hellraider »

So I have been tinkering with Dialogue System and especially 'textline'. It came to my attention that it there is only a single message template for NPC dialogue preventing to output messages of different NPCs in different styles.

Thinking 'Multiple NPC dialogue UI' extra would do the work I downloaded it just to realize that it only works with legacy UI.

My question is what would be the ideal solution to achieve this?
User avatar
Tony Li
Posts: 23309
Joined: Thu Jul 18, 2013 1:27 pm

Re: Multiple NPC dialogue UI

Post by Tony Li »

Hi,

You can make a subclass of TextlineDialogueUI and override the GetTemplate() method. The current method looks like this:

Code: Select all

protected virtual StandardUISubtitlePanel GetTemplate(Subtitle subtitle)
{
    return subtitle.speakerInfo.IsNPC ? conversationUIElements.defaultNPCSubtitlePanel : conversationUIElements.defaultPCSubtitlePanel;
}
It always uses the dialogue UI's default NPC subtitle panel. Override it to check for a custom subtitle panel:

Code: Select all

using PixelCrushers.DialogueSystem;
using UnityEngine;
public class MyCustomTextlineDialogueUI : TextlineDialogueUI
{
    protected override StandardUISubtitlePanel GetTemplate(Subtitle subtitle)
    {
        var panelNumber = DialogueActor.GetSubtitlePanelNumber(subtitle.speakerInfo.transform);
        if (panelNumber == SubtitlePanelNumber.Custom)
        {
            return subtitle.speakerInfo.transform.GetComponent<DialogueActor>().standardDialogueUISettings.customSubtitlePAnel;
        }
        else        
        {
            return base.GetTemplate(subtitle);
        }
    }
}
Then you can add a Dialogue Actor component to an NPC, set Standard Dialogue UI Settings > Subtitle Panel Number to Custom, and assign a different subtitle panel template to use.

To retain UI element assignments when replacing the TextlineDialogueUI component with your new subclass, use the triple bar menu in the upper right of the Inspector to change to Debug mode. Then drag your new subclass script into the TextlineDialogueUI component's Script field.
hellwalker
Posts: 112
Joined: Tue Jan 19, 2016 11:37 pm

Re: Multiple NPC dialogue UI

Post by hellwalker »

Hi,
Thanks!
But is the TextlineDialogueUI correct class? I can't find that class anywhere in the project. When I try to create class you posted the TextlineDialogueUI is not recognized by visual studio or unity.

I also cannot find GetTemplate text when I search VS for string search on the entire solution.
my DS version is 2.2.0
User avatar
Tony Li
Posts: 23309
Joined: Thu Jul 18, 2013 1:27 pm

Re: Multiple NPC dialogue UI

Post by Tony Li »

Hi,

Since the original poster (is that you, too?) mentioned Textline, I assumed they already had the Textline framework imported into their project. Textline is available on the Extras page. My post above specifically covers how to customize Textline to use multiple NPC templates.

If you only want to show different NPCs' text in different panels, you don't need Textline. You can use multiple panels as described in this post.
hellwalker
Posts: 112
Joined: Tue Jan 19, 2016 11:37 pm

Re: Multiple NPC dialogue UI

Post by hellwalker »

Ah sorry! :D
I mistook it for my issue I posted few days ago.
https://www.pixelcrushers.com/phpbb/vie ... 209#p14209

The username is similar and I guess solution too so I didn't pay close attention :lol:
Post Reply