SequencerTools GetAudioSource should also check DialogueManager

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
rakkar
Posts: 51
Joined: Mon Jan 13, 2020 10:39 pm

SequencerTools GetAudioSource should also check DialogueManager

Post by rakkar »

If the subject does not have an AudioSource, don't add a default one without first checking DialogueManager. Doing so means I cannot choose output channel, volume, etc.

Old:

Code: Select all

public static AudioSource GetAudioSource(Transform subject)
        {
            GameObject go = (subject != null) ? subject.gameObject : DialogueManager.instance.gameObject;
            AudioSource audio = go.GetComponentInChildren<AudioSource>();
            return (audio != null) ? audio : go.AddComponent<AudioSource>();
        }
New:

Code: Select all

public static AudioSource GetAudioSource(Transform subject)
        {
            GameObject go = (subject != null) ? subject.gameObject : DialogueManager.instance.gameObject;
            AudioSource audio = go.GetComponentInChildren<AudioSource>();
            // --------------------------------------------
            // KevinJ:
            if (audio == null && go != DialogueManager.instance.gameObject)
                audio = DialogueManager.instance.gameObject.GetComponentInChildren<AudioSource>();
            // --------------------------------------------
            return (audio != null) ? audio : go.AddComponent<AudioSource>();
        }
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: SequencerTools GetAudioSource should also check DialogueManager

Post by Tony Li »

I'll give this some thought. I think players may prefer to have a separate audio source on each speaker, especially in 3D games. You'll have the most control if you put the audio sources on the speakers at design time.
rakkar
Posts: 51
Joined: Mon Jan 13, 2020 10:39 pm

Re: SequencerTools GetAudioSource should also check DialogueManager

Post by rakkar »

In my case the subject is a generic conversation prefab that has a background with a scroll on it. I need to set the subject because I need the conversation ended callback. However, it also has an AudioSource used for something unrelated to narration (playing next-page sounds) that end up getting used by this code. So I took that off, then added a narration AudioSource to the DialogueManager instance.

It seems like the conversation trigger needs to indicate where the AudioSource is in some way, be it one of many AudioSources on the subject, or likewise on the DialogueManager
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: SequencerTools GetAudioSource should also check DialogueManager

Post by Tony Li »

You can get the conversation ended callback anywhere. It's automatically called on the Dialogue Manager and children, and the conversation's two primary participant GameObjects. If the dialogue UI is a child of the Dialogue Manager, it will get the event. If you want to get the event from anywhere, hook into DialogueManager.instance.conversationEnded:

Code: Select all

DialogueManager.instance.conversationEnded += OnConversationEnded;

void OnConversationEnded(Transform actor)
{
    // Do something when the conversation ends.
}
Post Reply