/* Yarn Spinner is licensed to you under the terms found in the file LICENSE.md. */ using UnityEngine; using Yarn.Markup; using System.Threading; #if USE_TMP using TMPro; #else using TMP_Text = Yarn.Unity.TMPShim; #endif #nullable enable namespace Yarn.Unity { /// /// A is an object that reacts to the /// delivery of a line of dialogue, and can optionally control the timing of /// that delivery. /// /// /// /// There are a number of cases where a line's delivery needs to have its /// timing controlled. For example, adds a /// small delay between each character, creating a 'typewriter' effect as /// each letter appears over time. /// /// /// Another example of a is an in-line /// event or animation, such as causing a character to play an animation /// (and waiting for that animation to complete before displaying the rest /// of the line). /// /// public interface IActionMarkupHandler { /// /// Called when the line view receives the line, to prepare for showing /// the line. /// /// /// This method is called before any part of the line is visible, and is /// an opportunity to set up any part of the 's display before the user can see it. /// /// The line being presented. /// A object that the line is /// being displayed in. public void OnPrepareForLine(MarkupParseResult line, TMP_Text text); /// /// Called immediately before the first character in the line is /// presented. /// /// The line being presented. /// A object that the line is /// being displayed in. public void OnLineDisplayBegin(MarkupParseResult line, TMP_Text text); /// /// Called repeatedly for each visible character in the line. /// /// This method is a /// object's main opportunity to take action during line /// display. /// The zero-based index of the /// character being displayed. /// A object that the line is /// being displayed in. /// A cancellation token representing /// whether the /// A task that completes when the has completed presenting this /// character. Dialogue presenters will wait until this task is complete /// before displaying the remainder of the line. public YarnTask OnCharacterWillAppear(int currentCharacterIndex, MarkupParseResult line, CancellationToken cancellationToken); /// /// Called after the last call to . /// /// This method is an opportunity for a to finalise its presentation after /// all of the characters in the line have been presented. public void OnLineDisplayComplete(); /// /// Called right before the line will dismiss itself. /// /// /// This does not mean that the entirety of the view itself will have been removed, just the has completed displaying everything and is returning control back to the to let more content flow. /// public void OnLineWillDismiss(); } /// /// This is an abstract monobehaviour that conforms to the interface. /// /// /// /// Intended to be used in situations where you require a monobehaviour version of the interfaces. /// This is used by to have a list of handlers that can be connected up via the inspector. /// /// public abstract class ActionMarkupHandler : MonoBehaviour, IActionMarkupHandler { /// public abstract void OnPrepareForLine(MarkupParseResult line, TMP_Text text); /// public abstract void OnLineDisplayBegin(MarkupParseResult line, TMP_Text text); /// public abstract YarnTask OnCharacterWillAppear(int currentCharacterIndex, MarkupParseResult line, CancellationToken cancellationToken); /// public abstract void OnLineDisplayComplete(); /// public abstract void OnLineWillDismiss(); } }