public IEnumerator CoroutineService_WaitForSecondsRealtimeAsync_WaitForSecondsRealtime()
        {
            var   coroutineService = new CoroutineService();
            float delaySeconds     = 0.05f;
            float startTimeSeconds = Time.realtimeSinceStartup;

            coroutineService.SetRealTime(startTimeSeconds);
            Task task = coroutineService.WaitForSecondsRealtimeAsync(delaySeconds);

            while (!task.IsCompleted)
            {
                coroutineService.SetRealTime(Time.realtimeSinceStartup);
                coroutineService.TickCoroutines();
                yield return(null);
            }

            Assert.IsTrue(Time.realtimeSinceStartup >= startTimeSeconds + delaySeconds, "Not enough time has passed");
        }
예제 #2
0
        public void CoroutineService_WaitForSecondsRealtimeAsync_ReturnTaskThatCompletesAfterNumSeconds()
        {
            float     timeoutSeconds = 0.2f;
            Stopwatch sw             = new Stopwatch();

            var coroutineService = new CoroutineService();

            Task task = coroutineService.WaitForSecondsRealtimeAsync(0.1f);

            sw.Start();

            while (!task.IsCompleted && sw.ElapsedMilliseconds < timeoutSeconds)
            {
                coroutineService.SetRealTime(sw.ElapsedMilliseconds * 1000);
                Thread.Sleep(1);
            }

            Assert.Less(timeoutSeconds, sw.ElapsedMilliseconds, "Task timed out");
        }
예제 #3
0
        public void CoroutineService_WaitForSecondsRealtime_CompletesCoroutineAfterNumRealtimeSeconds()
        {
            bool didComplete = false;

            var coroutineService = new CoroutineService();

            IEnumerator RunCoroutine()
            {
                yield return(coroutineService.WaitForSecondsRealtime(0.1f));

                didComplete = true;
            };

            coroutineService.StartCoroutine(RunCoroutine());

            coroutineService.SetRealTime(1);

            coroutineService.TickCoroutines();

            Assert.IsTrue(didComplete, "Did not complete");
        }
예제 #4
0
        public void CoroutineService_SetRealTime_UpdatesCoroutineRealTime()
        {
            bool isCompleted = false;

            var coroutineService = new CoroutineService();

            IEnumerator RunCoroutine()
            {
                yield return(coroutineService.WaitForSecondsRealtime(1f));

                isCompleted = true;
            }

            coroutineService.StartCoroutine(RunCoroutine());

            coroutineService.TickCoroutines(); // Still waits

            Assert.IsFalse(isCompleted, "Coroutine completed too early");

            coroutineService.SetRealTime(1f);
            coroutineService.TickCoroutines(); // Completes

            Assert.IsTrue(isCompleted, "Coroutine did not complete");
        }