-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDialogAutoPlay.cs
70 lines (66 loc) · 2.11 KB
/
DialogAutoPlay.cs
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// This code is part of the Fungus library (/~https://github.com/snozbot/fungus)
// It is released for free under the MIT open source license (/~https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEngine;
using UnityEngine.Serialization;
using System.Collections;
using System;
using UnityEngine.UI;
namespace Fungus
{
/// <summary>
/// Fungus Custom Command Template.
/// </summary>
[CommandInfo("flow",
"Dialog Auto Play",
"Auto play dialogue")]
[AddComponentMenu("")]
[ExecuteInEditMode]
public class DialogAutoPlay : Command
{
[SerializeField] protected SayDialog sayd;
[SerializeField] protected float delayBeforeContinue = 0f;
protected bool isRunning = false;
protected DialogInput dInput;
protected Writer writer;
protected bool wasPressed = false;
public override void OnEnter()
{
dInput = sayd.GetComponent<DialogInput>();
writer = sayd.GetComponent<Writer>();
AutoPlay(true);
Continue();
}
public void AutoPlay(bool state)
{
if(state)
{
if(!isRunning)
{
isRunning = true;
wasPressed = false;
StartCoroutine(AutoPlayFunction(true));
}
}
else
{
isRunning = false;
wasPressed = false;
StopCoroutine(AutoPlayFunction(false));
}
}
protected IEnumerator AutoPlayFunction(bool state)
{
while(isRunning)
{
yield return null;
if(!writer.IsWaitingForInput && !wasPressed)
{
wasPressed = true;
yield return new WaitForSeconds(delayBeforeContinue);
dInput.SetNextLineFlag();
wasPressed = false;
}
}
}
}
}