コード例 #1
0
        public void TestStartCoroutine(IEnumerator routine)
        {
            TestCoroutine tt = new TestCoroutine(routine);

            lock (temp)
            {
                temp.Add(tt);
            }
        }
コード例 #2
0
        void Start()
        {
            Test t = new Test();

            foreach (var item in t)
            {
                print(item);
            }

            print("--------------------------------------------------");

            t = new Test();
            IEnumerator ie = t.GetEnumerator();

            while (ie.MoveNext())
            {
                if (ie.Current != null)
                {
                    print(ie.Current);
                }
            }

            print("--------------------------------------------------");

            Test2       t2  = new Test2();
            IEnumerator ie2 = t2.GetEnumerator();

            while (ie2.MoveNext())
            {
                if ((string)ie2.Current == "fxk")
                {
                    Thread.Sleep(200);
                }
                print(ie2.Current + "   " + Time.realtimeSinceStartup);
            }

            print("--------------------------------------------------");

            TestStartCoroutine(TestIEnumerator());
            ThreadPool.QueueUserWorkItem(delegate(object o)
            {
                while (isOpenWorkThread)
                {
                    lock (temp)
                    {
                        for (int i = 0; i < temp.Count; i++)
                        {
                            TestCoroutine tc = temp[i];
                            IEnumerator ixe  = tc.GetEnumerator();
                            if (tc.isStart == false)
                            {
                                tc.isStart = true;
                                ixe.MoveNext();
                                break;
                            }
                            else
                            {
                                if (ixe.Current == null)
                                {
                                    ixe.MoveNext();
                                    break;
                                }
                                else if (ixe.Current is TestWaitMillisecond)
                                {
                                    TestWaitMillisecond tsc = ixe.Current as TestWaitMillisecond;
                                    if (tc.time >= tsc.sec)
                                    {
                                        tc.time = 0;
                                        ixe.MoveNext();
                                    }
                                    else
                                    {
                                        tc.time += 16;
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    Thread.Sleep(16);
                }
            });
        }