Hi there!
I was wondering if was possible to create captions for Dialogues.
I would like deaf people to be able to turn on/off an alternative dialogue UI that describes sounds they can't hear.
I was thinking to maybe use the "Menu text" field to describe sounds, but I'm not sure it would work.
Is there a way to do so?
Many thanks
Captions UI
Re: Captions UI
Hi,
You can add custom fields to your dialogue entry template. (See Templates.) For example, say you've added a Text field named "Caption" to your dialogue entry template, and you've set some dialogue entries' Captions to include text like "[birds chirping]" or "[jackhammer sounds]". Then you can add a script with an OnConversationLine(Subtitle) method to your Dialogue Manager or dialogue UI (assuming the dialogue UI ends up in the Dialogue Manager's hierarchy) that does something like this:
You can add custom fields to your dialogue entry template. (See Templates.) For example, say you've added a Text field named "Caption" to your dialogue entry template, and you've set some dialogue entries' Captions to include text like "[birds chirping]" or "[jackhammer sounds]". Then you can add a script with an OnConversationLine(Subtitle) method to your Dialogue Manager or dialogue UI (assuming the dialogue UI ends up in the Dialogue Manager's hierarchy) that does something like this:
Code: Select all
public class Captions : MonoBehaviour
{
public bool showCaptions; // If true, show captions.
public UITextField captionText; // Assign Text or TextMeshProUGUI component in inspector.
void OnConversationLine(Subtitle subtitle)
{
string caption = Field.LookupValue(subtitle.dialogueEntry.fields, "Caption");
captionText.gameObject.SetActive(showCaptions && !string.IsNullOrEmpty(caption));
captionText.text = caption;
}
}
Re: Captions UI
Alright, I'm trying to make it work.
I've added the custom field to the Dialogues and attached the script to the UI I'm using, I've also assigned the subtitle text I'm working on in the PC Subtitle Panel.
However, it's giving me the following error:
NullReferenceException: Object reference not set to an instance of an object
Captions.OnConversationLine (PixelCrushers.DialogueSystem.Subtitle subtitle) (at Assets/Captions.cs:15)
Additionally, the UI is not showing.
Here are some screenshots.
Thanks for the amazing help by the way.
I've added the custom field to the Dialogues and attached the script to the UI I'm using, I've also assigned the subtitle text I'm working on in the PC Subtitle Panel.
However, it's giving me the following error:
NullReferenceException: Object reference not set to an instance of an object
Captions.OnConversationLine (PixelCrushers.DialogueSystem.Subtitle subtitle) (at Assets/Captions.cs:15)
Additionally, the UI is not showing.
Here are some screenshots.
Thanks for the amazing help by the way.
- Attachments
-
- Screenshot_3_UI.png (46.55 KiB) Viewed 267 times
-
- screenshot_2_UI.png (451.66 KiB) Viewed 267 times
-
- Screenshot_1_UI.png (375.34 KiB) Viewed 267 times
Re: Captions UI
Hi,
That error suggests that a UI text component is no longer assigned to captionText.
Is there more than one instance of the Captions script in your scene?
If you enter play mode and start the conversation, is the Captions script's Caption Text field still assigned?
That error suggests that a UI text component is no longer assigned to captionText.
Is there more than one instance of the Captions script in your scene?
If you enter play mode and start the conversation, is the Captions script's Caption Text field still assigned?
Re: Captions UI
Hi Tony,
You were right, i had a duplicate, now the error has vanished.
However, the UI it's still not showing.
I'm using the default PC Subtitle Panel, which turns off automatically whenever i start a dialogue.
What do you suggest?
Thanks again
You were right, i had a duplicate, now the error has vanished.
However, the UI it's still not showing.
I'm using the default PC Subtitle Panel, which turns off automatically whenever i start a dialogue.
What do you suggest?
Thanks again
Re: Captions UI
Create your own Text or TextMeshProUGUI component and assign it to Caption Text. Don't use the Subtitle Text GameObject, since that's for the subtitle panel's use.