public static bool StopRequest(IEnumerator routine) { var sucess = false; CoroutineController controller = null; if (s_executingRequests.TryGetValue(routine, out controller)) { if (controller != null) { s_executingRequests.Remove(routine); } if (controller.state != CoroutineState.Finished) { sucess = true; //Stop Running Routines if (controller.state == CoroutineState.Running || controller.state == CoroutineState.Paused) { controller.Stop(); } } } if (s_pendingRequestsHash.Contains(routine)) { int v_index = s_pendingRequests.IndexOf(routine); if (v_index >= 0) { s_pendingRequests.RemoveAt(v_index); } sucess = s_pendingRequestsHash.Remove(routine) || sucess || v_index >= 0; } //Remove Sender from this routine MonoBehaviour sender = null; if (s_enumeratorToSenders.TryGetValue(routine, out sender)) { s_enumeratorToSenders.Remove(routine); } //Remove Hash var hash = ""; if (s_enumeratorToHashMap.TryGetValue(routine, out hash)) { s_enumeratorToHashMap.Remove(routine); s_hashToEnumeratorMap.Remove(hash); } if (sucess) { if (OnCancelRequest != null) { OnCancelRequest(sender, routine, hash); } } //The routine was finished but will only be unscheduled in next frame, so we can report the "OnRequestExecutionFinish" now else if (!sucess && controller != null) { if (OnRequestExecutionFinish != null) { OnRequestExecutionFinish(sender, routine, hash); } } return(sucess); }