Esempio n. 1
0
        private static async Task <bool> TestAwaitCoroutineAsync()
        {
            var  hostBehaviour = new GameObject("Test").AddComponent <TestHostBehaviour>();
            bool result        = false;
            await UnityTaskUtil.StartCoroutineAsync(LongRunningCoroutine(() => { result = true; }), hostBehaviour);

            //If we don't await till the coroutine is fully complete result will still be false here
            return(result);
        }
Esempio n. 2
0
        public IEnumerator CanStartCoroutineFromBackgroundThread()
        {
            var hostBehaviour = new GameObject("Test").AddComponent <TestHostBehaviour>();
            var result        = false;
            var task          = Task.Run(() =>
            {
                //Start coroutine and block task thread until coroutine is complete
                Assert.IsFalse(UnityTaskUtil.CurrentThreadIsUnityThread);
                UnityTaskUtil.StartCoroutineAsync(LongRunningCoroutine(() => { result = true; }), hostBehaviour).GetAwaiter().GetResult();
            });

            yield return(new WaitUntil(() => task.IsCompleted));

            Assert.IsTrue(result);
        }
        public IEnumerator StartCoroutineAsync()
        {
            var testHost = new GameObject().AddComponent <TestHostBehaviour>();
            int count    = 0;
            int countTo  = 3;

            var task = Task.Run(() =>
            {
                var coroutine = UnityTaskUtil.StartCoroutineAsync(TestCoroutine(() =>
                {
                    count++;
                    return(count < countTo);
                }), testHost);
                //Wait for coroutine to finish
                coroutine.GetAwaiter().GetResult();
            });

            yield return(new WaitUntil(() => task.IsCompleted));

            Assert.IsTrue(count >= countTo);
        }