public void DrawGUI() { EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.LabelField("Calculate prime numbers"); numPrimes = EditorGUILayout.IntField("Stop After", numPrimes); numPrimes = Mathf.Clamp(numPrimes, 100, 100000); if (runningRoutine == null || runningRoutine.State == EditorCoroutineState.Canceled || runningRoutine.State == EditorCoroutineState.Done) { if (GUILayout.Button("Start")) { runningRoutine = EditorCoroutine.Start(FindPrimeNumber(numPrimes)); } } else { if (runningRoutine != null && GUILayout.Button("Cancel")) { runningRoutine.Cancel(); } } if (runningRoutine != null) { var prevColor = GUI.backgroundColor; switch (runningRoutine.State) { case EditorCoroutineState.Running: GUI.backgroundColor = Color.yellow; break; case EditorCoroutineState.Canceled: GUI.backgroundColor = Color.red; break; case EditorCoroutineState.Done: GUI.backgroundColor = Color.green; break; } EditorGUILayout.LabelField(runningRoutine.State.ToString(), EditorStyles.helpBox); GUI.backgroundColor = prevColor; } EditorGUILayout.EndVertical(); }