If you're using plain Text or TextMesh Pro, here are two alternatives:
1. Write a subclass of UnityUITypewriterEffect or TextMeshProTypewriterEffect. Override the Play() method.
2. Or add a script with an OnConversationLine method to your Dialogue Manager. Locate the position(s) of the custom tags you're using to indicate the events, and compute the time that the event should happen by using the typewriter effect's charactersPerSecond value. Example:
Code: Select all
void OnConversationLine(Subtitle subtitle)
{
// Does the text contain the special tag [Shake]?
int shakePos = subtitle.formattedText.text.IndexOf("[Shake]");
if (shakePos != -1)
{
// Remove the tag from the text:
subtitle.formattedText.text = subtitle.formattedText.text.Remove(shakePos, "[Shake]".Length);
// Determine when the typewriter would reach that tag: (Note: Example doesn't account for RPG Maker pause tags.)
float time = shakePos / DialogueManager.standardDialogueUI.GetComponentInChildren<AbstractTypewriterEffect>().charactersPerSecond;
// Add a sequencer command to do something at that time:
subtitle.sequence = $"AC(Shake)@{time}; " + subtitle.sequence;
}
}
Tip: The Tools.StripRichTextCodes() and Tools.StripTextMeshProTags() may be helpful.