예제 #1
0
        public void UpdateCoroutine()
        {
            IEnumerator node = null;

            foreach (var coroutine in coroutineList)
            {
                bool next = true;
                if (coroutine.Current is IWait)
                {
                    IWait wait = (IWait)coroutine.Current;
                    // UnityEngine.Debug.LogError("迭代协程 "+(wait as WaitForSeconds).curTime);
                    if (wait.Tick())
                    {
                        next = coroutine.MoveNext();
                    }
                }
                else
                {
                    next = coroutine.MoveNext();
                }
                if (!next)
                {
                    endList.Add(coroutine);
                }
            }

            if (endList.Count > 0)
            {
                foreach (var c in endList)
                {
                    coroutineList.Remove(c);
                }
                endList.Clear();
            }
        }
예제 #2
0
        public bool MoveNext()
        {
            if (_routine == null)
            {
                return(false);
            }

            object current = _routine.Current;

            if (current is IWait)
            {
                IWait wait = (IWait)current;
                //检测等待条件,条件满足,跳到迭代器的下一元素 (IEnumerator方法里的下一个yield)
                if (!wait.Tick())
                {
                    return(true);
                }
            }

            if (current != null)
            {
                if (!AsyncCompleteChecker.IsCompleted(current))
                {
                    return(true);
                }
            }

            Completed = !_routine.MoveNext();

            return(!Completed);
        }
예제 #3
0
        public void UpdateCoroutine()
        {
            var node = coroutineList.First;

            while (node != null)
            {
                IEnumerator ie  = node.Value;
                bool        ret = true;
                if (ie.Current is IWait)
                {
                    IWait wait = (IWait)ie.Current;
                    //检测等待条件,条件满足,跳到迭代器的下一元素 (IEnumerator方法里的下一个yield)
                    if (wait.Tick())
                    {
                        ret = ie.MoveNext();
                    }
                }
                else
                {
                    ret = ie.MoveNext();
                }
                //迭代器没有下一个元素了,删除迭代器(IEnumerator方法执行结束)
                if (!ret)
                {
                    coroutineList.Remove(node);
                }
                //下一个迭代器
                node = node.Next;
            }
        }
예제 #4
0
        public bool MoveNext()
        {
            if (_routine == null)
            {
                return(false);
            }

            //看迭代器当前的流程控制(即yield return 后边的对象)
            //是否是我们当前IWait对象,如果是,看是否满足moveNext的条件
            IWait wait     = _routine.Current as IWait;
            bool  moveNext = true;

            if (wait != null)
            {
                moveNext = wait.Tick();
            }

            if (!moveNext)
            {
                //此处有些不好理解。当时间没有到时,我们应该返回true
                //告诉管理器我们后边还有对象需要下一次继续迭代
                Console.WriteLine("[Coroutine] not move next");
                return(true);
            }
            else
            {
                //此时所有等待时间或者帧都已经迭代完毕,看IEnumerator对象后续是否还有yield return对象
                //将此结果通知给管理器,管理器会在下一次迭代时决定是否继续迭代该Coroutine对象
                Console.WriteLine("[Coroutine] move next");
                return(_routine.MoveNext());
            }
        }