Beispiel #1
0
        IEnumerator _BatchCoroutines(IEnumerator[] etors)
        {
            foreach (var etor in etors)
            {
                Coex coex = StartCoroutine(etor);
                yield return(coex);

                coex.CheckError();
            }
        }
Beispiel #2
0
        IEnumerator TestBasic()
        {
            TestDeprecatedApi();
            Coex coex = StartCoroutine <int>(Basic());

            yield return(coex);

            Assert(coex.state == Coex.State.Done);
            Assert(coex.yieldCount == 11);
            Assert(coex.ReturnValue <int>() == 10);
        }
Beispiel #3
0
        internal bool Loop(CoexEngine.Process process)
        {
            if (!gameObject.activeInHierarchy || !enabled || coexCount == 0)
            {
                StopAllCoroutines();
                Clear();
                return(false);
            }

            List <Coex> list = coexs[(int)process];

            for (int i = 0; i < list.Count;)
            {
                Coex coex = list[i];
                if (coex.state != Coex.State.Running)
                {
                    list.RemoveAt(i);
                    continue;
                }

                if (coex.frameCount != Time.frameCount)
                {
                    bool wait = false;
                    if (process == CoexEngine.Process.Update)
                    {
                        object rv = coex.returnValue;
                        if (null != rv)
                        {
                            wait = (rv is CoexWaitForSeconds && !((CoexWaitForSeconds)rv).timeout) ||
                                   (rv is WWW && !((WWW)rv).isDone) ||
                                   (rv is Coex && ((Coex)rv).state == Coex.State.Running);
                        }
                    }

                    if (!wait)
                    {
                        coex.MoveNext();
                        CoexEngine.Process dispatchProcess = Dispatch(coex);
                        if (dispatchProcess != process)
                        {
                            list.RemoveAt(i);
                            coexs[(int)dispatchProcess].Add(coex);
                            continue;
                        }
                    }
                }
                ++i;
            }
            return(true);
        }
Beispiel #4
0
        IEnumerator TestExceptions()
        {
            Coex c = StartCoroutine(ThrowsBeforeYield());

            yield return(c);

            Assert(c.yieldCount == 0);
            Assert(c.state == Coex.State.Error);
            ExpectException <TestException>(c.CheckError);

            c = StartCoroutine(ThrowsAfterYield());
            yield return(c);

            Assert(c.yieldCount == 1);
            Assert(c.state == Coex.State.Error);
            ExpectException <TestException>(c.CheckError);
        }
Beispiel #5
0
        CoexEngine.Process Dispatch(Coex coex)
        {
            object rv = coex.returnValue;

            if (null != rv)
            {
                if (rv is CoexWaitForFixedUpdate)
                {
                    return(CoexEngine.Process.FixedUpdate);
                }
                else if (rv is CoexWaitForEndOfFrame)
                {
                    return(CoexEngine.Process.EndOfFrames);
                }
            }
            return(CoexEngine.Process.Update);
        }
Beispiel #6
0
 /// <summary>
 /// 停止协程的执行
 /// </summary>
 /// <param name="routine">协程object</param>
 public void StopCoroutine(Coex routine)
 {
     // NOTE(llisper):
     // i don't remove coex from coexs at this point.
     // because this function might be called inside the coroutine itself,
     // modify the coexs right away will corrupt the collection which is being iterating at this moment.
     // i leave all the removal works into Loop function
     if (routine.state == Coex.State.Running)
     {
         int i = (int)routine.process;
         if (i >= 0 && i < (int)CoexEngine.Process.Count)
         {
             if (-1 != coexs[i].IndexOf(routine))
             {
                 routine.Interrupt();
             }
         }
     }
 }
Beispiel #7
0
        internal Coex StartCoroutine(IEnumerator routine, Type rtType)
        {
            if (!addToEngine)
            {
                CoexEngine.Instance.AddBehaviour(this);
                addToEngine = true;
            }

            CheckReturnType(rtType);

            Coex c = new Coex(routine, rtType);

            c.MoveNext();
            if (c.state == Coex.State.Running)
            {
                c.process = Dispatch(c);
                coexs[(int)c.process].Add(c);
            }
            return(c);
        }
        public override void OnInspectorGUI()
        {
            CoexBehaviour script     = (CoexBehaviour)target;
            float         labelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 95f;
            EditorGUILayout.LabelField("AddToEngine: " + script.addToEngine);
            if (script.coexCount > 0)
            {
                if (foldoutList = EditorGUILayout.Foldout(foldoutList, string.Format("Coroutines({0})", script.coexCount)))
                {
                    for (int p = 0; p < script.coexs.Length; ++p)
                    {
                        EditorGUILayout.LabelField(string.Format("{0}:", (CoexEngine.Process)p));
                        ++EditorGUI.indentLevel;
                        var list = script.coexs[p];
                        for (int i = 0; i < list.Count; ++i)
                        {
                            Coex c = list[i];
                            if (c.foldout = EditorGUILayout.Foldout(c.foldout, c.routineName))
                            {
                                if (null != c.returnValueType)
                                {
                                    EditorGUILayout.LabelField("return type:", c.returnValueType.FullName);
                                }
                                if (null != c.returnValue)
                                {
                                    EditorGUILayout.LabelField("last return:", c.returnValue.ToString());
                                }
                                EditorGUILayout.LabelField("yield count:", c.yieldCount.ToString());
                            }
                        }
                        --EditorGUI.indentLevel;
                    }
                }
            }
            EditorGUIUtility.labelWidth = labelWidth;
        }
Beispiel #9
0
 public void StopCoroutine(Coex routine)
 {
     Instance.engineBehaviour.StopCoroutine(routine);
 }