Page 1 of 1

SequencerTools GetAudioSource should also check DialogueManager

Posted: Thu Sep 03, 2020 10:58 am
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>();
        }

Re: SequencerTools GetAudioSource should also check DialogueManager

Posted: Thu Sep 03, 2020 1:15 pm
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.

Re: SequencerTools GetAudioSource should also check DialogueManager

Posted: Thu Sep 03, 2020 3:11 pm
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

Re: SequencerTools GetAudioSource should also check DialogueManager

Posted: Thu Sep 03, 2020 3:26 pm
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.
}