public IEnumerator UnlockObjectBehavior() { // Given a training with UnlockObjectBehavior TrainingSceneObject trainingSceneObject = TestingUtils.CreateSceneObject("TestObject"); ICourse training1 = new LinearTrainingBuilder("Training") .AddChapter(new LinearChapterBuilder("Chapter") .AddStep(new BasicStepBuilder("Step") .AddBehavior(new UnlockObjectBehavior(trainingSceneObject)))) .Build(); // When we serialize and deserialize it ICourse training2 = Serializer.CourseFromByteArray(Serializer.CourseToByteArray(training1)); UnlockObjectBehavior behavior1 = training1.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as UnlockObjectBehavior; UnlockObjectBehavior behavior2 = training2.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as UnlockObjectBehavior; // Then that behavior's target should not change. Assert.IsNotNull(behavior1); Assert.IsNotNull(behavior2); Assert.AreEqual(behavior1.Data.Target.Value, behavior2.Data.Target.Value); // Cleanup TestingUtils.DestroySceneObject(trainingSceneObject); return(null); }
public IEnumerator EnableGameObjectBehavior() { // Given EnableGameObjectBehavior, TrainingSceneObject trainingSceneObject = TestingUtils.CreateSceneObject("TestObject"); ICourse training1 = new LinearTrainingBuilder("Training") .AddChapter(new LinearChapterBuilder("Chapter") .AddStep(new BasicCourseStepBuilder("Step") .Enable("TestObject"))) .Build(); // When we serialize and deserialize a training course with it ICourse training2 = Serializer.CourseFromByteArray(Serializer.CourseToByteArray(training1)); EnableGameObjectBehavior behavior1 = training1.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as EnableGameObjectBehavior; EnableGameObjectBehavior behavior2 = training2.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as EnableGameObjectBehavior; // Then it's target training scene object is still the same. Assert.IsNotNull(behavior1); Assert.IsNotNull(behavior2); Assert.AreEqual(behavior1.Data.Target.Value, behavior2.Data.Target.Value); TestingUtils.DestroySceneObject(trainingSceneObject); return(null); }
public IEnumerator ObjectInRangeCondition() { // Given a training with ObjectInRangeCondition, TrainingSceneObject testObjectToo = TestingUtils.CreateSceneObject("TestObjectToo"); TransformInRangeDetectorProperty detector = testObjectToo.gameObject.AddComponent <TransformInRangeDetectorProperty>(); TrainingSceneObject testObject = TestingUtils.CreateSceneObject("TestObject"); ICourse training1 = new LinearTrainingBuilder("Training") .AddChapter(new LinearChapterBuilder("Chapter") .AddStep(new BasicStepBuilder("Step") .AddCondition(new ObjectInRangeCondition(testObject, detector, 1.5f)))) .Build(); // When we serialize and deserialize it ICourse training2 = Serializer.CourseFromByteArray(Serializer.CourseToByteArray(training1)); // Then that condition's target, detector and range should stay unchanged. ObjectInRangeCondition condition1 = training1.Data.FirstChapter.Data.FirstStep.Data.Transitions.Data.Transitions.First().Data.Conditions.First() as ObjectInRangeCondition; ObjectInRangeCondition condition2 = training2.Data.FirstChapter.Data.FirstStep.Data.Transitions.Data.Transitions.First().Data.Conditions.First() as ObjectInRangeCondition; Assert.IsNotNull(condition1); Assert.IsNotNull(condition2); Assert.AreEqual(condition1.Data.Range, condition2.Data.Range); Assert.AreEqual(condition1.Data.Target.Value, condition2.Data.Target.Value); Assert.AreEqual(condition1.Data.DistanceDetector.Value, condition2.Data.DistanceDetector.Value); // Cleanup TestingUtils.DestroySceneObject(testObjectToo); TestingUtils.DestroySceneObject(testObject); return(null); }
public IEnumerator LockObjectBehavior() { // Given a training with LockObjectBehavior TrainingSceneObject trainingSceneObject = TestingUtils.CreateSceneObject("TestObject"); ICourse training1 = new LinearTrainingBuilder("Training") .AddChapter(new LinearChapterBuilder("Chapter") .AddStep(new BasicStepBuilder("Step") .DisableAutomaticAudioHandling() .AddBehavior(new LockObjectBehavior(trainingSceneObject)))) .Build(); // When we serialize and deserialize it ICourse training2 = JsonTrainingSerializer.Deserialize(JsonTrainingSerializer.Serialize(training1)); // Then that's behavior target is still the same. LockObjectBehavior behavior1 = training1.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as LockObjectBehavior; LockObjectBehavior behavior2 = training2.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as LockObjectBehavior; Assert.IsNotNull(behavior1); Assert.IsNotNull(behavior2); Assert.AreEqual(behavior1.Data.Target.Value, behavior2.Data.Target.Value); // Cleanup TestingUtils.DestroySceneObject(trainingSceneObject); return(null); }
public IEnumerator MoveObjectBehavior() { // Given training with MoveObjectBehavior TrainingSceneObject moved = TestingUtils.CreateSceneObject("moved"); TrainingSceneObject positionProvider = TestingUtils.CreateSceneObject("positionprovider"); ICourse training1 = new LinearTrainingBuilder("Training") .AddChapter(new LinearChapterBuilder("Chapter") .AddStep(new BasicStepBuilder("Step") .AddBehavior(new MoveObjectBehavior(moved, positionProvider, 24.7f)))) .Build(); // When that training is serialized and deserialzied ICourse training2 = Serializer.CourseFromByteArray(Serializer.CourseToByteArray(training1)); // Then we should have two identical move object behaviors MoveObjectBehavior behavior1 = training1.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as MoveObjectBehavior; MoveObjectBehavior behavior2 = training2.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as MoveObjectBehavior; Assert.IsNotNull(behavior1); Assert.IsNotNull(behavior2); Assert.IsFalse(ReferenceEquals(behavior1, behavior2)); Assert.AreEqual(behavior1.Data.Target.Value, behavior2.Data.Target.Value); Assert.AreEqual(behavior1.Data.PositionProvider.Value, behavior2.Data.PositionProvider.Value); Assert.AreEqual(behavior1.Data.Duration, behavior2.Data.Duration); // Cleanup created game objects. TestingUtils.DestroySceneObject(moved); TestingUtils.DestroySceneObject(positionProvider); return(null); }
public IEnumerator GetLockablePropertiesObjectInMultipleConditions() { // Given a scene object with one lockable property and one non-lockable property used by two conditions in a transition. ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); LockablePropertyMock property = o1.GameObject.AddComponent <LockablePropertyMock>(); o1.GameObject.AddComponent <PropertyMock>(); LockableReferencingConditionMock condition1 = new LockableReferencingConditionMock(); condition1.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName); condition1.LockableProperties = new[] { new LockablePropertyData(property, true) }; LockableReferencingConditionMock condition2 = new LockableReferencingConditionMock(); condition2.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName); condition2.LockableProperties = new[] { new LockablePropertyData(property, false) }; Step step2 = new BasicStepBuilder("step2").Build(); Step step = new BasicStepBuilder("step").AddCondition(condition1).AddCondition(condition2).Build(); Transition transition = (Transition)step.Data.Transitions.Data.Transitions[0]; transition.Data.TargetStep = step2; // When counting the lockable properties in the transition. // Then there is exactly one lockable property. Assert.IsTrue(transition.GetLockableProperties().Count() == 1); yield return(null); }
public IEnumerator SecondPropertyStaysLocked() { // Given two steps and two scene objects with each one lockable property // where only the first property is referenced in the first step. ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); LockablePropertyMock property1 = o1.GameObject.AddComponent <LockablePropertyMock>(); ISceneObject o2 = TestingUtils.CreateSceneObject("o2"); LockablePropertyMock property2 = o2.GameObject.AddComponent <LockablePropertyMock>(); LockableReferencingConditionMock doNotLockAtEndOfStepCondition = new LockableReferencingConditionMock(); doNotLockAtEndOfStepCondition.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName); doNotLockAtEndOfStepCondition.LockableProperties = new[] { new LockablePropertyData(property1, false) }; Step step2 = new BasicStepBuilder("step2").Build(); Step step = new BasicStepBuilder("step") .AddCondition(doNotLockAtEndOfStepCondition) .Build(); property1.SetLocked(true); property2.SetLocked(true); step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2; // When executing the locking routine in the first step. LockHandling.Unlock(step.Data, new List <LockablePropertyData>()); // Then property 2 is locked during the first step. Assert.IsTrue(property2.IsLocked); yield return(null); }
public IEnumerator OtherPropertyLockedAfterManualUnlockFinished() { // Given a scene object with two independent lockable properties which are not referenced by any condition. ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); LockablePropertyMock property = o1.GameObject.AddComponent <LockablePropertyMock>(); LockablePropertyMock property2 = o1.GameObject.AddComponent <LockablePropertyMock>(); EndlessConditionMock condition = new EndlessConditionMock(); Step step2 = new BasicStepBuilder("step").AddCondition(new EndlessConditionMock()).Build(); Step step = new BasicStepBuilder("step").AddCondition(condition).Build(); step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2; property.SetLocked(true); property2.SetLocked(true); // When we manually unlock one property for one step. LockHandling.Unlock(step.Data, new List <LockablePropertyData>()); step.Data.Transitions.Data.Transitions.First().Autocomplete(); step.Data.Transitions.Data.Transitions.First().Data.IsCompleted = true; LockHandling.Lock(step.Data, new List <LockablePropertyData> { new LockablePropertyData(property) }); // Then the other property stays locked after the step was completed. Assert.IsTrue(property2.IsLocked); yield return(null); }
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 UnlockedAfterManualUnlockStarted() { // Given a scene object with a lockable property which is not referenced by any condition. ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); LockablePropertyMock property = o1.GameObject.AddComponent <LockablePropertyMock>(); EndlessConditionMock condition = new EndlessConditionMock(); Step step2 = new BasicStepBuilder("step").AddCondition(new EndlessConditionMock()).Build(); Step step = new BasicStepBuilder("step").AddCondition(condition).Build(); step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2; property.SetLocked(true); // When we include the property into the manualUnlocked list of the UnlockPropertiesForStepData method. LockHandling.Unlock(step.Data, new List <LockablePropertyData> { new LockablePropertyData(property) }); // Then the property is not locked. Assert.IsFalse(property.IsLocked); yield return(null); }
public IEnumerator SamePropertyInSecondStepStaysUnlocked() { // Given a scene object with a lockable property which is referenced in the transitions of the first and second step // and should normally lock at the end of a step. ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); LockablePropertyMock property = o1.GameObject.AddComponent <LockablePropertyMock>(); LockableReferencingConditionMock lockAtEndOfStepCondition = new LockableReferencingConditionMock(); lockAtEndOfStepCondition.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName); lockAtEndOfStepCondition.LockableProperties = new[] { new LockablePropertyData(property, true) }; Step step2 = new BasicStepBuilder("step2").AddCondition(lockAtEndOfStepCondition).Build(); Step step = new BasicStepBuilder("step").AddCondition(lockAtEndOfStepCondition).Build(); step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2; // When executing the locking routine in the first step. LockHandling.Unlock(step.Data, new List <LockablePropertyData>()); step.Data.Transitions.Data.Transitions.First().Autocomplete(); step.Data.Transitions.Data.Transitions.First().Data.IsCompleted = true; LockHandling.Lock(step.Data, new List <LockablePropertyData>()); // Then the property is not locked at the end of the first step because it is needed in the second step. Assert.IsFalse(property.IsLocked); yield return(null); }
public IEnumerator DependencyGetsLocked() { // Given a scene object with one lockable property with dependency. ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); LockablePropertyMock dependency = o1.GameObject.AddComponent <LockablePropertyMock>(); LockablePropertyMockWithDependency propertyWithDependency = o1.GameObject.AddComponent <LockablePropertyMockWithDependency>(); Step step2 = new BasicStepBuilder("step").Build(); Step step = new BasicStepBuilder("step").AddCondition(new EndlessConditionMock()).Build(); step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2; dependency.SetLocked(true); propertyWithDependency.SetLocked(true); // When we manually unlock the property for one step. LockHandling.Unlock(step.Data, new List <LockablePropertyData> { new LockablePropertyData(propertyWithDependency) }); step.Data.Transitions.Data.Transitions.First().Autocomplete(); step.Data.Transitions.Data.Transitions.First().Data.IsCompleted = true; LockHandling.Lock(step.Data, new List <LockablePropertyData> { new LockablePropertyData(propertyWithDependency) }); // Then after the step the dependent property is also locked again. Assert.IsTrue(dependency.IsLocked); yield return(null); }
public IEnumerator DisableGameObjectBehavior() { // Given DisableGameObjectBehavior, TrainingSceneObject trainingSceneObject = TestingUtils.CreateSceneObject("TestObject"); ICourse training1 = new LinearTrainingBuilder("Training") .AddChapter(new LinearChapterBuilder("Chapter") .AddStep(new BasicStepBuilder("Step") .DisableAutomaticAudioHandling() .Disable("TestObject"))) .Build(); // When we serialize and deserialize a training with it string serialized = JsonTrainingSerializer.Serialize(training1); ICourse training2 = JsonTrainingSerializer.Deserialize(serialized); DisableGameObjectBehavior behavior1 = training1.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as DisableGameObjectBehavior; DisableGameObjectBehavior behavior2 = training2.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as DisableGameObjectBehavior; // Then it's target training scene object is still the same. Assert.IsNotNull(behavior1); Assert.IsNotNull(behavior2); Assert.AreEqual(behavior1.Data.Target.Value, behavior2.Data.Target.Value); TestingUtils.DestroySceneObject(trainingSceneObject); return(null); }
public IEnumerator KeepUnlockedAtEndPropertyIsUnlockedAfterFinishingStep() { // Given a transition with a condition referencing a scene object with a lockable property // that should not be locked in the end of a step. ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); LockablePropertyMock property = o1.GameObject.AddComponent <LockablePropertyMock>(); LockableReferencingConditionMock doNotLockAtEndOfStepCondition = new LockableReferencingConditionMock(); doNotLockAtEndOfStepCondition.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName); doNotLockAtEndOfStepCondition.LockableProperties = new[] { new LockablePropertyData(property, false) }; Step step2 = new BasicStepBuilder("step2").Build(); Step step = new BasicStepBuilder("step").AddCondition(doNotLockAtEndOfStepCondition).Build(); step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2; // When executing the locking routine and completing the step. LockHandling.Unlock(step.Data, new List <LockablePropertyData>()); step.Data.Transitions.Data.Transitions.First().Autocomplete(); step.Data.Transitions.Data.Transitions.First().Data.IsCompleted = true; LockHandling.Lock(step.Data, new List <LockablePropertyData>()); // Then the property is not locked in the end. Assert.IsFalse(property.IsLocked); yield return(null); }
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 GetLockablePropertiesMultipleObjectsAndConditions() { // Given three scene objects, // one of them with one lockable property and one non-lockable property, // one of them with only one non-lockable property, // and one of them with only one lockable property, // used by three different conditions in a transition. ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); LockablePropertyMock property = o1.GameObject.AddComponent <LockablePropertyMock>(); o1.GameObject.AddComponent <PropertyMock>(); ISceneObject o2 = TestingUtils.CreateSceneObject("o2"); o2.GameObject.AddComponent <PropertyMock>(); ISceneObject o3 = TestingUtils.CreateSceneObject("o3"); LockablePropertyMock property2 = o2.GameObject.AddComponent <LockablePropertyMock>(); LockableReferencingConditionMock condition1 = new LockableReferencingConditionMock(); condition1.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName); condition1.LockableProperties = new[] { new LockablePropertyData(property, true) }; ReferencingConditionMock condition2 = new ReferencingConditionMock(); condition2.Data.PropertyMock = new ScenePropertyReference <PropertyMock>(o2.UniqueName); LockableReferencingConditionMock condition3 = new LockableReferencingConditionMock(); condition3.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o3.UniqueName); condition3.LockableProperties = new[] { new LockablePropertyData(property2, true) }; Step step2 = new BasicStepBuilder("step2").Build(); Step step = new BasicStepBuilder("step") .AddCondition(condition1) .AddCondition(condition2) .AddCondition(condition3) .Build(); Transition transition = (Transition)step.Data.Transitions.Data.Transitions[0]; transition.Data.TargetStep = step2; // When counting the lockable properties in the transition. // Then there are exactly two lockable properties. Assert.IsTrue(transition.GetLockableProperties().Count() == 2); yield return(null); }
public IEnumerator ObjectInConditionIsNotInManualUnlockList() { // Given a step with a condition with a LockableProperty ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); LockableProperty lockableProperty = o1.GameObject.AddComponent <LockablePropertyMock>(); LockableReferencingConditionMock lockCondition = new LockableReferencingConditionMock(); lockCondition.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName); Step step = new BasicStepBuilder("step").AddCondition(lockCondition).Build(); // When we create a collection referencing this step LockableObjectsCollection collection = new LockableObjectsCollection(step.Data); // Then the lockable property is not in the Manual Unlock List of the collection Assert.IsFalse(collection.IsInManualUnlockList(lockableProperty)); yield return(null); }
public IEnumerator FastForwardInactiveBehavior() { // Given an active training scene object and a DisableGameObjectBehavior, TrainingSceneObject toDisable = TestingUtils.CreateSceneObject("ToDisable"); DisableGameObjectBehavior behavior = new DisableGameObjectBehavior(toDisable); // When we mark it to fast-forward, behavior.LifeCycle.MarkToFastForward(); // Then it doesn't autocomplete because it weren't activated yet. Assert.AreEqual(Stage.Inactive, behavior.LifeCycle.Stage); // Cleanup. TestingUtils.DestroySceneObject(toDisable); yield break; }
public IEnumerator ManuallyAddedSceneObjectIsNotInAutoUnlockList() { // Given a step with a condition with a LockableProperty and a collection referencing this step Step step = new BasicStepBuilder("step").Build(); LockableObjectsCollection collection = new LockableObjectsCollection(step.Data); // When we create a SceneObject with a lockable property ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); LockableProperty lockableProperty = o1.GameObject.AddComponent <LockablePropertyMock>(); // ...and add the SceneObject and its property to the collection collection.AddSceneObject(o1); collection.Add(lockableProperty); // Then the lockable property is not in the Auto Unlock List of the collection Assert.IsFalse(collection.IsInAutoUnlockList(lockableProperty)); yield return(null); }
public IEnumerator FastForwardInactiveBehaviorAndActivateIt() { // Given an active training scene object and a DisableGameObjectBehavior, TrainingSceneObject toDisable = TestingUtils.CreateSceneObject("ToDisable"); DisableGameObjectBehavior behavior = new DisableGameObjectBehavior(toDisable); // When we mark it to fast-forward and activate it, behavior.LifeCycle.MarkToFastForward(); behavior.LifeCycle.Activate(); // Then it should work without any differences because the behavior is done immediately anyways. Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage); Assert.IsFalse(toDisable.GameObject.activeSelf); // Cleanup. TestingUtils.DestroySceneObject(toDisable); yield break; }
public IEnumerator RemovedPropertyIsNotInManualUnlockList() { // Given a step with a condition with a LockableProperty Step step = new BasicStepBuilder("step").Build(); // ...and a collection with a manually added SceneObject and an added lockable property LockableObjectsCollection collection = new LockableObjectsCollection(step.Data); ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); LockableProperty lockableProperty = o1.GameObject.AddComponent <LockablePropertyMock>(); collection.AddSceneObject(o1); collection.Add(lockableProperty); // When we remove the property from the collection collection.Remove(lockableProperty); // Then the lockable property is not in the Auto Unlock List of the collection Assert.IsFalse(collection.IsInAutoUnlockList(lockableProperty)); yield return(null); }
public IEnumerator SecondTransitionIsLocked() { // Given a step with two different transitions, // each of them having an own condition with a lockable property which should not be locked at the end of a step. ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); LockablePropertyMock property = o1.GameObject.AddComponent <LockablePropertyMock>(); ISceneObject o2 = TestingUtils.CreateSceneObject("o2"); LockablePropertyMock property2 = o2.GameObject.AddComponent <LockablePropertyMock>(); LockableReferencingConditionMock doNotLockAtEndOfStepCondition1 = new LockableReferencingConditionMock(); doNotLockAtEndOfStepCondition1.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName); doNotLockAtEndOfStepCondition1.LockableProperties = new[] { new LockablePropertyData(property, false) }; LockableReferencingConditionMock doNotLockAtEndOfStepCondition2 = new LockableReferencingConditionMock(); doNotLockAtEndOfStepCondition2.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o2.UniqueName); doNotLockAtEndOfStepCondition2.LockableProperties = new[] { new LockablePropertyData(property2, false) }; Step step2 = new BasicStepBuilder("step2").AddCondition(doNotLockAtEndOfStepCondition1).Build(); Step step = new BasicStepBuilder("step").AddCondition(doNotLockAtEndOfStepCondition1).Build(); step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2; step.Data.Transitions.Data.Transitions.Add(new Transition()); step.Data.Transitions.Data.Transitions[1].Data.Conditions.Add(doNotLockAtEndOfStepCondition2); // When completing only the first transition. LockHandling.Unlock(step.Data, new List <LockablePropertyData>()); step.Data.Transitions.Data.Transitions.First().Autocomplete(); step.Data.Transitions.Data.Transitions.First().Data.IsCompleted = true; LockHandling.Lock(step.Data, new List <LockablePropertyData>()); // Then the lockable property of the second transition is locked, // even though lock at the end of step is set to false. Assert.IsTrue(property2.IsLocked); yield return(null); }
public IEnumerator SecondPropertyGetsLockedAfterNotBeingNeededAnymore() { // Given two steps and two scene objects with each one lockable property // and property 2 (lock at the end of step = true) is referenced only in the first step, // whereas property 1 (lock at the end of step = false) is referenced in both steps. ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); LockablePropertyMock DoNotLockAtEndOfStep = o1.GameObject.AddComponent <LockablePropertyMock>(); ISceneObject o2 = TestingUtils.CreateSceneObject("o2"); LockablePropertyMock lockAtEndOfStep = o2.GameObject.AddComponent <LockablePropertyMock>(); LockableReferencingConditionMock doNotLockAtEndOfStepCondition = new LockableReferencingConditionMock(); doNotLockAtEndOfStepCondition.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o1.UniqueName); doNotLockAtEndOfStepCondition.LockableProperties = new[] { new LockablePropertyData(DoNotLockAtEndOfStep, false) }; LockableReferencingConditionMock lockAtEndOfStepCondition = new LockableReferencingConditionMock(); lockAtEndOfStepCondition.Data.LockablePropertyMock = new ScenePropertyReference <ILockablePropertyMock>(o2.UniqueName); lockAtEndOfStepCondition.LockableProperties = new[] { new LockablePropertyData(lockAtEndOfStep, true) }; Step step2 = new BasicStepBuilder("step2").AddCondition(doNotLockAtEndOfStepCondition).Build(); Step step = new BasicStepBuilder("step") .AddCondition(doNotLockAtEndOfStepCondition) .AddCondition(lockAtEndOfStepCondition) .Build(); step.Data.Transitions.Data.Transitions[0].Data.TargetStep = step2; // When executing the locking routine in the first step. LockHandling.Unlock(step.Data, new List <LockablePropertyData>()); step.Data.Transitions.Data.Transitions.First().Autocomplete(); step.Data.Transitions.Data.Transitions.First().Data.IsCompleted = true; LockHandling.Lock(step.Data, new List <LockablePropertyData>()); // Then property 2 is locked in the end of the first step. Assert.IsTrue(lockAtEndOfStep.IsLocked); yield return(null); }
public IEnumerator GetLockablePropertiesZeroLockables() { // Given a scene object with one non-lockable property used by a condition in a transition. ISceneObject o1 = TestingUtils.CreateSceneObject("o1"); o1.GameObject.AddComponent <PropertyMock>(); ReferencingConditionMock condition = new ReferencingConditionMock(); condition.Data.PropertyMock = new ScenePropertyReference <PropertyMock>(o1.UniqueName); Step step2 = new BasicStepBuilder("step2").Build(); Step step = new BasicStepBuilder("step").AddCondition(condition).Build(); Transition transition = (Transition)step.Data.Transitions.Data.Transitions[0]; transition.Data.TargetStep = step2; // When counting the lockable properties in the transition. // Then there is no lockable property. Assert.IsFalse(transition.GetLockableProperties().Any()); yield return(null); }
public IEnumerator GameObjectStaysEnabled() { // Given an active training scene object and a training with enalbe game object condition, TrainingSceneObject toEnable = TestingUtils.CreateSceneObject("toEnable"); toEnable.GameObject.SetActive(false); EndlessCondition trigger = new EndlessCondition(); ICourse course = new LinearTrainingBuilder("Training") .AddChapter(new LinearChapterBuilder("Chapter") .AddStep(new BasicStepBuilder("Step") .DisableAutomaticAudioHandling() .Enable(toEnable)) .AddStep(new BasicStepBuilder("Step") .DisableAutomaticAudioHandling() .AddCondition(trigger))) .Build(); course.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When the behavior is activated and after the step is completed TrainingRunner.Initialize(course); TrainingRunner.Run(); yield return(new WaitUntil(() => course.Data.FirstChapter.Data.Steps[0].LifeCycle.Stage == Stage.Active)); trigger.Autocomplete(); yield return(new WaitUntil(() => course.Data.FirstChapter.Data.Steps[0].LifeCycle.Stage == Stage.Inactive)); // Then the training scene object stays enabled. Assert.True(toEnable.GameObject.activeSelf); // Cleanup TestingUtils.DestroySceneObject(toEnable); }