public CoroutineController(MonoBehaviour mono, IEnumerator routine) { _item = new CoroutineItem(); _mono = mono; _routine = routine; ResetData(); }
private void AddCoroutine(CoroutineItem item, bool writeLock = false) { #if USE_QUEUE if (writeLock) { coroutineLock.EnterWriteLock(); nextCoroutines.Enqueue(item); coroutineLock.ExitWriteLock(); } else { coroutineLock.EnterUpgradeableReadLock(); nextCoroutines.Enqueue(item); coroutineLock.ExitUpgradeableReadLock(); } #else writeLock = true; if (writeLock) { coroutineLock.EnterWriteLock(); nextCoroutines.AddLast(item); coroutineLock.ExitWriteLock(); } else { coroutineLock.EnterUpgradeableReadLock(); nextCoroutines.AddLast(item); coroutineLock.ExitUpgradeableReadLock(); } #endif Interlocked.Increment(ref coroutineCount); }
public void StartCoroutine(IEnumerator routine) { var item = new CoroutineItem { Routine = routine, Next = null }; AddCoroutine(item, (workerThread != Thread.CurrentThread)); }
public static void StartCoroutine(GameObject go, IEnumerator coroutine) { var comp = go.GetComponent <CoroutineRunner>(); if (comp == null) { comp = go.AddComponent <CoroutineRunner>(); } var item = new CoroutineItem(coroutine, comp.Run(coroutine)); comp.Routines.Add(item); AsyncManager.Instance.StartCoRoutine(item.Run); }
private CoroutineItem NextCoroutine() { CoroutineItem item = null; if (curCoroutines.Count > 0) { #if USE_QUEUE item = curCoroutines.Dequeue(); #else item = curCoroutines.First.Value; curCoroutines.RemoveFirst(); #endif } if (item != null) { Interlocked.Decrement(ref coroutineCount); } return(item); }
private void UpdateCoroutine(CoroutineItem item) { if (item.Routine.MoveNext()) { if (item.Routine.Current is IYieldInstruction current) { if (!(current is CoroutineResult)) { item = new CoroutineItem { Routine = current.GetEnumerator(), Next = item }; } } AddCoroutine(item); } else { if (item.Next != null) { AddCoroutine(item.Next); } } }