void GoStartCoroutine(PausableCoroutine coroutine) { if (!coroutine_dict.ContainsKey(coroutine.routine_unique_hash)) { List <PausableCoroutine> new_coroutine_list = new List <PausableCoroutine>(); coroutine_dict.Add(coroutine.routine_unique_hash, new_coroutine_list); } coroutine_dict[coroutine.routine_unique_hash].Add(coroutine); if (!coroutine_owner_dict.ContainsKey(coroutine.owner_unique_hash)) { Dictionary <string, PausableCoroutine> new_coroutine_dict = new Dictionary <string, PausableCoroutine>(); coroutine_owner_dict.Add(coroutine.owner_unique_hash, new_coroutine_dict); } // If the method from the same owner has been stored before, it doesn't have to be stored anymore, // One reference is enough in order for "StopAllCoroutines" to work if (!coroutine_owner_dict[coroutine.owner_unique_hash].ContainsKey(coroutine.routine_unique_hash)) { coroutine_owner_dict[coroutine.owner_unique_hash].Add(coroutine.routine_unique_hash, coroutine); } MoveNext(coroutine); }
public static PausableCoroutine StartPausableCoroutine(MonoBehaviour monoBehaviour, IEnumerator toStartEnumerator) { PausableCoroutine result = PausableCoroutineManager.instance.StartCoroutine(toStartEnumerator, monoBehaviour); return(result); }
bool MoveNext(PausableCoroutine coroutine) { if (coroutine.routine.MoveNext()) { return(Process(coroutine)); } return(false); }
void GoStopActualRoutine(PausableCoroutine routine) { if (!coroutine_dict.ContainsKey(routine.routine_unique_hash)) { return; } coroutine_owner_dict[routine.owner_unique_hash].Remove(routine.routine_unique_hash); coroutine_dict.Remove(routine.routine_unique_hash); }
public static PausableCoroutine StopAndStartCachePausableCoroutine(MonoBehaviour monoBehaviour, string enumeratorName, IEnumerator toStartEnumerator) { Dictionary <string, PausableCoroutine> pausableCoroutineDict = monoBehaviour.GetCachePausableCoroutineDict(); PausableCoroutine saveEnumerator = pausableCoroutineDict.GetOrAddDefault2 <PausableCoroutine>(enumeratorName); pausableCoroutineDict[enumeratorName] = monoBehaviour.StopAndStartPausableCoroutine(ref saveEnumerator, toStartEnumerator); return(pausableCoroutineDict[enumeratorName]); }
PausableCoroutine GoStartCoroutine(IEnumerator routine, object this_reference) { if (routine == null) { Debug.LogException(new Exception("IEnumerator is null!"), null); } PausableCoroutine coroutine = CreateCoroutine(routine, this_reference); GoStartCoroutine(coroutine); return(coroutine); }
public static PausableCoroutine StopAndStartPausableCoroutine(MonoBehaviour monoBehaviour, ref PausableCoroutine saveEnumerator, IEnumerator toStartEnumerator) { if (saveEnumerator != null) { PausableCoroutineManager.instance.StopCoroutine(saveEnumerator.routine, monoBehaviour); } PausableCoroutine result = PausableCoroutineManager.instance.StartCoroutine(toStartEnumerator, monoBehaviour); saveEnumerator = result; return(result); }
void GoStopAllCoroutines(object this_reference) { PausableCoroutine coroutine = CreateCoroutine(null, this_reference); if (!coroutine_owner_dict.ContainsKey(coroutine.owner_unique_hash)) { return; } foreach (var couple in coroutine_owner_dict[coroutine.owner_unique_hash]) { coroutine_dict.Remove(couple.Value.routine_unique_hash); } coroutine_owner_dict.Remove(coroutine.owner_unique_hash); }
// returns false if no next, returns true if OK bool Process(PausableCoroutine coroutine) { object current = coroutine.routine.Current; if (current == null) { coroutine.current_yield = new YieldDefault(); } else if (current is WaitForSeconds) { coroutine.current_yield = new YieldWaitForSeconds(current.GetFieldValue <float>("m_Seconds")); } else if (current is CustomYieldInstruction customYield) { coroutine.current_yield = new YieldCustomYieldInstruction(customYield); } else if (current is WWW) { coroutine.current_yield = new YieldWWW((WWW)current); } else if (current is WaitForFixedUpdate || current is WaitForEndOfFrame) { coroutine.current_yield = new YieldDefault(); } else if (current is AsyncOperation asyncOperation) { coroutine.current_yield = new YieldAsync(asyncOperation); } else if (current is PausableCoroutine co) { coroutine.current_yield = new YieldNestedCoroutine(co); } else { Debug.LogException( new Exception("<" + coroutine.method_name + "> yielded an unknown or unsupported type! (" + current.GetType() + ")"), null); coroutine.current_yield = new YieldDefault(); } return(true); }
public static PausableCoroutine StopAndStartPausableCoroutine(this MonoBehaviour self, ref PausableCoroutine saveCo, IEnumerator toStartIE) { return(MonoBehaviourUtil.StopAndStartPausableCoroutine(self, ref saveCo, toStartIE)); }
void Update() { // LogCat.log("ggggg"); float deltaTime = Time.deltaTime; #if UNITY_EDITOR if (!EditorApplication.isPlayingOrWillChangePlaymode) { deltaTime = Time.realtimeSinceStartup - previousTimeSinceStartup; previousTimeSinceStartup = Time.realtimeSinceStartup; } #endif if (this.is_paused) { return; } if (deltaTime == 0f) { return; } if (coroutine_dict.Count == 0) { return; } temp_coroutine_list.Clear(); foreach (var pair in coroutine_dict) { temp_coroutine_list.Add(pair.Value); } for (var i = temp_coroutine_list.Count - 1; i >= 0; i--) { List <PausableCoroutine> coroutines = temp_coroutine_list[i]; for (int j = coroutines.Count - 1; j >= 0; j--) { PausableCoroutine coroutine = coroutines[j]; if (coroutine.is_paused) { continue; } if (!coroutine.current_yield.IsDone(deltaTime)) { continue; } if (!MoveNext(coroutine)) { coroutines.RemoveAt(j); coroutine.current_yield = null; coroutine.isFinished = true; } if (coroutines.Count == 0) { coroutine_dict.Remove(coroutine.owner_unique_hash); } } } }