Skip to content

Instantly share code, notes, and snippets.

@kalineh
Last active March 3, 2016 21:43
Show Gist options
  • Save kalineh/62527b1844600afe2aed to your computer and use it in GitHub Desktop.
Save kalineh/62527b1844600afe2aed to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class CoroutineBugTest
: MonoBehaviour
{
public IEnumerator OuterReturnIEnumerator(string s)
{
Debug.LogFormat("Outer: enter: {0}", s);
yield return Inner(s);
}
public IEnumerator OuterManualIteration(string s)
{
Debug.LogFormat("Outer: enter: {0}", s);
var e = Inner(s);
while (e.MoveNext())
{
yield return e.Current;
}
}
public IEnumerator Inner(string s)
{
Debug.LogFormat("Inner: enter: {0}", s);
while (true)
{
Debug.LogFormat("Inner: loop: {0}", s);
yield return new WaitForSeconds(1.0f);
}
}
void Start()
{
StartCoroutine(Test());
}
public IEnumerator Test()
{
var outerA = OuterReturnIEnumerator("A");
var outerB = OuterManualIteration("B");
var inner = Inner("C");
StartCoroutine(outerA);
StartCoroutine(outerB);
StartCoroutine(inner);
Debug.Log("CoroutineBugTest.Test(): starting...");
yield return new WaitForSeconds(2.5f);
// wont stop
Debug.Log("CoroutineBugTest.Test(): stopping A");
StopCoroutine(outerA);
yield return new WaitForSeconds(0.1f);
// will stop
Debug.Log("CoroutineBugTest.Test(): stopping B");
StopCoroutine(outerB);
yield return new WaitForSeconds(0.1f);
// will stop
Debug.Log("CoroutineBugTest.Test(): stopping C");
StopCoroutine(inner);
yield return new WaitForSeconds(0.1f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment