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 StopAllCoroutines_SpecificOwnerArg_StopsAllCoroutinesCorrectly()
        {
            OwnerOfRoutine ownerA        = new OwnerOfRoutine();
            RefBool        wasCancelledA = new RefBool();
            RefBool        wasCancelledB = new RefBool();

            // Test coroutines will be stopped. Check in 1 second for expected results. Test coroutines should finish by then, successfully or not.
            DateTime     then          = DateTime.Now;
            const double secondsToWait = 1;

            TestContext.WriteLine("Starting SimpleIteratorToBeStoppedB and ownerA.SimpleIteratorToBeStoppedA routines.\nWill automatically attempt to stop routines belonging to ownerA after a frame.");
            // All the following coroutines will be attempted to be cancelled after 1 frame, in the line after the following `yield return null`.
            EditorCoroutineService.StartCoroutine(ownerA, "SimpleIteratorToBeStoppedA", new object[] { wasCancelledA });
            EditorCoroutineService.StartCoroutine(SimpleIteratorToBeStoppedB(wasCancelledB));
            yield return(null);

            EditorCoroutineService.StopAllCoroutines(ownerA);

            double deltaSeconds = (DateTime.Now - then).TotalSeconds;

            while (deltaSeconds < secondsToWait)
            {
                yield return(null);

                deltaSeconds = (DateTime.Now - then).TotalSeconds;
            }

            Assert.IsTrue(wasCancelledA.Value && !wasCancelledB.Value, "EditorCoroutines belonging to a specific owner were not stopped correctly.");
        }
 private void Button_5()
 {
     EditorCoroutineService.StopAllCoroutines();
 }