コード例 #1
0
 /// <summary>
 /// Start this instance.
 /// </summary>
 void Start()
 {
     if (timeLeft > 0f)
     {
         cooldownCoroutine = coroutineContainer.StartCoroutine(CooldownCoroutine());
     }
 }
コード例 #2
0
ファイル: StackGroup.cs プロジェクト: TFM-AEIS/TFM
 /// <summary>
 /// Calls the drag and drop event manually from script.
 /// </summary>
 /// <param name="sourceCell">Source cell.</param>
 /// <param name="destinationCell">Destination cell.</param>
 public void CallDadEventManually(StackCell sourceCell, StackCell destinationCell)
 {
     if (myState == MyState.WaitForRequest)
     {
         if (sourceCell != null && destinationCell != null)
         {
             DadCell.DadEventDescriptor desc = new DadCell.DadEventDescriptor();
             desc.sourceCell      = sourceCell.GetComponent <DadCell>();
             desc.destinationCell = destinationCell.GetComponent <DadCell>();
             myState = MyState.Busy;
             // Operate item's drop
             eventHandkerCoroutine = coroutineContainer.StartCoroutine(EventHandler(desc));
         }
     }
 }
コード例 #3
0
        public void TestTaskDelay()
        {
            var i      = 0;
            var run    = true;
            var thread = Thread.CurrentThread.ManagedThreadId;
            var co     = CoroutineContainer.StartCoroutine(Run);

            Assert.AreEqual(0, i);
            while (run && co.IsRunning())
            {
                TimerManager.Update(TimerManager.Now + TimeSpan.FromMilliseconds(100));
                CoroutineManager.OneLoop();
                Thread.Yield();
            }
            Assert.IsTrue(co.IsSuccess());
            Assert.AreEqual(3, i);
            async IWaitable Run()
            {
                i++;
                Assert.AreEqual(thread, Thread.CurrentThread.ManagedThreadId);
                await Task.Delay(1);

                i++;
                Assert.AreEqual(thread, Thread.CurrentThread.ManagedThreadId);
                await Task.Delay(1);

                i++;
                Assert.AreEqual(thread, Thread.CurrentThread.ManagedThreadId);
                run = false;
            }
        }
