Few questions about changing dialogue flow on runtime

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Few questions about changing dialogue flow on runtime

Post by Tony Li »

Maybe you're thinking about the custom actor-specific node colors you can set for the node editor?

Anyway, a quick and easy way to set the color of an actor's name as it's shown in dialogue UIs is to add an Override Actor Name component and wrap the Override Name in rich text codes, such as:
  • Override Name: <color=yellow>Private Hart</color>
The only caveat is if you use Variable["Conversant"], since this will be set to "<color=yellow>Private Hart</color>" instead of "Private Hart".
hellwalker
Posts: 112
Joined: Tue Jan 19, 2016 11:37 pm

Re: Few questions about changing dialogue flow on runtime

Post by hellwalker »

Ah thanks, but would that mess with Lua commands and the like?
For example if i have something like Actor["John"].Disposition that I use to set that actors variable, or get it in Sequences, Lua custom script etc. Will this now be changed to color code version?
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Few questions about changing dialogue flow on runtime

Post by Tony Li »

You can still use Actor["John"].Disposition.

You just can't use Actor[Variable["Conversant"]].Disposition.

If you need to use Variable["Conversant"], then an alternative way of changing actor name colors is to add a script with an OnConversationLine method. In this method, put rich text around the speaker's name:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ActorColor : MonoBehaviour {

    public Color color;
    
    void OnConversationLine(Subtitle subtitle) {
        if (subtitle.speakerInfo.transform == this.transform) {
            subtitle.speakerInfo.Name = "<color=" + Tools.ToWebColor(color) + ">" + subtitle.speakerInfo.Name + "</color>";
        }
    }
} 
hellwalker
Posts: 112
Joined: Tue Jan 19, 2016 11:37 pm

Re: Few questions about changing dialogue flow on runtime

Post by hellwalker »

Thank you, probably code method will work best for me, as I have up to five actors in some conversations.
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Few questions about changing dialogue flow on runtime

Post by Tony Li »

Both methods should work fine for as many actors as you want. If you run into any issues, just let me know!
hellwalker
Posts: 112
Joined: Tue Jan 19, 2016 11:37 pm

Re: Few questions about changing dialogue flow on runtime

Post by hellwalker »

Thanks,
I only have two conversant added to dialogue starter trigger. I don't have game object associated with others which if I understood is needed for first method right?
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Few questions about changing dialogue flow on runtime

Post by Tony Li »

That's correct. A variation of the second method is probably best for your case. You could define a custom field in your Actor template that holds a web color such as "ff0000" for red. Let's say you name that field "NameColor". Then your script becomes:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ActorColor : MonoBehaviour { // Add to Dialogue Manager.

    void OnConversationLine(Subtitle subtitle) {
        var webcolor = DialogueManager.MasterDatabase.GetActor(subtitle.speakerInfo.id).LookupValue("NameColor");
        subtitle.speakerInfo.Name = "<color=#" + webcolor + ">" + subtitle.speakerInfo.Name + "</color>";
    }
} 
hellwalker
Posts: 112
Joined: Tue Jan 19, 2016 11:37 pm

Re: Few questions about changing dialogue flow on runtime

Post by hellwalker »

How can I delay the PC Response appearing in subtitle ?
Meaning I click on some response and actual dialogue appears x seconds later?
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Few questions about changing dialogue flow on runtime

Post by Tony Li »

There's no built-in way to do that. You can create a subclass of UnityUIDialogueUI and override ShowSubtitle. If subtitle.speakerInfo.characterType is CharacterType.PC, you could delay before actually showing it. For example:

Code: Select all

using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;

public class MyDialogueUI : UnityUIDialogueUI {

    public override void ShowSubtitle(Subtitle subtitle) {
        if (subtitle.speakerInfo.characterType == CharacterType.PC) {
            StartCoroutine(ShowSubtitleDelayed(subtitle));
        } else {
            base.ShowSubtitle(subtitle);
        }
    }
    
    IEnumerator ShowSubtitleDelayed(Subtitle subtitle) {
        yield return new WaitForSeconds(3); // Wait 3 seconds before showing PC subtitle.
        base.ShowSubtitle(subtitle);
    }
} 
hellwalker
Posts: 112
Joined: Tue Jan 19, 2016 11:37 pm

Re: Few questions about changing dialogue flow on runtime

Post by hellwalker »

Umm I think I have one problem with loading that is caused by delayed sequencer command.
For example lets say I start the game, and after 20 seconds dialogue is to launch. and on 10th second I load my game with different chapter. The dialogue from first scene launches 10 seconds later.

So this is what I'm calling now before loading different chapter.

DialogueManager.StopConversation();
PersistentDataManager.LevelWillBeUnloaded();
DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault);

is there something like Sequence.CancelAll that I can call to stop sequences?
Post Reply