예제 #1
0
        //physicScheduler -> updateScheduler -> coroutineScheduler -> lateScheduler

        internal static void KillSchedulers()
        {
            if (_multiThreadScheduler != null)
            {
                _multiThreadScheduler.Dispose();
            }
            _multiThreadScheduler = null;

#if UNITY_5 || UNITY_5_3_OR_NEWER
            if (_coroutineScheduler != null)
            {
                _coroutineScheduler.StopAllCoroutines();
            }
            if (_physicScheduler != null)
            {
                _physicScheduler.StopAllCoroutines();
            }
            if (_lateScheduler != null)
            {
                _lateScheduler.StopAllCoroutines();
            }
            if (_updateScheduler != null)
            {
                _updateScheduler.StopAllCoroutines();
            }

            _coroutineScheduler = null;
            _physicScheduler    = null;
            _lateScheduler      = null;
            _updateScheduler    = null;
#endif
        }
예제 #2
0
    public void TestCoroutineMonoRunnerStartsTheFirstIterationImmediately()
    {
        var testFirstInstruction = TestFirstInstruction();
        var runner = new CoroutineMonoRunner("test4");

        testFirstInstruction.RunOnScheduler(runner);
        runner.Dispose();

        Assert.That(testFirstInstruction.Current, Is.EqualTo(1));
    }
예제 #3
0
        //physicScheduler -> updateScheduler -> coroutineScheduler -> lateScheduler

        static StandardSchedulers()
        {
            multiThreadScheduler = new MultiThreadRunner("MultiThreadRunner", true);
#if UNITY_5 || UNITY_5_3_OR_NEWER
            coroutineScheduler = new CoroutineMonoRunner("StandardCoroutineRunner");
            physicScheduler    = new PhysicMonoRunner("StandardPhysicRunner");
            lateScheduler      = new LateMonoRunner("StandardLateRunner");
            updateScheduler    = new UpdateMonoRunner("StandardMonoRunner");
#endif
        }
예제 #4
0
    public IEnumerator TestUnityWait()
    {
        var coroutineMonoRunner = new CoroutineMonoRunner("test1");
        ITaskRoutine <IEnumerator> taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine(coroutineMonoRunner);

        taskRoutine.SetEnumeratorProvider(new WaitForSecondsUnity().GetEnumerator);


        taskRoutine.Start();
        DateTime then = DateTime.Now;

        while (taskRoutine.isRunning == true)
        {
            yield return(null);
        }
        coroutineMonoRunner.Dispose();
        var totalSeconds = (DateTime.Now - then).TotalSeconds;

        Assert.That(totalSeconds, Is.InRange(0.9, 1.1));
    }
예제 #5
0
    public IEnumerator TaskWithUnityYieldInstructionMustRestartImmediately()
    {
        var valueRef = new ValueRef();

        using (var runner = new CoroutineMonoRunner("test3"))
        {
            var task = TaskRunner.Instance.AllocateNewTaskRoutine(runner);
            task
            .SetEnumeratorProvider(() => UnityWaitEnumerator(valueRef));

            bool stopped = false;

            DateTime time = DateTime.Now;

            task.Start(onStop: () => { stopped = true; });

            while (task.isRunning == true)
            {
                yield return(null); //stop is called inside the runner

                task.Stop();
                yield return(null); //stop is called inside the runner
            }

            var totalSeconds = (DateTime.Now - time).TotalSeconds;
            Assert.Less(totalSeconds, 0.2);
            Assert.That(stopped == true);
            Assert.That(valueRef.isDone == false);

            stopped = false;
            time    = DateTime.Now;

            yield return(task.Start(onStop: () => { stopped = true; }));

            totalSeconds = (DateTime.Now - time).TotalSeconds;
            Assert.Greater(totalSeconds, 1.9);
            Assert.Less(totalSeconds, 2.1);
            Assert.That(valueRef.isDone == true);
            Assert.That(stopped == false);
        }
    }
예제 #6
0
    public IEnumerator TestSimpleTaskRoutineStart()
    {
        yield return(null);

        using (var runner = new CoroutineMonoRunner("TestSimpleTaskRoutineStartStart"))
        {
            ValueObject result = new ValueObject();

            var taskRoutine = TaskRunner.Instance.AllocateNewTaskRoutine(runner);
            taskRoutine.SetEnumeratorProvider(() => SimpleEnumerator(result));

            var continuation = taskRoutine.Start();

            while ((continuation as IEnumerator).MoveNext())
            {
                yield return(null);
            }

            Assert.That(result.counter, Is.EqualTo(1));
        }
    }