private void Button_4() { if (loopEveryTwoSecondsHandle != null) { EditorCoroutineService.StopCoroutine(loopEveryTwoSecondsHandle); } }
private void OnGUI() { if (GUILayout.Button("Wait for two seconds")) { _loopEveryTwoSecondsHandle = EditorCoroutineService.StartCoroutine(WaitForTwoSeconds()); } if (GUILayout.Button("Wait for 20 frames")) { EditorCoroutineService.StartCoroutine(WaitForTwentyFrames()); } if (GUILayout.Button("Wait for UnityWebRequest")) { EditorCoroutineService.StartCoroutine(WaitForUnityWebRequest()); } if (GUILayout.Button("Wait for nested coroutines")) { EditorCoroutineService.StartCoroutine(WaitForNestedCoroutines()); } if (GUILayout.Button("Stop 'Wait for two seconds' coroutine")) { if (_loopEveryTwoSecondsHandle != null) { EditorCoroutineService.StopCoroutine(_loopEveryTwoSecondsHandle); } } if (GUILayout.Button("Stop all")) { EditorCoroutineService.StopAllCoroutines(); } }
public IEnumerator StopCoroutine_MethodName_StopsCorrectly() { RefBool isTestComplete = new RefBool(); RefBool wasCancelled = new RefBool(); // Test coroutine will be stopped. Check in 1 second for expected results. Test coroutine should finish by then, successfully or not. EditorCoroutineService.StartCoroutine(ReturnAfterSecondsToBeStopped(1f, isTestComplete)); TestContext.WriteLine("Starting SimpleIteratorToBeStopped routine.\nWill automatically attempt to stop it after a frame."); // This coroutine will be attempted to be cancelled after 1 frame, in the line after the following `yield return null`. EditorCoroutineService.StartCoroutine(this, "SimpleIteratorToBeStopped", new object[] { wasCancelled }); yield return(null); EditorCoroutineService.StopCoroutine(this, "SimpleIteratorToBeStopped"); while (!isTestComplete.Value) { yield return(null); } Assert.IsTrue(wasCancelled.Value, "EditorCoroutine was not stopped correctly via Method Name arg."); }