reverse markup possible?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
joeylu
Posts: 111
Joined: Sun May 17, 2020 1:07 pm

reverse markup possible?

Post by joeylu »

Hi Tony,
I use emphasis settings (something like <em1></em1>) as the basic styling markup for my contents, it works well.
However, since I have a lot of dialogue contents in my game, it becomes inconvenience to add or edit <em> markup when needed.
In my usage, my purpose is to show some different text styling for keywords, for instance, a keyword "Purple Chest" will always has purple color.
My question is that is it possible to define or add <em> markup dynamically based on a given keyword? For instance, as long as the subtitle text detects the "Purple Chest" in its text line, it will display it with purple color automatically.
I'm thinking using global search & replace function or maybe build a custom dictionary with SequenceCommander?
the first option lacks of versality, maybe you have some better ideas? tks
User avatar
Tony Li
Posts: 21676
Joined: Thu Jul 18, 2013 1:27 pm

Re: reverse markup possible?

Post by Tony Li »

Hi,

You can add a script to the Dialogue Manager that uses an OnConversationLine(Subtitle) method to add [em#] tags around keywords. Simple example:

Code: Select all

public class HighlightKeywords : MonoBehaviour
{
    void OnConversationLine(Subtitle subtitle)
    {
        subtitle.formattedText.text = subtitle.formattedText.text.Replace("Purple Chest", "[em1]Purple Chest[/em1]");
    }
}
I kept the example simple for clarity. If you're comfortable with a bit of programming, I recommend using a table of some sort rather than hard-coding the strings into the Replace() function like that. You might also use Regex.Replace() instead of string.Replace().
Post Reply