示例#1
0
        public MyCoroutine MyStartCoroutine(IEnumerator enumerator)
        {
            Dump(enumerator.Current, "curetnn");

            enumerator.MoveNext(); // 没有unity的实现细腻的原因

            Stack <IEnumerator> stack = new Stack <IEnumerator>();

            stack.Push(enumerator);
            enumeratorStackList.Add(stack);

            if (enumerator.Current is MyCoroutine)
            {
                stack.Push(((MyCoroutine)enumerator.Current).enumerator);
            }

            if (enumerator.Current is MyYieldInstruction)
            {
                MyYieldInstruction instruction = (MyYieldInstruction)enumerator.Current;
                if (!instruction.IsDone())
                {
                }
            }

            if (enumerator.Current == null)   // todo 处理第一帧的要延迟的问题
            // enumerator.Reset();
            {
            }

            // enumeratorList.Add(enumerator);
            // if (enumerator.Current == null){
            //         waitForNextFrameDic.Add(enumeratorList.Count - 1, true);
            // }

            // return new MyYieldInstruction();
            // return enumerator;
            return(new MyCoroutine(enumerator));
        }
示例#2
0
        private void LateUpdate()
        {
            for (int i = enumeratorStackList.Count - 1; i >= 0; i--)
            {
                // 如果是yield return null 应该晚一帧调用
                // if (waitForNextFrameDic.ContainsKey(i) && waitForNextFrameDic[i]){
                //     waitForNextFrameDic[i] = false;
                //     continue;
                // }

                if (enumeratorStackList[i].Peek().Current is MyYieldInstruction)
                {
                    MyYieldInstruction instruction = (MyYieldInstruction)enumeratorStackList[i].Peek().Current;
                    if (!instruction.IsDone())
                    {
                        continue;
                    }
                }

                bool tag = false;
                while (!enumeratorStackList[i].Peek().MoveNext())
                {
                    enumeratorStackList[i].Pop();
                    if (enumeratorStackList[i].Count <= 0)
                    {
                        tag = true;
                        break;
                    }
                }
                if (tag)
                {
                    enumeratorStackList.RemoveAt(i);
                    continue;
                }

                // if (!enumeratorStackList[i].Peek().MoveNext()){
                //     enumeratorStackList[i].Pop();
                //     if (enumeratorStackList[i].Count <= 0){
                //         enumeratorStackList.RemoveAt(i);
                //     }else{
                //         enumeratorStackList[i].Peek().MoveNext();
                //     }
                //     // enumeratorList.RemoveAt(i);
                //     continue;
                // }

                if (enumeratorStackList[i].Peek().Current is MyCoroutine)
                {
                    enumeratorStackList[i].Push(((MyCoroutine)enumeratorStackList[i].Peek().Current).enumerator);
                    enumeratorStackList.RemoveAt(enumeratorStackList.Count - 1);
                    continue;
                }

                if (enumeratorStackList[i].Peek().Current is MyYieldInstruction)
                {
                    MyYieldInstruction instruction = (MyYieldInstruction)enumeratorStackList[i].Peek().Current;
                    if (!instruction.IsDone())
                    {
                        continue;
                    }
                }
            }
        }