Example #1
0
        public void SubCoroutine_SpawnSequentialChildren()
        {
            var coroutine = new SubCoroutine(
                spawnParallel: false, executeImmediatelly: false,
                executeChildren: new SubCoroutine[] { new SubCoroutine(), new SubCoroutine(), new SubCoroutine() });

            var scheduler = new InterleavedCoroutineScheduler();

            scheduler.Execute(coroutine);

            for (int i = 0; i < 3; i++)
            {
                scheduler.Update(0);
            }
            Assert.Equal(CoroutineStatus.Running, coroutine.Status);

            scheduler.Update(0);
            Assert.Equal(CoroutineStatus.CompletedNormal, coroutine.Status);
        }
Example #2
0
        public void SubCoroutine_ExecuteChildrenImmediatelly()
        {
            var subCoroutines = new List <SubCoroutine>()
            {
                new SubCoroutine(),
                new SubCoroutine(),
                new SubCoroutine()
            };

            var coroutine = new SubCoroutine(
                spawnParallel: true, executeImmediatelly: true, executeChildren: subCoroutines.ToArray());

            var scheduler = new InterleavedCoroutineScheduler();

            scheduler.Execute(coroutine);

            scheduler.Update(0); //< Executes ALL children with one frame
            Assert.Equal(CoroutineStatus.Running, coroutine.Status);

            scheduler.Update(0); //< All children complete
            Assert.Equal(CoroutineStatus.CompletedNormal, coroutine.Status);
        }
Example #3
0
        public void SubCoroutine_SpawnOneChild()
        {
            var subCoroutine = new SubCoroutine();
            var coroutine    = new SubCoroutine(
                false, false, subCoroutine);

            var scheduler = new InterleavedCoroutineScheduler();

            scheduler.Execute(coroutine);

            Assert.Equal(CoroutineStatus.WaitingForStart, subCoroutine.Status);

            // Yield of child executes immediatelly. As child
            // has one yield null, we expect that after one update,
            // it is still running, second update it completes
            // and also completes parent
            scheduler.Update(0);
            Assert.Equal(CoroutineStatus.Running, coroutine.Status);
            Assert.Equal(CoroutineStatus.Running, subCoroutine.Status);

            scheduler.Update(0);
            Assert.Equal(CoroutineStatus.CompletedNormal, subCoroutine.Status);
            Assert.Equal(CoroutineStatus.CompletedNormal, coroutine.Status);
        }