diff --git a/Runtime/Views/ActionMarkupHandler.cs b/Runtime/Views/ActionMarkupHandler.cs index ca390d76..6e7f968f 100644 --- a/Runtime/Views/ActionMarkupHandler.cs +++ b/Runtime/Views/ActionMarkupHandler.cs @@ -71,7 +71,7 @@ public interface IActionMarkupHandler /// A object that the line is /// being displayed in. /// A cancellation token representing - /// whether the + /// whether cancellation has been requested. /// A task that completes when the has completed presenting this /// character. Dialogue presenters will wait until this task is complete @@ -85,7 +85,13 @@ public interface IActionMarkupHandler /// 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(); + /// A cancellation token representing + /// whether cancellation has been requested. + /// A task that completes when the has completed presenting this + /// character. Dialogue presenters will wait until this task is complete + /// before proceeding to dismiss the line. + public YarnTask OnLineDisplayComplete(CancellationToken cancellationToken); /// /// Called right before the line will dismiss itself. @@ -117,7 +123,7 @@ public abstract class ActionMarkupHandler : MonoBehaviour, IActionMarkupHandler public abstract YarnTask OnCharacterWillAppear(int currentCharacterIndex, MarkupParseResult line, CancellationToken cancellationToken); /// - public abstract void OnLineDisplayComplete(); + public abstract YarnTask OnLineDisplayComplete(); /// public abstract void OnLineWillDismiss(); diff --git a/Runtime/Views/LineAdvancer.cs b/Runtime/Views/LineAdvancer.cs index e3b84631..0bf3a694 100644 --- a/Runtime/Views/LineAdvancer.cs +++ b/Runtime/Views/LineAdvancer.cs @@ -769,7 +769,7 @@ public YarnTask OnCharacterWillAppear(int currentCharacterIndex, MarkupParseResu return YarnTask.CompletedTask; } - public void OnLineDisplayComplete() + public YarnTask OnLineDisplayComplete(CancellationToken cancellationToken) { if (status == PresentationStatus.LineBegan) { @@ -779,6 +779,8 @@ public void OnLineDisplayComplete() { status = PresentationStatus.OptionsWaiting; } + + return YarnTask.CompletedTask; } public void OnLineWillDismiss() diff --git a/Runtime/Views/LinePresenterButtonHandler.cs b/Runtime/Views/LinePresenterButtonHandler.cs index 9d7b9294..0c5dcc2e 100644 --- a/Runtime/Views/LinePresenterButtonHandler.cs +++ b/Runtime/Views/LinePresenterButtonHandler.cs @@ -69,9 +69,9 @@ public override YarnTask OnCharacterWillAppear(int currentCharacterIndex, Markup return YarnTask.CompletedTask; } - public override void OnLineDisplayComplete() + public override YarnTask OnLineDisplayComplete() { - return; + return YarnTask.CompletedTask; } public override void OnLineWillDismiss() diff --git a/Runtime/Views/PauseEventProcessor.cs b/Runtime/Views/PauseEventProcessor.cs index 571fdf10..adf0b84d 100644 --- a/Runtime/Views/PauseEventProcessor.cs +++ b/Runtime/Views/PauseEventProcessor.cs @@ -23,9 +23,10 @@ namespace Yarn.Unity public sealed class PauseEventProcessor : IActionMarkupHandler { private Dictionary pauses = new(); - public void OnLineDisplayComplete() + public YarnTask OnLineDisplayComplete(CancellationToken cancellationToken) { pauses.Clear(); + return YarnTask.CompletedTask; } public void OnLineDisplayBegin(MarkupParseResult line, TMP_Text text) diff --git a/Runtime/Views/Typewriter/InstantTypewriter.cs b/Runtime/Views/Typewriter/InstantTypewriter.cs index 4e35dbcb..fe4a2981 100644 --- a/Runtime/Views/Typewriter/InstantTypewriter.cs +++ b/Runtime/Views/Typewriter/InstantTypewriter.cs @@ -4,6 +4,7 @@ namespace Yarn.Unity { using System; using System.Collections.Generic; + using System.Linq; using System.Threading; using UnityEngine; using Yarn.Markup; @@ -75,10 +76,9 @@ await processor Text.maxVisibleCharacters = visibleCharacterCount; // Let each markup handler know the line has finished displaying - foreach (var markupHandler in ActionMarkupHandlers) - { - markupHandler.OnLineDisplayComplete(); - } + await YarnTask.WhenAll( + ActionMarkupHandlers.Select(handler => handler.OnLineDisplayComplete(cancellationToken)) + ); } public void PrepareForContent(MarkupParseResult line) diff --git a/Runtime/Views/Typewriter/LetterTypewriter.cs b/Runtime/Views/Typewriter/LetterTypewriter.cs index be38a114..52e19385 100644 --- a/Runtime/Views/Typewriter/LetterTypewriter.cs +++ b/Runtime/Views/Typewriter/LetterTypewriter.cs @@ -4,6 +4,7 @@ namespace Yarn.Unity { using System; using System.Collections.Generic; + using System.Linq; using System.Threading; using UnityEngine; #if USE_TMP @@ -105,10 +106,9 @@ await processor } // Let each markup handler know the line has finished displaying - foreach (var markupHandler in ActionMarkupHandlers) - { - markupHandler.OnLineDisplayComplete(); - } + await YarnTask.WhenAll( + ActionMarkupHandlers.Select(handler => handler.OnLineDisplayComplete(cancellationToken)) + ); } public void PrepareForContent(Markup.MarkupParseResult line) diff --git a/Runtime/Views/Typewriter/WordTypewriter.cs b/Runtime/Views/Typewriter/WordTypewriter.cs index 7e0f465a..91f42a2a 100644 --- a/Runtime/Views/Typewriter/WordTypewriter.cs +++ b/Runtime/Views/Typewriter/WordTypewriter.cs @@ -4,6 +4,7 @@ namespace Yarn.Unity { using System; using System.Collections.Generic; + using System.Linq; using System.Threading; using UnityEngine; #if USE_TMP @@ -131,10 +132,9 @@ await processor } // Let each markup handler know the line has finished displaying - foreach (var markupHandler in ActionMarkupHandlers) - { - markupHandler.OnLineDisplayComplete(); - } + await YarnTask.WhenAll( + ActionMarkupHandlers.Select(handler => handler.OnLineDisplayComplete(cancellationToken)) + ); } public void PrepareForContent(Markup.MarkupParseResult line)