Skip to content

Commit

Permalink
Add OnDialogueStartedAsync; Dialogue Runner now waits for all views t…
Browse files Browse the repository at this point in the history
…o report ready before delivering content
  • Loading branch information
desplesda committed May 21, 2024
1 parent 3154828 commit 04e3cea
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Runtime/Async/AsyncDialogueViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public abstract class AsyncDialogueViewBase : MonoBehaviour
{
public abstract YarnTask RunLineAsync(LocalizedLine line, CancellationToken token);
public abstract YarnOptionTask RunOptionsAsync(DialogueOption[] dialogueOptions, CancellationToken cancellationToken);
public abstract YarnTask DialogueCompleteAsync();
public abstract YarnTask OnDialogueStartedAsync();
public abstract YarnTask OnDialogueCompleteAsync();

public virtual bool EndLineWhenViewFinishes => false;
}
Expand Down
19 changes: 17 additions & 2 deletions Runtime/DialogueRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ async YarnTask RunCompletion()
{
try
{
await view.DialogueCompleteAsync();
await view.OnDialogueCompleteAsync();
}
catch (System.Exception e)
{
Expand Down Expand Up @@ -615,7 +615,22 @@ public void StartDialogue(string nodeName)

onDialogueStart?.Invoke();

Dialogue.Continue();
StartDialogueAsync().Forget();

async YarnTask StartDialogueAsync()
{
var tasks = new List<YarnTask>();
foreach (var view in DialogueViews)
{
if (view == null)
{
continue;
}
tasks.Add(view.OnDialogueStartedAsync());
}
await YarnTask.WhenAll(tasks);
Dialogue.Continue();
}
}

public void CancelCurrentLine()
Expand Down
7 changes: 6 additions & 1 deletion Runtime/Views/DialogueViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,12 @@ public virtual void UserRequestedViewAdvancement()
// default implementation does nothing
}

public override YarnTask DialogueCompleteAsync()
public override YarnTask OnDialogueStartedAsync()
{
return YarnTask.CompletedTask;
}

public override YarnTask OnDialogueCompleteAsync()
{
return YarnTask.CompletedTask;
}
Expand Down
7 changes: 6 additions & 1 deletion Tests/Runtime/DialogueRunnerTests/DialogueRunnerMockUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ public override async YarnOptionTask RunOptionsAsync(DialogueOption[] dialogueOp
return dialogueOptions[selectedOption];
}

public override YarnTask DialogueCompleteAsync()
public override YarnTask OnDialogueStartedAsync()
{
return YarnTask.CompletedTask;
}

public override YarnTask OnDialogueCompleteAsync()
{
return YarnTask.CompletedTask;
}
Expand Down

0 comments on commit 04e3cea

Please sign in to comment.