Essential Systems / Dialogues

Dialogues

Enjoying Essential Systems?Leave a review

Learn to use the included dialogue manager.

Setup

Create a dialogue asset via Create → Essentials → Dialogue → Dialogue. Each asset has a Header and Description, which make up the displayed text.

Branches and conditions

A Branch links one dialogue to another. To transition from dialogue A to B, add a branch to A and assign B as the Next dialogue.

Each branch uses a Condition to determine when to transition. Built-in conditions can be found under Create → Essentials → Dialogue → Conditions.

Custom conditions

[CreateAssetMenu(fileName = "Test [CONDITION]", menuName = "Essentials/Dialogue/Conditions/Test", order = 0)]
public class TestCondition : Condition
{
    // If Evaluate() is not overridden, it returns isSatisfied.
    // You can set it directly or call SetTrue() / SetFalse().

    public override void Init(DialogueManager manager)
    {
        base.Init(manager);
        // initialization logic
    }

    public override void Dispose()
    {
        base.Dispose();
        // cleanup logic
    }

    public override bool Evaluate()
    {
        return // evaluation logic
    }
}

Skip on input:

[CreateAssetMenu(fileName = "Skip [CONDITION]", menuName = "Essentials/Dialogue/Conditions/Skip", order = 0)]
public class SkipCondition : Condition
{
    public override bool Evaluate()
    {
        return Input.GetKeyDown(KeyCode.Space);
    }
}

Transition when dialogue finishes:

[CreateAssetMenu(fileName = "Done [CONDITION]", menuName = "Essentials/Dialogue/Conditions/Done", order = 0)]
public class DoneCondition : Condition
{
    public override void Init(DialogueManager manager)
    {
        base.Init(manager);
        manager.onDialogueFinished += SetTrue;
    }

    public override void Dispose()
    {
        base.Dispose();
        manager.onDialogueFinished -= SetTrue; // always unsubscribe to avoid leaks.
    }
}

Dialogue Manager

DialogueManager is abstract, letting you present dialogues however you want. Override Show() and Hide() to hook into your UI or any other presentation layer.

public class DialogueUI : DialogueManager
{
    public TextMeshProUGUI headerText, descriptionText;

    protected override void Hide()
    {
        headerText.text = "";
        descriptionText.text = "";
    }

    protected override void Show(Dialogue dialogue)
    {
        headerText.text = dialogue.Header;
        descriptionText.text = dialogue.Description;

        StartCoroutine(DelayFinish());
        // alt: Thread.Delay(this, Finish, 1)
    }

    private IEnumerator DelayFinish()
    {
        yield return new WaitForSeconds(5);
        Finish(); // must always be called when the dialogue is done.
    }
}

Running a dialogue

public DialogueManager manager;
public Dialogue dialogue;

manager.Run(dialogue);
Last updated