コード例 #4
0
        public void TestCascade()
        {
            var i  = 0;
            var co = CoroutineContainer.StartCoroutine(RunFather());

            Assert.IsTrue(co.IsRunning());
            Assert.AreEqual(0, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(1, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(2, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(4, i);
            Assert.IsTrue(co.IsSuccess());
            Tick();
            Assert.IsTrue(co.IsSuccess());

            IEnumerable RunFather()
            {
                i++;
                yield return(CoroutineContainer.StartCoroutine(RunChild()));

                i++;
            }

            IEnumerable RunChild()
            {
                i++;
                yield return(null);

                i++;
            }
        }
コード例 #5
0
        public void TestClear()
        {
            var i = 0;

            CoroutineContainer.StartCoroutine(Run());
            CoroutineContainer.StartCoroutine(Run());

            Assert.AreEqual(0, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(0, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(2, i);

            CoroutineContainer.ClearAllCoroutines();

            CoroutineManager.OneLoop();
            Assert.AreEqual(2, i);

            IEnumerable Run()
            {
                while (true)
                {
                    yield return(null);

                    i++;
                }
            }
        }
コード例 #6
0
        public void Test2()
        {
            var i  = 0;
            var co = CoroutineContainer.StartCoroutine(Run());

            Assert.AreEqual(0, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(0, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(1, i);
            Tick();
            co.Throw();
            Assert.AreEqual(1, i);
            Assert.IsTrue(co.IsSuccess());

            IEnumerable Run()
            {
                Assert.AreEqual(0, i);
                yield return(null);

                Assert.AreEqual(0, i);
                i++;
                Assert.AreEqual(1, i);
            }
        }
コード例 #7
0
        public void TestCascadeThrow3()
        {
            var i = 0;

            CoroutineContainer.StartCoroutine(RunFather());

            Assert.AreEqual(0, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(1, i);
            Tick();

            //handle
            Assert.AreEqual(-10, i);

            IEnumerable RunFather()
            {
                i++;

                yield return(CoroutineContainer.StartCoroutine(RunChild()).Catch(e =>
                {
                    i = -10;
                }));

                Assert.Fail();
            }

            IEnumerable RunChild()
            {
                i++;
                yield return(null);

                i++;
                throw new ArgumentException();
            }
        }
コード例 #8
0
        public void TestAbort1()
        {
            var i = 0;

            CoroutineContainer.StartCoroutine(RunFather()).With(out var co);
            Assert.AreEqual(0, i);

            for (var tick = 0; tick < 1000; tick++)
            {
                CoroutineManager.OneLoop();
                if (i == 10)
                {
                    co.Abort();
                }
            }
            Assert.AreEqual(10, i);

            IEnumerable RunFather()
            {
                while (true)
                {
                    i++;
                    yield return(null);
                }
            }
        }
コード例 #9
0
        public void TestCascadeThrow2()
        {
            var i  = 0;
            var co = CoroutineContainer.StartCoroutine(RunFather());

            Assert.AreEqual(0, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(1, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(2, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(3, i);
            Assert.IsTrue(co.IsError());
            Tick();

            //handle
            Assert.AreEqual(3, i);

            IEnumerable RunFather()
            {
                i++;
                yield return(CoroutineContainer.StartCoroutine(RunChild()));

                Assert.Fail();
            }

            IEnumerable RunChild()
            {
                i++;
                yield return(null);

                i++;
                throw new ArgumentException();
            }
        }
コード例 #10
0
        public void TestYield()
        {
            var i  = 0;
            var co = CoroutineContainer.StartCoroutine(Run());

            Assert.AreEqual(0, i);
            Assert.IsTrue(co.IsRunning());

            CoroutineManager.OneLoop();
            Assert.AreEqual(1, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(2, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(3, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(3, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(3, i);

            Assert.IsTrue(co.IsSuccess());

            IEnumerable Run()
            {
                i++;
                yield return(WaitFor.Yield());

                i++;
                yield return(WaitFor.Yield());

                i++;
            }
        }
コード例 #11
0
        public void TestCascadeThrow1()
        {
            var i  = 0;
            var co = CoroutineContainer.StartCoroutine(RunFather());

            Assert.AreEqual(0, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(1, i);
            Assert.IsTrue(co.IsRunning());
            Tick();
            Assert.AreEqual(1, i);
            Assert.IsTrue(co.IsError());

            IEnumerable RunFather()
            {
                i++;
                yield return(CoroutineContainer.StartCoroutine(RunChild(true)));

                Assert.Fail();
            }

            IEnumerable RunChild(bool b)
            {
                if (b)
                {
                    throw new ArgumentException();
                }
                yield break;
            }
        }
コード例 #12
0
        public void TestAwait()
        {
            var i  = 0;
            var co = CoroutineContainer.StartCoroutine(Run);

            Assert.AreEqual(0, i);
            Assert.IsTrue(co.IsRunning());

            CoroutineManager.OneLoop();
            Assert.AreEqual(1, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(2, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(3, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(3, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(3, i);

            Assert.IsTrue(co.IsSuccess());

            async IWaitable Run()
            {
                i++;
                await WaitFor.Yield();

                i++;
                await WaitFor.Yield();

                i++;
            }
        }
コード例 #13
0
 /// <summary>
 /// Starts the highlight.
 /// </summary>
 public void StartHighlight()
 {
     if (inited == false)
     {
         Init();
     }
     highlightCoroutine = coroutineContainer.StartCoroutine(HighlightCoroutine());
 }
コード例 #14
0
        public void TestAbort3()
        {
            var i = 0;
            var j = 0;

            var co2 = CoroutineContainer.StartCoroutine(RunChild());

            Assert.AreEqual(0, i);

            CoroutineManager.OneLoop();
            Assert.AreEqual(1, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(2, i);

            var co1 = CoroutineContainer.StartCoroutine(RunFather());

            Assert.AreEqual(2, i);

            CoroutineManager.OneLoop();
            //father++ child++
            Assert.AreEqual(4, i);
            CoroutineManager.OneLoop();
            //father wait child++
            Assert.AreEqual(5, i);

            co2.Abort();
            Assert.AreEqual(6, i);
            Assert.AreEqual(1, j);

            CoroutineManager.OneLoop();
            //father++ child abort
            Assert.IsTrue(co2.IsAborted());
            Assert.AreEqual(6, i);

            Tick();
            Assert.AreEqual(6, i);
            Assert.AreEqual(1, j);

            Assert.AreEqual(WaitableStatus.Abort, co2.Status);
            Assert.AreEqual(WaitableStatus.Success, co1.Status);

            IEnumerable RunFather()
            {
                i++;
                yield return(co2.Catch(e => j++));

                i++;
            }

            IEnumerable RunChild()
            {
                while (true)
                {
                    i++;
                    yield return(null);
                }
            }
        }
コード例 #15
0
        public void TestAbort4()
        {
            var i = 0;

            var co2 = CoroutineContainer.StartCoroutine(RunChild());

            Assert.AreEqual(0, i);

            CoroutineManager.OneLoop();
            Assert.AreEqual(1, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(2, i);

            var co1 = CoroutineContainer.StartCoroutine(RunFather());

            Assert.AreEqual(2, i);

            CoroutineManager.OneLoop();
            Assert.AreEqual(4, i);

            co1.Abort(false);
            Assert.AreEqual(4, i);

            CoroutineManager.OneLoop();
            Assert.AreEqual(5, i);

            CoroutineManager.OneLoop();
            Assert.AreEqual(6, i);

            IEnumerable RunFather()
            {
                i++;
                yield return(co2);

                i++;
            }

            IEnumerable RunChild()
            {
                while (true)
                {
                    i++;
                    yield return(null);
                }
            }
        }
コード例 #16
0
        public void Test1()
        {
            var i  = 0;
            var co = CoroutineContainer.StartCoroutine(Run());

            Assert.AreEqual(0, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(1, i);
            Tick();
            Assert.AreEqual(1, i);
            Assert.IsTrue(co.IsSuccess());

            IEnumerable Run()
            {
                i++;
                yield break;
            }
        }
コード例 #17
0
        public void TestAbort2()
        {
            var       i   = 0;
            IWaitable co2 = null;

            var co1 = CoroutineContainer.StartCoroutine(RunFather());

            Assert.AreEqual(0, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(1, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(2, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(3, i);
            co1.Abort();
            Assert.AreEqual(3, i);
            CoroutineManager.OneLoop();
            Assert.AreEqual(3, i);

            Tick();
            Assert.AreEqual(3, i);
            Assert.AreEqual(WaitableStatus.Abort, co1.Status);
            Assert.AreEqual(WaitableStatus.Abort, co2.Status);
            Assert.IsTrue(co1.IsAborted());
            Assert.IsTrue(co2.IsAborted());

            IEnumerable RunFather()
            {
                i++;
                co2 = CoroutineContainer.StartCoroutine(RunChild());
                yield return(co2);

                i++;
            }

            IEnumerable RunChild()
            {
                while (true)
                {
                    i++;
                    yield return(null);
                }
            }
        }
コード例 #18
0
        public void TestThrow()
        {
            var i = 0;

            Assert.AreEqual(0, i);
            var co = CoroutineContainer.StartCoroutine(Run(true));

            Assert.AreEqual(0, i);
            Tick();
            Assert.AreEqual(0, i);
            Assert.IsTrue(co.IsError());

            IEnumerable Run(bool t)
            {
                if (t)
                {
                    throw new ArgumentException();
                }
                i++;
                yield return(null);

                i++;
            }
        }
コード例 #19
0
        public void Test1()
        {
            var i      = 0;
            var thread = Thread.CurrentThread.ManagedThreadId;
            var co     = CoroutineContainer.StartCoroutine(Run);

            Assert.AreEqual(0, i);
            Tick();
            Assert.AreEqual(3, i);
            Assert.IsTrue(co.IsSuccess());
            async IWaitable Run()
            {
                i++;
                Assert.AreEqual(thread, Thread.CurrentThread.ManagedThreadId);
                await WaitFor.Seconds(TimerManager, 0.1);

                i++;
                Assert.AreEqual(thread, Thread.CurrentThread.ManagedThreadId);
                await WaitFor.Seconds(TimerManager, 0.1);

                i++;
                Assert.AreEqual(thread, Thread.CurrentThread.ManagedThreadId);
            }
        }
コード例 #20
0
 /// <summary>
 /// Starts the highlight.
 /// </summary>
 public void StartHighlight()
 {
     Init();
     highlightCoroutine = coroutineContainer.StartCoroutine(HighlightCoroutine());
 }
コード例 #21
0
    public static Coroutine StartACoroutine(ConditionPredicate ConditionToSatisfy, System.Action ActionUntilCondtionSatisfied, System.Action OnSatisfied)
    {
        RequestInstanceCreation();

        return(Instance.StartCoroutine(GenericRoutine(ConditionToSatisfy, ActionUntilCondtionSatisfied, OnSatisfied)));
    }