On this thread a while back, you mention that you can assign a font by duplicating and changing the ActorSubtitleColor script. I looked in the script and was wondering how exactly I could do that.
Thank you!
How to change actor font through ActorSubtitleColor
-
- Posts: 5
- Joined: Sat Oct 23, 2021 7:04 pm
Re: How to change actor font through ActorSubtitleColor
Hi,
Here are three ways to change fonts:
1. Use different subtitle panels for different actors. Assign a different font to each subtitle panel.
2. Or, if you're using TextMesh Pro, make a new script like ActorSubtitleColor that wraps the text in <font> tags (see note) similarly to how ActorSubtitleColor.ProcessText wraps the text in color tags. This is the best method to use if you're accumulating text like the Runic or WRPG dialogue UI prefabs do. The ProcessText method might look something like:
3. Or make a new script like ActorSubtitleColor that changes the subtitle panel's font in ProcessText. The ProcessText method might look something like:
Here are three ways to change fonts:
1. Use different subtitle panels for different actors. Assign a different font to each subtitle panel.
2. Or, if you're using TextMesh Pro, make a new script like ActorSubtitleColor that wraps the text in <font> tags (see note) similarly to how ActorSubtitleColor.ProcessText wraps the text in color tags. This is the best method to use if you're accumulating text like the Runic or WRPG dialogue UI prefabs do. The ProcessText method might look something like:
Code: Select all
public string fontAssetName; // Set in inspector.
...
private string ProcessText(Subtitle subtitle)
{
return $"<font='{fontAssetName}'>{subtitle.formattedText.text}</font>";
}
Code: Select all
public Font font;
...
public string ProcessText(Subtitle subtitle)
{
// Get the subtitle panel:
DialogueActor dialogueActor;
var panel = DialogueManager.standardDialogueUI.conversationUIElements.standardSubtitleControls.GetPanel(subtitle, out dialogueActor);
// And set its subtitle text font:
panel.subtitleText.uiText.font = font; // Assumes UI Text. Set textMeshProUGUI property instead if using TMPro.
}
-
- Posts: 5
- Joined: Sat Oct 23, 2021 7:04 pm
Re: How to change actor font through ActorSubtitleColor
When I use the code below, I get an error with the text where it only puts in the first part of the font indicator (image attached). There's probably something extremely simple that i'm missing but I cant quite figure it out.
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
namespace PixelCrushers.DialogueSystem
{
public class ActorFont : MonoBehaviour
{
public string fontAssetName;
public void OnConversationLine(Subtitle subtitle)
{
CheckSubtitle(subtitle);
}
private void CheckSubtitle(Subtitle subtitle)
{
if (subtitle != null && subtitle.speakerInfo != null && subtitle.speakerInfo.transform == this.transform)
{
subtitle.formattedText.text = ProcessText(subtitle.formattedText.text);
}
}
private string ProcessText(string text)
{
return $"<font='{fontAssetName}'>{text}</font>";
}
}
}
Thank you for your help so far!
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
namespace PixelCrushers.DialogueSystem
{
public class ActorFont : MonoBehaviour
{
public string fontAssetName;
public void OnConversationLine(Subtitle subtitle)
{
CheckSubtitle(subtitle);
}
private void CheckSubtitle(Subtitle subtitle)
{
if (subtitle != null && subtitle.speakerInfo != null && subtitle.speakerInfo.transform == this.transform)
{
subtitle.formattedText.text = ProcessText(subtitle.formattedText.text);
}
}
private string ProcessText(string text)
{
return $"<font='{fontAssetName}'>{text}</font>";
}
}
}
Thank you for your help so far!
- Attachments
-
- an example of what my dialog system looks like when i initiate a conversation
- example.PNG (14.48 KiB) Viewed 448 times
Re: How to change actor font through ActorSubtitleColor
Hi,
Try double quotes:
(Maybe TMPro doesn't accept single quotes?)
Also, make sure your font is in a Resources folder as described in the (see note) link above. This link might have a more helpful screenshot: https://forum.unity.com/threads/font-ma ... st-4024261
Try double quotes:
Code: Select all
return $"<font=\"{fontAssetName}\">{subtitle.formattedText.text}</font>";
Also, make sure your font is in a Resources folder as described in the (see note) link above. This link might have a more helpful screenshot: https://forum.unity.com/threads/font-ma ... st-4024261
-
- Posts: 5
- Joined: Sat Oct 23, 2021 7:04 pm
Re: How to change actor font through ActorSubtitleColor
Thank you so much! You were right, for some reason TMP doesn't support single quotes.
Re: How to change actor font through ActorSubtitleColor
Glad to help!