← Back to all addons

Speech Dialog (Dialog Audio)

Posted by Mr.Titan on Dec 29, 2024 at 3:31 AM

GameplayExperimentalFeature
💡 1

Add audio to your dialogs! Each “line” in your dialog can play an audio clip. However, keep in mind that if you have multiple lines, the same audio will play for all of them.

In the DialogueUtils.cs add the following line:

        private static DialogueNode CreateDialogueNodeRecursive(DialogueSequence sequence, string speaker, params string[] args)
        {
 ...
            for (int i = 0; i < sequence.lines.Length; ++i)
            {
                ...
                current.speaker = speaker;
                current.audio = sequence.audio; //add this line
                ...
            }

            ...
        }
...

In the DialogueSequence.cs add the following line:

public class DialogueSequence : DatabaseEntry
{
    ...
    [SerializeReference] //add this line
    public AudioClipResolver audio = null; //add this line
}

In the DialogueSequenceEditor.cs add the following lines:

    public class DialogueSequenceEditor : DatabaseEntryEditor
    {
      // Private Members
      private SerializedProperty m_audio;   // add this line
      
      void OnEnable()
      {
          m_audio = serializedObject.FindProperty("audio");   // add this line
      }
      
      public override void OnInspectorGUI()
      {
          base.OnInspectorGUI();
          EditorGUILayout.PropertyField(m_audio);   // add this line
          EditorGUILayout.Separator();   // add this line
          ...
      }
}

In the DialogueChannel.cs add the following lines:

private void SetCurrentNode(DialogueNode node)
{
    ....
    else
    {
//add this ->
        if (m_currentNode.audio)
        {
            GameManager.NotificationSystem.audioPlaybackRequested.Invoke(m_currentNode.audio);
        }
// <- up until this
        m_currentNode.toExecuteOnStart?.Execute();
    }
}

You can now add the audios to your dialogues!

💬 Comments (1)

Gyvr Dec 29, 2024 at 06:26 AM
Very nice! Thanks for sharing 🙏

Want to continue the conversation?