How to sync Name color with Subtitle color (TMP)

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Abelius
Posts: 312
Joined: Fri Jul 21, 2017 12:45 pm

How to sync Name color with Subtitle color (TMP)

Post by Abelius »

Hello,

I'd swear there was a thread about this, but I can't find it anymore, so here's mine...

I "just" need to make sure the NPC Name and NPC Subtltle Text TMP - Text (UI) components have the same color.

In Dialogue Actor there's an option to use a subtitle color, but there's not an equivalent for the character name, and I find that aesthetically unpleasing.

I tried synchronizing "Vertex Color" in every line change, but then I realized the color is applied "manually" by DS with a tag.

So, before I go to the extreme of extracting that tag from the subtitle text, I'd like to know if you have a better suggestion.

Also, could I suggest to just add a name/subtitle sync option to DS, please?

Thank you!
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 20642
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to sync Name color with Subtitle color (TMP)

Post by Tony Li »

Hi,

How are you setting the NPC's subtitle color? Using a Dialogue Actor component on the NPC's GameObject?

If you, then you could get the Dialogue Actor's subtitle color in an OnConversationLine method and apply it to the portrait name. Example:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ApplySubtitleColorToPortraitName : MonoBehaviour // Add to Dialogue Manager
{
    public Color defaultNameColor = Color.white;

    void OnConversationLine(Subtitle subtitle)
    {
        var ui = DialogueManager.dialogueUI as StandardDialogueUI;
        DialogueActor dialogueActor;
        var panel = ui.conversationUIElements.standardSubtitleControls.GetPanel(subtitle, out dialogueActor);
        if (dialogueActor != null && dialogueActor.standardDialogueUISettings.setSubtitleColor)
        {
            panel.portraitName.color = dialogueActor.standardDialogueUISettings.subtitleColor;
        }
        else
        {
            panel.portraitName.color = defaultNameColor;
        }
    }
}
User avatar
Abelius
Posts: 312
Joined: Fri Jul 21, 2017 12:45 pm

Re: How to sync Name color with Subtitle color (TMP)

Post by Abelius »

Ah, I see.

Yeah, I'm using Dialogue Actor but also PlayMaker, so I ended up using that dirty trick of extracting the Hex color code from the Subtitle TMP and converting it to color, and apply it to the name TMP. It's more or less the same.

Only that your suggestion of using OnConversationLine event is better performance-wise. I'll modify it that way.

Thank you!
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 20642
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to sync Name color with Subtitle color (TMP)

Post by Tony Li »

Glad to help!
Post Reply