public CoroutineController(MonoBehaviour mono, IEnumerator routine)
 {
     _item    = new CoroutineItem();
     _mono    = mono;
     _routine = routine;
     ResetData();
 }
예제 #2
0
        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);
        }
예제 #3
0
        public void StartCoroutine(IEnumerator routine)
        {
            var item = new CoroutineItem {
                Routine = routine, Next = null
            };

            AddCoroutine(item, (workerThread != Thread.CurrentThread));
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
 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);
         }
     }
 }