How to trigger a sequence command in the middle of a dialogue text ?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Strook
Posts: 70
Joined: Fri Nov 08, 2019 10:51 am

How to trigger a sequence command in the middle of a dialogue text ?

Post 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 ?
Currently working on ->Squeakross: Home Squeak Home<- Using Dialogue System Save System and other features.
Previous game made with Dialogue system ->The Spirit and The mouse<-
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to trigger a sequence command in the middle of a dialogue text ?

Post 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.)
Post Reply