1. Make a copy of the subtitle panel for each character, and assign them to the Standard Dialogue UI's list of subtitle panels. Add a Dialogue Actor component to each character, and select the subtitle panel number to use (e.g., 0 for male, 2 for female, etc.). Then customize that subtitle panel's typewriter effect.
2. Or, if you want to use one subtitle panel, assign a C# method to the typewriter effect's OnBegin() method. In this method, set the typewriter effect's audio clip. If you put the audio clips in a Resources folder, you can add a custom field to each actor that specifies the audio clip name. In your C# method, look up that field, load the corresponding audio clip, and assign it. Something like:
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class SetTypewriterForActor : MonoBehaviour
{
public void OnBeginTypewriter() // Assign to typewriter's OnBegin() event.
{
// Look up character's audio clip:
var actorName = DialogueManager.currentConversationState.subtitle.speakerInfo.nameInDatabase;
var clipName = DialogueManager.masterDatabase.GetActor(actorName).LookupValue("AudioClip");
var clip = Resources.Load<AudioClip>(clipName);
// Assign to typewriter:
var typewriter = GetComponent<AbstractTypewriterEffect>();
typewriter.audioClip = clip;
typewriter.audioSource.clip = clip;
}
}
ModifyTypewriterExample_2019-09-11.unitypackage
(Exported from Unity 2019.1.)
Let's say you have an audio clip for each actor. Put them in a folder named Resources:
The Resources folder can be anywhere in your project, and you can have as many Resources folders in your project as you want.
Inspect each actor in the Dialogue Editor. Add a custom field named AudioClip, and set its value to the name of the audio clip:
The field name "AudioClip" is arbitrary; it's just what I chose to use in the script.
Add the script above (named SetTypewriterForActor.cs) to the subtitle text GameObject. Also add an Audio Source so you can configure it exactly the way you want it to sound (e.g., volume, etc.). Assign them both to the typewriter effect as shown below:
When the typewriter effect begins, it will run SetTypewriterForActor's OnBeginTypewriter method. This method looks up the current speaker's AudioClip field and assigns the corresponding audio clip to the typewriter.