Exemplo n.º 1
0
        public IEnumerator TestExecuteDelayed()
        {
            var counter = 0;
            {
                MonoBehaviour myMonoBehaviour = CreateSomeMonoBehaviour();
                myMonoBehaviour.ExecuteDelayed(() => {
                    counter++;
                }, delayInMsBeforeExecution: 600);
            }
            { // while the delayed task is running check over time if the counter increases:
                yield return(new WaitForSeconds(.5f));

                Assert.AreEqual(0, counter);
                yield return(new WaitForSeconds(.2f));

                Assert.AreEqual(1, counter);
                yield return(new WaitForSeconds(2f));

                Assert.AreEqual(1, counter);
            }

            int firstDelayInMs = 100;
            var x = firstDelayInMs / 1000f;

            Assert.IsTrue(x > 0);
            Assert.AreEqual(0.1f, x);
        }
Exemplo n.º 2
0
        public IEnumerator ExampleUsage1()
        {
            MonoBehaviour myMonoBehaviour = CreateSomeMonoBehaviour();

            // Execute a task after a defined time:
            myMonoBehaviour.ExecuteDelayed(() => {
                Log.d("I am executed after 0.6 seconds");
            }, delayInSecBeforeExecution: 0.6f);

            // Execute a task multiple times:
            myMonoBehaviour.ExecuteRepeated(() => {
                Log.d("I am executed every 0.3 seconds until I return false");
                return(true);
            }, delayInSecBetweenIterations: 0.3f, delayInSecBeforeFirstExecution: .2f);

            yield return(null);
        }
Exemplo n.º 3
0
 public IEnumerator TestExecuteDelayed2()
 {
     {
         MonoBehaviour myMonoBehaviour = CreateSomeMonoBehaviour();
         myMonoBehaviour.enabled = false;
         AssertV2.Throws <Exception>(() => {
             myMonoBehaviour.ExecuteDelayed(() => { throw Log.e("Executing coroutine of disabled mono"); });
         });
     }
     {
         MonoBehaviour myMonoBehaviour = CreateSomeMonoBehaviour();
         myMonoBehaviour.gameObject.SetActive(false);
         AssertV2.Throws <Exception>(() => {
             myMonoBehaviour.ExecuteDelayed(() => { throw Log.e("Executing coroutine of inactive GO"); });
         });
     }
     yield return(null);
 }
Exemplo n.º 4
0
        public IEnumerator TestExecuteDelayed()
        {
            var counter = 0;
            {
                MonoBehaviour myMonoBehaviour = CreateSomeMonoBehaviour();
                myMonoBehaviour.ExecuteDelayed(() => {
                    counter++;
                }, delayInSecBeforeExecution: 0.6f);
            }
            { // while the delayed task is running check over time if the counter increases:
                yield return(new WaitForSeconds(.5f));

                Assert.AreEqual(0, counter);
                yield return(new WaitForSeconds(.2f));

                Assert.AreEqual(1, counter);
                yield return(new WaitForSeconds(2f));

                Assert.AreEqual(1, counter);
            }
        }