public IEnumerator GameObjectStaysDisabled()
        {
            // Given an active training scene object and a training course with disable game object behavior,
            TrainingSceneObject  toDisable = TestingUtils.CreateSceneObject("ToDisable");
            EndlessConditionMock trigger   = new EndlessConditionMock();

            ICourse course = new LinearTrainingBuilder("Course")
                             .AddChapter(new LinearChapterBuilder("Chapter")
                                         .AddStep(new BasicCourseStepBuilder("Step")
                                                  .Disable(toDisable))
                                         .AddStep(new BasicCourseStepBuilder("Step")
                                                  .AddCondition(trigger)))
                             .Build();

            course.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // When the behavior is activated and after the step is completed
            CourseRunner.Initialize(course);
            CourseRunner.Run();

            yield return(new WaitUntil(() => course.Data.FirstChapter.Data.Steps[1].LifeCycle.Stage == Stage.Active));

            trigger.Autocomplete();

            yield return(new WaitUntil(() => course.Data.FirstChapter.Data.Steps[1].LifeCycle.Stage == Stage.Inactive));

            // Then the training scene object stays disabled.
            Assert.False(toDisable.GameObject.activeSelf);

            // Cleanup.
            TestingUtils.DestroySceneObject(toDisable);

            yield break;
        }
        public IEnumerator GameObjectIsEnabledAfterActivation()
        {
            // Given an active training scene object and a training with enable game object behavior,
            TrainingSceneObject toEnable = TestingUtils.CreateSceneObject("toEnable");

            toEnable.GameObject.SetActive(false);

            EndlessConditionMock trigger = new EndlessConditionMock();

            ICourse course = new LinearTrainingBuilder("Training")
                             .AddChapter(new LinearChapterBuilder("Chapter")
                                         .AddStep(new BasicCourseStepBuilder("Step")
                                                  .Enable(toEnable)
                                                  .AddCondition(trigger)))
                             .Build();

            course.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            CourseRunner.Initialize(course);
            CourseRunner.Run();

            // When the behavior is activated
            CourseRunner.Initialize(course);
            CourseRunner.Run();

            yield return(new WaitUntil(() => course.Data.FirstChapter.Data.Steps[0].LifeCycle.Stage == Stage.Active));

            // Then the training scene object is enabled.
            Assert.True(toEnable.GameObject.activeSelf);

            // Cleanup
            TestingUtils.DestroySceneObject(toEnable);

            yield break;
        }
コード例 #3
0
        private void FastForwardChapters(int numberOfChapters)
        {
            // Skip if no chapters have to be fast-forwarded.
            if (numberOfChapters == 0)
            {
                return;
            }

            CourseRunner.SkipChapters(numberOfChapters);
        }
コード例 #4
0
        private IEnumerator Start()
        {
            // Skip the first two frames to give VRTK time to initialize.
            yield return(null);

            yield return(null);

            // Load the currently selected training course.
            string  coursePath     = RuntimeConfigurator.Instance.GetSelectedCourse();
            ICourse trainingCourse = RuntimeConfigurator.Configuration.LoadCourse(coursePath);

            // Start the training execution.
            CourseRunner.Initialize(trainingCourse);
            CourseRunner.Run();
        }
コード例 #5
0
ファイル: ChapterTests.cs プロジェクト: VaLiuM09/Creator
        public IEnumerator ActivationIsDone()
        {
            // Setup Chapter
            Chapter chapter = TestLinearChapterBuilder.SetupChapterBuilder(1, false).Build();

            // Activate should work on simple steps.
            CourseRunner.Initialize(new Course("Course", chapter));
            CourseRunner.Run();

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

            // Chapter should be finished now.
            Assert.AreEqual(Stage.Inactive, chapter.LifeCycle.Stage);
        }
コード例 #6
0
        private void SetupSkipStepPicker()
        {
            // Dropdown.onValueChanged won't be call if Dropdown.value is equal to the selected value.
            // Dropdown.value can't be less than 0 or grater than Dropdown.options.Count -1.
            // This causes the dropdown to never call onValueChanged in cases when there is only 1 transition.
            // By setting the value to be out of range from the "editor" instead than from Dropdown.value we ensure that Dropdown.onValueChanged is always called.
            skipStepPickerEditorValueField = skipStepPicker.GetType().GetField("m_Value", BindingFlags.NonPublic | BindingFlags.Instance);

            // When a target step was chosen,
            skipStepPicker.onValueChanged.AddListener(index =>
            {
                // If there's an active step and it's not the last step,
                if (displayedStep != null && index < displayedStep.Data.Transitions.Data.Transitions.Count && displayedStep.LifeCycle.Stage != Stage.Inactive)
                {
                    CourseRunner.SkipStep(displayedStep.Data.Transitions.Data.Transitions[index]);
                }
            });
        }
コード例 #7
0
        private void SetupStartTrainingButton()
        {
            // When user clicks on Start Training button,
            startTrainingButton.onClick.AddListener(() =>
            {
                if (CourseRunner.Current == null)
                {
                    Debug.LogError("No training course is selected.", RuntimeConfigurator.Instance.gameObject);
                    return;
                }

                //Skip all chapters before selected.
                FastForwardChapters(chapterPicker.value);

                // Start the training
                CourseRunner.Run();
            });
        }
