Skip to content

Commit 1ca65b7

Browse files
authored
Merge pull request #2 from hxdnshx/master
Add WaitUntil / WaitWhile support to EditorCoroutine
2 parents 353cbaf + 02b9d7a commit 1ca65b7

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
File renamed without changes.

Assets/EditorCoroutines/Scripts/CoroutineWindowExample.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@ void OnGUI()
4242
{
4343
this.StopAllCoroutines();
4444
}
45+
46+
if (GUILayout.Button("WaitUntil/WaitWhile"))
47+
{
48+
status = false;
49+
this.StartCoroutine(ExampleWaitUntilWhile());
50+
}
51+
52+
if (GUILayout.Button("Switch For WaitUntil/WaitWhile:" + (status ? "On" : "Off")))
53+
{
54+
status = !status;
55+
EditorUtility.SetDirty(this);
56+
}
57+
}
58+
59+
private bool status;
60+
61+
IEnumerator ExampleWaitUntilWhile()
62+
{
63+
yield return new WaitUntil(()=>status);
64+
Debug.Log("Switch On");
65+
yield return new WaitWhile(()=>status);
66+
Debug.Log("Switch Off");
4567
}
4668

4769
IEnumerator Example()

Assets/EditorCoroutines/Scripts/EditorCoroutines.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ public bool IsDone(float deltaTime)
7575
}
7676
}
7777

78+
struct YieldCustomYieldInstruction : ICoroutineYield
79+
{
80+
public CustomYieldInstruction customYield;
81+
82+
public bool IsDone(float deltaTime)
83+
{
84+
return !customYield.keepWaiting;
85+
}
86+
}
87+
7888
struct YieldWWW : ICoroutineYield
7989
{
8090
public WWW Www;
@@ -354,6 +364,13 @@ static bool Process(EditorCoroutine coroutine)
354364
float seconds = float.Parse(GetInstanceField(typeof(WaitForSeconds), current, "m_Seconds").ToString());
355365
coroutine.currentYield = new YieldWaitForSeconds() {timeLeft = (float) seconds};
356366
}
367+
else if (current is CustomYieldInstruction)
368+
{
369+
coroutine.currentYield = new YieldCustomYieldInstruction()
370+
{
371+
customYield = current as CustomYieldInstruction
372+
};
373+
}
357374
else if (current is WWW)
358375
{
359376
coroutine.currentYield = new YieldWWW {Www = (WWW) current};

0 commit comments

Comments
 (0)