Page 1 of 1

Active Speaker Overhead Indicator

Posted: Sat Mar 27, 2021 5:37 pm
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!

Re: Active Speaker Overhead Indicator

Posted: Sat Mar 27, 2021 5:48 pm
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;
    }
}

Re: Active Speaker Overhead Indicator

Posted: Sat Mar 27, 2021 7:59 pm
by tmeans825
Thank you for the example Tony, this makes a lot of sense. You rock!

Re: Active Speaker Overhead Indicator

Posted: Sat Mar 27, 2021 8:19 pm
by Tony Li
Glad to help. Thanks for using the Dialogue System!

Re: Active Speaker Overhead Indicator

Posted: Mon May 03, 2021 7:58 am
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.

Re: Active Speaker Overhead Indicator

Posted: Mon May 03, 2021 8:59 am
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.

Re: Active Speaker Overhead Indicator

Posted: Mon May 03, 2021 9:37 am
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.

Re: Active Speaker Overhead Indicator

Posted: Mon May 03, 2021 10:51 am
by Tony Li
Great! Glad it's working.