コード例 #8
0
        public IEnumerator FastForwardActivatingCourse()
        {
            // Given an activated training
            Course course = new LinearTrainingBuilder("Training Course")
                            .AddChapter(new LinearChapterBuilder("Chapter")
                                        .AddStep(new BasicStepBuilder("Step")
                                                 .AddCondition(new EndlessConditionMock())))
                            .Build();

            CourseRunner.Initialize(course);
            CourseRunner.Run();

            // When you mark it to fast-forward,
            course.LifeCycle.MarkToFastForward();

            // Then it finishes activation.
            Assert.AreEqual(Stage.Active, course.LifeCycle.Stage);
            yield break;
        }
コード例 #9
0
        private void SetupTraining()
        {
            // Load training course from a file.
            string coursePath = RuntimeConfigurator.Instance.GetSelectedCourse();

            // Try to load the in the [TRAINING_CONFIGURATION] selected training course.
            try
            {
                trainingCourse = RuntimeConfigurator.Configuration.LoadCourse(coursePath);
            }
            catch (Exception exception)
            {
                Debug.LogError($"{exception.GetType().Name}, {exception.Message}\n{exception.StackTrace}", RuntimeConfigurator.Instance.gameObject);
                return;
            }

            // Initializes the training course. That will synthesize an audio for the training instructions, too.
            CourseRunner.Initialize(trainingCourse);
        }
コード例 #10
0
        public IEnumerator OneChapterCourse()
        {
            Chapter chapter1 = TestLinearChapterBuilder.SetupChapterBuilder(3, false).Build();
            Course  course   = new Course("MyCourse", chapter1);

            CourseRunner.Initialize(course);
            CourseRunner.Run();

            Debug.Log(chapter1.LifeCycle.Stage);
            yield return(null);

            Assert.AreEqual(Stage.Activating, chapter1.LifeCycle.Stage);

            while (chapter1.LifeCycle.Stage != Stage.Inactive)
            {
                Debug.Log(chapter1.LifeCycle.Stage);
                yield return(null);
            }

            Assert.AreEqual(Stage.Inactive, chapter1.LifeCycle.Stage);
        }
コード例 #11
0
        public IEnumerator FastForwardInactiveCourseAndActivateIt()
        {
            // Given a training
            Course course = new LinearTrainingBuilder("Training Course")
                            .AddChapter(new LinearChapterBuilder("Chapter")
                                        .AddStep(new BasicStepBuilder("Step")
                                                 .AddCondition(new EndlessConditionMock())))
                            .Build();

            // When you mark it to fast-forward and activate it,
            course.LifeCycle.MarkToFastForward();

            CourseRunner.Initialize(course);
            CourseRunner.Run();

            yield return(null);

            // Then it autocompletes.
            Assert.AreEqual(Stage.Inactive, course.LifeCycle.Stage);
            yield break;
        }
コード例 #12
0
        public IEnumerator TwoChapterCourse()
        {
            Chapter chapter1 = TestLinearChapterBuilder.SetupChapterBuilder(3, false).Build();
            Chapter chapter2 = TestLinearChapterBuilder.SetupChapterBuilder().Build();
            Course  course   = new Course("MyCourse", new List <IChapter>
            {
                chapter1,
                chapter2
            });

            CourseRunner.Initialize(course);
            CourseRunner.Run();

            yield return(new WaitUntil(() => chapter1.LifeCycle.Stage == Stage.Activating));

            Assert.AreEqual(Stage.Inactive, chapter2.LifeCycle.Stage);

            yield return(new WaitUntil(() => chapter2.LifeCycle.Stage == Stage.Activating));

            Assert.AreEqual(Stage.Inactive, chapter1.LifeCycle.Stage);
            Assert.AreEqual(Stage.Activating, chapter2.LifeCycle.Stage);
        }
コード例 #13
0
        private void SetupStartTrainingButton()
        {
            // When user clicks on Start Training button,
            startTrainingButton.onClick.AddListener(() =>
            {
                if (CourseRunner.Current == null)
                {
                    Debug.LogError("No training course is selected.", RuntimeConfigurator.Instance.gameObject);
                    return;
                }

                // Subscribe to the "stage changed" event of the current training in order to change the skip step button to the start button after finishing the training.
                CourseRunner.Current.LifeCycle.StageChanged += (sender, args) =>
                {
                    if (args.Stage == Stage.Inactive)
                    {
                        skipStepPicker.gameObject.SetActive(false);
                        startTrainingButton.gameObject.SetActive(true);
                    }
                };

                //Skip all chapters before selected.
                FastForwardChapters(chapterPicker.value);

                // Start the training
                CourseRunner.Run();

                // Show the skip step button instead of the start button.
                skipStepPicker.gameObject.SetActive(true);
                startTrainingButton.gameObject.SetActive(false);

                // Disable button as you have to reset scene before starting the training again.
                startTrainingButton.interactable = false;
                // Disable the language picker as it is not allowed to change the language during the training's execution.
                languagePicker.interactable = false;
            });
        }
