Dialogue Controller

DialogueController is the base class for every dialogue view in Luna — speech bubbles, tutorial modals, visual novels. Provides character-by-character reveal with three modes, audio integration via DialogueAudio, and parses text effects inline.

Features

  • Text Reveal Animation: Character-by-character text reveal with configurable timing
  • Audio Integration: Automatic audio playback for letters and punctuation pauses
  • Text Effects Support: Full integration with the Text Effects system
  • Multiple Animation Modes: Choose from VertexReveal, Default, or Instant modes
  • Event System: Events for text start and completion

Components

DialogueController requires a DialogueAudio component on the same GameObject for audio playback.

Animation Modes

ModeDescription
VertexRevealRecommended. Uses vertex manipulation for smooth reveal with text effects
DefaultLegacy mode. Shows text character by character
InstantShows all text immediately with text effects active

Inspector

SettingDescription
Skip CharsCharacters to skip during reveal (default: space)
Stop CharsCharacters that trigger a pause (default: ., ,, !, ?)
Text Animation ModeThe reveal mode to use

Basic Usage

csharp
using UnityEngine; using CupkekGames.Luna; public class MyDialogue : MonoBehaviour { [SerializeField] private DialogueController _dialogueController; private void Start() { // Subscribe to events _dialogueController.OnTextStart += OnDialogueStart; _dialogueController.OnTextComplete += OnDialogueComplete; } public void ShowDialogue(string text) { // Continue with text, don't skip current if playing _dialogueController.Continue(text, skipCurrent: false); } public void SkipToEnd() { // End current text animation immediately _dialogueController.EndCurrent(); } private void OnDialogueStart() { Debug.Log("Dialogue started"); } private void OnDialogueComplete() { Debug.Log("Dialogue complete"); } }

API

Properties

IsPlaying

Returns true if text is currently being revealed.

csharp
if (_dialogueController.IsPlaying) { // Text is still being revealed }

Methods

Continue

Plays text with optional skip behavior.

csharp
public bool Continue(string text, bool skipCurrent)
ParameterDescription
textThe text to display (can include text effect tags)
skipCurrentIf true and text is playing, skips to new text. If false, completes current text first.

Returns: true if new text started playing, false if current text was completed instead.

Example:

csharp
// First call starts "Hello World" _dialogueController.Continue("Hello World", false); // If called while playing, this completes "Hello World" and returns false bool started = _dialogueController.Continue("Next line", false); // With skipCurrent: true, immediately starts new text _dialogueController.Continue("Skipped to this!", true);

EndCurrent

Immediately completes the current text animation and shows the full text.

csharp
public void EndCurrent()

InitializeUI

Virtual method that queries the view's UI elements. Override in derived classes to set up additional elements.

csharp
public virtual void InitializeUI()

It runs on the OnUILoaded contract, not in Awake: a freshly instantiated view (a world-space speech bubble, a prefab you spawn yourself) has no loaded panel tree yet, so ParentElement is null at Awake. OnUILoaded fires synchronously when the tree is already loaded and again on every UI reload, so your override always queries the live tree — and should expect to run more than once per scene. Register callbacks idempotently (-= before +=).

Setters on the shipped implementations are state-first: calling them before the panel tree loads stores the desired state, which InitializeUI applies once the elements exist — so you can configure a bubble immediately after instantiating it. See SpeechBubbleController.

Events

EventDescription
OnTextStartFired when text begins playing
OnTextCompleteFired when text finishes (either naturally or via EndCurrent)

Using Text Effects

DialogueController automatically parses and applies text effects:

csharp
// Text effects are automatically parsed and applied _dialogueController.Continue( "This is <shake maxxamplitude=\"5\">scary</shake> stuff!", false ); // Rainbow effect _dialogueController.Continue( "Look at this <rainb durationperchar=\"1.0\">magical</rainb> text!", false );

DialogueAudio Component

The DialogueAudio component handles audio playback during text reveal.

Inspector

SettingDescription
LetterAudioClip played for each character
PauseAudioClip played for punctuation pauses

Methods

csharp
public void PlayLetter() // Play letter sound public void PlayPause() // Play pause sound

Required UXML structure

The DialogueController expects a Label with name "Speech":

xml
<ui:UXML xmlns:ui="UnityEngine.UIElements"> <ui:Label name="Speech" /> </ui:UXML>

Derived Classes

DialogueController serves as the base for specialized dialogue implementations:

Tips

  • Use VertexReveal mode for the best visual quality with text effects
  • The skipCurrent parameter is useful for implementing "click to skip" functionality
  • Subscribe to OnTextComplete to know when to show "continue" prompts
  • Text effect tags are automatically removed from the displayed text

See also

Settings

Theme

Light

Contrast

Material

Dark

Dim

Material Dark

System

Sidebar(Light & Contrast only)

Light
Dark

Font Family

DM Sans

Wix

Inclusive Sans

AR One Sans

Direction

LTR
RTL