Exemplo n.º 1
0
 public static async AwaitableCoroutine DelaySecond(float second)
 {
     for (var i = 0.0f; i < second; i += Engine.DeltaSecond)
     {
         await AwaitableCoroutine.Yield();
     }
 }
        public void AwaitForLoop()
        {
            var runner  = new CoroutineRunner();
            var counter = new Counter();

            var co = runner.Create(async() =>
            {
                for (var i = 0; i < 5; i++)
                {
                    counter.Inc();
                    await AwaitableCoroutine.Yield();
                }
                counter.Inc();
            });

            Assert.False(co.IsCompleted);
            Assert.Equal(0, counter.Count);
            Assert.False(co.IsCompleted);

            for (var i = 1; i <= 5; i++)
            {
                runner.Update();
                Assert.False(co.IsCompleted);
                Assert.Equal(i, counter.Count);
                Assert.False(co.IsCompleted);
            }

            runner.Update();
            Assert.Equal(6, counter.Count);
            Assert.True(co.IsCompleted);
        }
Exemplo n.º 3
0
 private static async AwaitableCoroutine CreateCoroutine()
 {
     for (var i = 0; i < 10; i++)
     {
         s_count++;
         await AwaitableCoroutine.Yield();
     }
 }
Exemplo n.º 4
0
        private async AwaitableCoroutine SingleYieldCoroutine(Counter counter)
        {
            counter.Inc();
            Log($"Count: {counter.Count}");
            await AwaitableCoroutine.Yield();

            counter.Inc();
            Log($"Count: {counter.Count}");
        }
Exemplo n.º 5
0
        private async AwaitableCoroutine GetCoroutine(Counter counter)
        {
            for (var i = 0; i < 3; i++)
            {
                counter.Inc();
                Log($"Count: {counter.Count}");
                await AwaitableCoroutine.Yield();
            }

            counter.Inc();
            Log($"Count: {counter.Count}");
            // inc 4
        }
Exemplo n.º 6
0
        private async AwaitableCoroutine CreateCoroutine(int target, Counter counter)
        {
            int count = 0;

            while (true)
            {
                count++;
                counter.Inc();
                if (count >= target)
                {
                    return;
                }
                await AwaitableCoroutine.Yield();
            }
        }
Exemplo n.º 7
0
        private async AwaitableCoroutine GetCoroutine2(Counter counter)
        {
            counter.Inc();
            Log($"Count: {counter.Count}");
            await AwaitableCoroutine.Yield(); // 1

            counter.Inc();
            Log($"Count: {counter.Count}"); // 2

            await GetCoroutine(counter);    // 6

            // counter.Inc();
            // Log($"Count: {counter.Count}");

            await GetCoroutine(counter); // 10

            // counter.Inc();
            // Log($"Count: {counter.Count}");
            // inc 10
        }
        public void AwaitYieldTest()
        {
            var runner  = new CoroutineRunner();
            var counter = new Counter();

            var co = runner.Create(async() =>
            {
                counter.Inc();
                await AwaitableCoroutine.Yield();
                counter.Inc();
            });

            Assert.False(co.IsCompleted);
            Assert.Equal(0, counter.Count);
            Assert.False(co.IsCompleted);

            runner.Update();
            Assert.Equal(1, counter.Count);
            Assert.False(co.IsCompleted);

            runner.Update();
            Assert.Equal(2, counter.Count);
            Assert.True(co.IsCompleted);
        }
Exemplo n.º 9
0
        private async AwaitableCoroutine CreateWithException()
        {
            await AwaitableCoroutine.Yield();

            throw new MyException();
        }