コード例 #14
0
        public IEnumerator EventsAreThrown()
        {
            Chapter chapter1 = TestLinearChapterBuilder.SetupChapterBuilder(3, false).Build();
            Chapter chapter2 = TestLinearChapterBuilder.SetupChapterBuilder(3, false).Build();
            Course  course   = new Course("MyCourse", new List <IChapter>
            {
                chapter1,
                chapter2
            });

            bool wasStarted   = false;
            bool wasCompleted = false;

            course.LifeCycle.StageChanged += (obj, args) =>
            {
                if (args.Stage == Stage.Activating)
                {
                    wasStarted = true;
                }
                else if (args.Stage == Stage.Active)
                {
                    wasCompleted = true;
                }
            };

            CourseRunner.Initialize(course);
            CourseRunner.Run();

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

            Assert.IsTrue(wasStarted);
            Assert.IsTrue(wasCompleted);
        }
コード例 #15
0
        public IEnumerator ActivationBehavior()
        {
            // Given a linear three step course with 3 ActivationStageBehaviorMock set to Activation and an EndlessConditionMock
            IBehavior behavior1 = new ActivationStageBehaviorMock(BehaviorExecutionStages.Activation);
            IBehavior behavior2 = new ActivationStageBehaviorMock(BehaviorExecutionStages.Activation);
            IBehavior behavior3 = new ActivationStageBehaviorMock(BehaviorExecutionStages.Activation);

            TestLinearChapterBuilder chapterBuilder = TestLinearChapterBuilder.SetupChapterBuilder(3, true);

            chapterBuilder.Steps[0].Data.Behaviors.Data.Behaviors = new List <IBehavior> {
                behavior1
            };
            chapterBuilder.Steps[1].Data.Behaviors.Data.Behaviors = new List <IBehavior> {
                behavior2
            };
            chapterBuilder.Steps[2].Data.Behaviors.Data.Behaviors = new List <IBehavior> {
                behavior3
            };
            IChapter chapter = chapterBuilder.Build();

            ICourse course = new Course("course", chapter);

            // And given a "restricted" and an "unrestricted" mode.
            IMode restricted   = new Mode("Restricted", new WhitelistTypeRule <IOptional>().Add <ActivationStageBehaviorMock>());
            IMode unrestricted = new Mode("Unrestricted", new WhitelistTypeRule <IOptional>());

            // When running it and changing the mode during execution several times,
            // Then the corresponding ActivationStageBehaviorMock of the current step is activated and deactivated accordingly.
            // The other ActivationStageBehaviorMock of the other steps stay inactive.
            CourseRunner.Initialize(course);
            CourseRunner.Run();
            course.Configure(unrestricted);

            yield return(new WaitUntil(() => behavior1.LifeCycle.Stage == Stage.Activating));

            Assert.AreEqual(Stage.Activating, behavior1.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior2.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior3.LifeCycle.Stage);

            course.Configure(restricted);

            Assert.AreEqual(Stage.Inactive, behavior1.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior2.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior3.LifeCycle.Stage);

            ICondition condition1 = course.Data.FirstChapter.Data.FirstStep.Data.Transitions.Data.Transitions[0].Data.Conditions[0];

            yield return(new WaitUntil(() => condition1.LifeCycle.Stage == Stage.Active));

            condition1.Autocomplete();

            ICondition condition2 = course.Data.FirstChapter.Data.Steps[1].Data.Transitions.Data.Transitions[0].Data.Conditions[0];

            yield return(new WaitUntil(() => condition2.LifeCycle.Stage == Stage.Active));

            Assert.AreEqual(Stage.Inactive, behavior1.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior2.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior3.LifeCycle.Stage);

            course.Configure(unrestricted);

            Assert.AreEqual(Stage.Inactive, behavior1.LifeCycle.Stage);
            Assert.AreEqual(Stage.Activating, behavior2.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior3.LifeCycle.Stage);

            condition2.Autocomplete();

            ICondition condition3 = course.Data.FirstChapter.Data.Steps[2].Data.Transitions.Data.Transitions[0].Data.Conditions[0];

            yield return(new WaitUntil(() => condition3.LifeCycle.Stage == Stage.Active));

            Assert.AreEqual(Stage.Inactive, behavior1.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior2.LifeCycle.Stage);
            Assert.AreEqual(Stage.Active, behavior3.LifeCycle.Stage);

            course.Configure(restricted);

            Assert.AreEqual(Stage.Inactive, behavior1.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior2.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior3.LifeCycle.Stage);

            course.Configure(unrestricted);

            Assert.AreEqual(Stage.Inactive, behavior1.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior2.LifeCycle.Stage);
            Assert.AreEqual(Stage.Activating, behavior3.LifeCycle.Stage);

            condition3.Autocomplete();

            yield return(new WaitUntil(() => condition3.LifeCycle.Stage == Stage.Inactive));

            Assert.AreEqual(Stage.Inactive, behavior1.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior2.LifeCycle.Stage);
            Assert.AreEqual(Stage.Active, behavior3.LifeCycle.Stage);
        }