Пример #1
0
        public IEnumerator FastForwardActivatingBehavior()
        {
            // Given an UnlockObjectBehavior and a locked game object,
            GameObject          gameObject   = new GameObject("Test");
            TrainingSceneObject targetObject = gameObject.AddComponent <TrainingSceneObject>();

            UnlockObjectBehavior behavior = new UnlockObjectBehavior(targetObject);

            behavior.Configure(RuntimeConfigurator.Configuration.GetCurrentMode());

            targetObject.SetLocked(true);

            bool isLockedInitially = targetObject.IsLocked;

            behavior.LifeCycle.Activate();

            // When we mark the behavior to fast-forward,
            behavior.LifeCycle.MarkToFastForward();

            // Then it should work without any differences because the behavior is done immediately anyways.
            bool isLockedDuringStep = targetObject.IsLocked;

            behavior.LifeCycle.Deactivate();

            bool isLockedInEnd = targetObject.IsLocked;

            Assert.IsTrue(isLockedInitially, "Object should be locked initially");
            Assert.IsFalse(isLockedDuringStep, "Object should be unlocked during step");
            Assert.IsTrue(isLockedInEnd, "Object should be locked in the end");

            // Cleanup created game objects.
            Object.DestroyImmediate(gameObject);

            yield return(null);
        }
Пример #2
0
        public IEnumerator UnlockBehaviorOnLockedObject()
        {
            // Given an UnlockObjectBehavior, a locked game object, and a full training step,
            GameObject          gameObject   = new GameObject("Test");
            TrainingSceneObject targetObject = gameObject.AddComponent <TrainingSceneObject>();

            Step       step       = new Step("TestStep");
            Transition transition = new Transition();

            step.Data.Transitions.Data.Transitions.Add(transition);

            UnlockObjectBehavior unlockBehavior = new UnlockObjectBehavior(targetObject);

            step.Data.Behaviors.Data.Behaviors.Add(unlockBehavior);
            step.Configure(RuntimeConfigurator.Configuration.GetCurrentMode());

            targetObject.SetLocked(true);

            // When we fulfill the step,
            bool isLockedInitially = targetObject.IsLocked;

            step.LifeCycle.Activate();

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

                step.Update();
            }

            bool isLockedDuringStep = targetObject.IsLocked;

            step.LifeCycle.Deactivate();

            while (step.LifeCycle.Stage != Stage.Inactive)
            {
                yield return(null);

                step.Update();
            }

            bool isLockedInEnd = targetObject.IsLocked;

            // Then the game object was locked initially, unlocked during step execution, and locked after the completion.
            Assert.IsTrue(isLockedInitially, "Object should be locked initially");
            Assert.IsFalse(isLockedDuringStep, "Object should be unlocked during step");
            Assert.IsTrue(isLockedInEnd, "Object should be locked in the end");

            // Cleanup created game objects.
            Object.DestroyImmediate(gameObject);
            yield return(null);
        }