Page 1 of 1
How to trigger a sequence command in the middle of a dialogue text ?
Posted: Fri Nov 15, 2019 10:32 am
by Strook
Hello I have a question, I'm sure it's possible but I can't find it :
let's say I have a dialoge that goes :
"Hello, my name is...UNITY"
I would like to trigger a sequence commande exactly at a certain point for example
"Hello, my name is...[CHANGE CAMERA]UNITY"
I now I could do a wait, but is there a precise way to control sequence in the middle of dialogue text ?
Re: How to trigger a sequence command in the middle of a dialogue text ?
Posted: Fri Nov 15, 2019 10:58 am
by Tony Li
Hi,
You could add a custom tag to the text, like:
"Hello, my name is... <camera>UNITY"
and set the Sequence to something like:
Code: Select all
{{default}};
Camera(Closeup)@Message(MoveCamera)
Then add little script to the Dialogue Manager that handles that tag and sends the sequencer message "MoveCamera" at the appropriate time. The script can use an OnConversationLine method that extracts the tag and adjusts the Sequence to send the sequencer message. Something like:
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class CustomDialogueTagHandler : MonoBehaviour
{
public float typewriterCharsPerSec = 50;
void OnConversationLine(Subtitle subtitle)
{
int tagPosition = subtitle.formattedText.text.IndexOf("<camera>");
if (tagPosition == -1) return; // If no tag, we're done.
// Remove the tag from the text:
subtitle.formattedText.text = subtitle.formattedText.text.Remove(tagPosition, "<camera>".Length);
// Add a sequencer command to send "MoveCamera" at the right time:
string textBeforeTag = subtitle.formattedText.text.Substring(0, tagPosition);
float duration = textBeforeTag.Length / typewriterCharsPerSec;
if (string.IsNullOrEmpty(subtitle.sequence)) subtitle.sequence = "{{default}}";
subtitle.sequence = "Delay(" + duration + ")->Message(MoveCamera); " + subtitle.sequence;
}
}
(Note: I just typed this into the reply. It might have typos.)
(EDIT: Changed the way the duration is computed.)