-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIInterlocutor.cs
More file actions
52 lines (44 loc) · 1.86 KB
/
Copy pathIInterlocutor.cs
File metadata and controls
52 lines (44 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace Screenplay;
public interface IInterlocutor
{
UniTask RunDialog(IEventContext context, IEnumerable<string> lines, bool previewMode, bool passive, Cancellation cancellation);
public static async UniTask DefaultRunDialog(IEventContext context, IEnumerable<string> lines, bool previewMode, Cancellation cancellation)
{
var ui = context.GetDialogUI();
ui.StartDialogPresentation();
foreach (var text in lines)
{
ui.StartLineTypewriting(text);
ui.SetTypewritingCharacter(0);
float delay = 0;
// Length - 1 as we don't want to delay after showing the last character
for (int i = 0; i < text.Length - 1; i++)
{
ui.SetTypewritingCharacter(i + 1);
delay += 0.05f;
while ((delay -= Time.unscaledDeltaTime) > 0 && ui.FastForwardRequested == false)
await Uni.NextFrame(cancellation: cancellation, cancelImmediately: true);
if (ui.FastForwardRequested) // After a skip in the middle of typewriting, wait for another skip signal before continuing
{
await Uni.NextFrame(cancellation, cancelImmediately: true);
break;
}
}
ui.SetTypewritingCharacter(text.Length);
ui.FinishedTypewriting();
while (previewMode || ui.DialogAdvancesAutomatically == false)
{
if (ui.FastForwardRequested)
{
await Uni.NextFrame(cancellation, cancelImmediately:true);
break;
}
await Uni.NextFrame(cancellation, cancelImmediately:true);
}
}
ui.EndDialogPresentation();
}
}