-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBetterWait.cs
78 lines (65 loc) · 2.25 KB
/
BetterWait.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
71
72
73
74
75
76
77
78
// 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;
namespace Fungus
{
/// <summary>
/// Waits for period of time before executing the next command in the block.
/// </summary>
[CommandInfo("Flow",
"Better Wait",
"Waits for period of time before executing the next command in the block.")]
[AddComponentMenu("")]
[ExecuteInEditMode]
public class BetterWait : Command
{
[Tooltip("Duration to wait for")]
[SerializeField] protected FloatData _duration = new FloatData(1);
protected virtual void OnWaitComplete()
{
SayDialog sayDialog = SayDialog.GetSayDialog();
sayDialog.GetComponent<DialogInput>().enabled = true;
//Not necessary, but hey
StopCoroutine(OnWaiting());
Continue();
}
protected virtual IEnumerator OnWaiting()
{
SayDialog sayDialog = SayDialog.GetSayDialog();
sayDialog.GetComponent<DialogInput>().enabled = false;
yield return new WaitForSeconds(_duration);
OnWaitComplete();
}
#region Public members
public override void OnEnter()
{
StartCoroutine(OnWaiting());
}
public override string GetSummary()
{
return _duration.Value.ToString() + " seconds";
}
public override Color GetButtonColor()
{
return new Color32(235, 191, 217, 255);
}
public override bool HasReference(Variable variable)
{
return _duration.floatRef == variable || base.HasReference(variable);
}
#endregion
#region Backwards compatibility
[HideInInspector] [FormerlySerializedAs("duration")] public float durationOLD;
protected virtual void OnEnable()
{
if (durationOLD != default(float))
{
_duration.Value = durationOLD;
durationOLD = default(float);
}
}
#endregion
}
}