-
Notifications
You must be signed in to change notification settings - Fork 0
/
When.cs
56 lines (40 loc) · 1.22 KB
/
When.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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class When
{
protected When() {}
private Func<bool> validator;
private Action executor;
/// <summary>
/// Triggers the specified code in the execution block the first time that the paramaters return true
/// </summary>
/// <param name="validator"></param>
/// <param name="executor"></param>
public When(Func<bool> validator, Action executor)
{
this.validator = validator;
this.executor = executor;
//Creates an object to start the coroutine
GameObject dummyObj = new GameObject("_WhenClassDummyGameObjectForCoroutine");
dummyObj.AddComponent<WhenDummy>().StartCoroutine(WhenCoRo());
dummyObj.hideFlags = HideFlags.HideInHierarchy;
}
public IEnumerator WhenCoRo()
{
yield return null;
while (true)
{
if (validator.Invoke())
{
executor.Invoke();
yield break;
}
yield return null;
}
}
}
public class WhenDummy : MonoBehaviour
{
}