Beispiel #1
0
        public IEnumerator CompleteWhenItIsDoneOnStart()
        {
            // Setup object with mocked grabbed property and activate
            GameObject obj = new GameObject("T1");

            obj.AddComponent <TouchedConditionTests.TouchablePropertyMock>();
            GrabbablePropertyMock mockedProperty = obj.AddComponent <GrabbablePropertyMock>();

            mockedProperty.SetGrabbed(false);

            yield return(new WaitForFixedUpdate());

            ReleasedCondition condition = new ReleasedCondition(mockedProperty);

            condition.LifeCycle.Activate();

            while (condition.IsCompleted == false)
            {
                yield return(null);

                condition.Update();
            }

            // Assert that condition is now completed due IsUngrabbed being true
            Assert.IsTrue(condition.IsCompleted);

            // Clean up
            Object.DestroyImmediate(obj);
        }
Beispiel #2
0
        public IEnumerator ConditionNotCompleted()
        {
            // Setup object with mocked grabbed property and activate
            GameObject obj = new GameObject("T1");

            obj.AddComponent <TouchedConditionTests.TouchablePropertyMock>();
            GrabbablePropertyMock property  = obj.AddComponent <GrabbablePropertyMock>();
            ReleasedCondition     condition = new ReleasedCondition(property);

            condition.LifeCycle.Activate();

            float startTime = Time.time;

            while (Time.time < startTime + 0.1f)
            {
                yield return(null);

                condition.Update();
            }

            // Assert after doing nothing the condition is not completed.
            Assert.IsFalse(condition.IsCompleted);

            // Clean up
            Object.DestroyImmediate(obj);
        }
Beispiel #3
0
        public IEnumerator FastForwardDoesNotCompleteCondition()
        {
            // Given an ungrabbed condition
            GameObject go = new GameObject("Meme");

            go.AddComponent <TouchedConditionTests.TouchablePropertyMock>();
            GrabbablePropertyMock mock      = go.AddComponent <GrabbablePropertyMock>();
            ReleasedCondition     condition = new ReleasedCondition(mock);

            bool wasGrabbed   = false;
            bool wasUngrabbed = false;

            mock.Grabbed += (sender, args) =>
            {
                wasGrabbed      = true;
                mock.Ungrabbed += (sendery, argsy) => wasUngrabbed = true;
            };

            // When you activate it,
            condition.LifeCycle.Activate();

            while (condition.LifeCycle.Stage != Stage.Active)
            {
                yield return(null);

                condition.Update();
            }

            // When you fast-forward it
            condition.LifeCycle.MarkToFastForward();

            // Then nothing happens.
            Assert.AreEqual(Stage.Active, condition.LifeCycle.Stage);
            Assert.IsFalse(condition.IsCompleted);
            Assert.IsFalse(wasGrabbed);
            Assert.IsFalse(wasUngrabbed);

            yield return(null);
        }
Beispiel #4
0
        public IEnumerator AutoCompleteActive()
        {
            // Given an ungrabbed condition
            GameObject go = new GameObject("Meme");

            go.AddComponent <TouchedConditionTests.TouchablePropertyMock>();
            GrabbablePropertyMock mock      = go.AddComponent <GrabbablePropertyMock>();
            ReleasedCondition     condition = new ReleasedCondition(mock);

            bool wasGrabbed   = false;
            bool wasUngrabbed = false;

            mock.Grabbed += (sender, args) =>
            {
                wasGrabbed      = true;
                mock.Ungrabbed += (sendery, argsy) => wasUngrabbed = true;
            };

            // When you activate and autocomplete it,
            condition.LifeCycle.Activate();

            while (condition.LifeCycle.Stage != Stage.Active)
            {
                yield return(null);

                condition.Update();
            }

            condition.Autocomplete();

            // Then it is completed.
            Assert.AreEqual(Stage.Active, condition.LifeCycle.Stage);
            Assert.IsTrue(condition.IsCompleted, "Condition should be complete!");
            Assert.IsTrue(wasGrabbed);
            Assert.IsTrue(wasUngrabbed);

            yield return(null);
        }