summaryrefslogtreecommitdiff
path: root/GameCode/DelayEvent.cs
blob: 0ebea5658005f781b2fe06e5cff4dd8a338be985 (plain)
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
using System.Collections;
using UnityEngine;
using UnityEngine.Events;

public class DelayEvent : MonoBehaviour
{
	public UnityEvent delayedEvent;

	public float time = 1f;

	public bool auto;

	public bool repeating;

	public bool usedTimeScale = true;

	private void Start()
	{
		CodeAnimation componentInParent = GetComponentInParent<CodeAnimation>();
		if ((bool)componentInParent)
		{
			time /= componentInParent.animations[0].animationSpeed;
		}
		if (auto)
		{
			Go();
		}
	}

	public void Go()
	{
		StartCoroutine(DelayEventCall());
	}

	private IEnumerator DelayEventCall()
	{
		yield return 1;
		if (usedTimeScale)
		{
			yield return new WaitForSeconds(time);
		}
		else
		{
			yield return new WaitForSecondsRealtime(time);
		}
		if (base.enabled)
		{
			delayedEvent.Invoke();
			if (repeating)
			{
				Go();
			}
		}
	}

	public void DoEvent()
	{
		StopAllCoroutines();
		delayedEvent.Invoke();
	}
}