device buttons image in dialogues

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
alfonso
Posts: 104
Joined: Mon Jul 13, 2015 6:31 am

device buttons image in dialogues

Post by alfonso »

Hi Tony,

I would like to put some icons inline in the dialogue text according to the console, for example "press <action1 ... /> to attack".
I'm making a research for put the icons inline but i would like to know if i can parse this stuff in the normal flow of the logic, some method that i can override or something like that or a need to make my own Parser and call before the base.showSubtitle(...) in my UnityUIDialogueUI.cs.

The main idea is to use a generic custom tag like <action1 ... /> and according the console show the device button icon if XBOX show "A" icon, if is PS "X" icon, ...

thanks so much for the help :)
User avatar
Tony Li
Posts: 22102
Joined: Thu Jul 18, 2013 1:27 pm

Re: device buttons image in dialogues

Post by Tony Li »

Hi Alfonso,

Here are two options. You can choose the one that works best for your needs.

Option 1:
Create a subclass of your dialogue UI, and override ShowSubtitle:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class MyDialogueUI : UnityUIDialogueUI {

    public override void ShowSubtitle(Subtitle subtitle) {
        // Extract <action1>:
        bool hasAction1 = subtitle.formattedText.text.Contains("<action1>");
        subtitle.formattedText.text = subtitle.formattedText.text.Replace("<action1>", string.Empty);
        
        // Show the subtitle without the action tags:
        base.ShowSubtitle(subtitle);
        
        // Show the action buttons:
        if (hasAction1) ShowActionButton(1); // example.
    }

Option 2:
Add a script to the Dialogue Manager that has an OnConversationLine method. Something like this:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class CustomTagParser : MonoBehaviour {

    public void OnConversationLine(Subtitle subtitle) {
        // Extract <action1>:
        bool hasAction1 = subtitle.formattedText.text.Contains("<action1>");
        subtitle.formattedText.text = subtitle.formattedText.text.Replace("<action1>", string.Empty);
    }
You'll probably want to use Regex, not String.Contains and String.Replace. I simplified the code above to make it easier to read.
Post Reply