Active Speaker Overhead Indicator

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
tmeans825
Posts: 9
Joined: Sat Mar 27, 2021 5:32 pm

Active Speaker Overhead Indicator

Post by tmeans825 »

Hey! I am not using text-bubble based dialogue in my game (I'm essentially using the base WRPG type template).

With that, I was wondering if there was a relatively easy built-in way to show an indicator (not a quest indicator) over the current speaking actor's head (like the icon of a speech bubble with '...' to indicate they're the one currently speaking). I searched all over the forum/documentation and could only find references to quest indicators, though I want this indicator over the head of whoever is speaking at any given time, regardless of quests.

Thank you, and I'm loving the plug-in so far!
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Active Speaker Overhead Indicator

Post by Tony Li »

Hi,

You can use a script with an OnConversationLine method to show the indicator. Here's a basic example:

First, say each character has a simple script like the one below to manage its overhead indicator:

Code: Select all

public class Speaker : MonoBehaviour
{
    public GameObject indicator;
}
Then add a script to the Dialogue Manager, something like:

Code: Select all

public class SpeakingIndicatorManager : MonoBehaviour
{
    private Speaker lastSpeaker;
    
    void OnConversationLine(Subtitle subtitle)
    {
        if (string.IsNullOrEmpty(subtitle.formattedText.text)) return; // Line is empty; don't show indicator.
        if (lastSpeaker == null || subtitle.speakerInfo.transform != lastSpeaker.transform)
        {
            if (lastSpeaker != null) lastSpeaker.indicator.SetActive(false);
            var currentSpeaker = subtitle.speakerInfo.transform.GetComponent<Speaker>();
            currentSpeaker.indicator.SetActive(true);
            lastSpeaker = currentSpeaker;
        }
    }  
    
    void OnConversationEnd(Transform actor) 
    {
        if (lastSpeaker != null) lastSpeaker.indicator.SetActive(false);
        lastSpeaker = null;
    }
}
tmeans825
Posts: 9
Joined: Sat Mar 27, 2021 5:32 pm

Re: Active Speaker Overhead Indicator

Post by tmeans825 »

Thank you for the example Tony, this makes a lot of sense. You rock!
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Active Speaker Overhead Indicator

Post by Tony Li »

Glad to help. Thanks for using the Dialogue System!
Lekonia
Posts: 2
Joined: Mon May 03, 2021 7:53 am

Re: Active Speaker Overhead Indicator

Post by Lekonia »

Hi
Just got the Dialogue System and it is working wonderfully, i stumbled on this post which sounds exactly like what i am looking for, i am trying to implement the scripts for a simple test, I wanted to confirm that with the "SpeakingIndicatorManager" script, it needs to use the "using PixelCrushers.DialogueSystem;" for the "OnConversationLine" to work? (Specifically the "Subtitle" aspect of the method)

I am very new to all this but i am very keen to learn, and thank you for making such a great System.
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Active Speaker Overhead Indicator

Post by Tony Li »

Yes, that's correct.

Tip: If you type in some code and it doesn't recognize a word such as "Subtitle", you can usually right-click on the word and select a menu option to add the necessary line to recognize it, such as "using PixelCrushers.DialogueSystem;" in this case.
Lekonia
Posts: 2
Joined: Mon May 03, 2021 7:53 am

Re: Active Speaker Overhead Indicator

Post by Lekonia »

Thank you!
It is working wonders and the indicators are doing their thing for the NPC's, thank you for the help and to the original poster for this thread.
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Active Speaker Overhead Indicator

Post by Tony Li »

Great! Glad it's working.
Post Reply