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; }
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; }
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(); }
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); }
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(); }); }
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; }
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); }
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; }
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); }
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; }); }
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); }
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); }