public IEnumerator BuildingGrabTest() { // Given a `GrabbableProperty` and a builder for a training with a Grab default step GameObject go = new GameObject("TestGrabbable"); TrainingSceneObject to = go.AddComponent <TrainingSceneObject>(); go.AddComponent <GrabbableProperty>(); to.ChangeUniqueName("Grabbable"); LinearTrainingBuilder builder = new LinearTrainingBuilder("TestTraining") .AddChapter(new LinearChapterBuilder("TestChapter") .AddStep(DefaultSteps.Grab("TestGrabStep", "Grabbable"))); // When we build a training from it IStep step = builder.Build().Data.FirstChapter.Data.FirstStep; //Then it should has a stap with a GrabbedCondition which refers to the `GrabbableProperty`. Assert.True(step != null); Assert.True(step.Data.Name == "TestGrabStep"); Assert.True(step.Data.Transitions.Data.Transitions.First().Data.Conditions.Count == 1); GrabbedCondition condition = step.Data.Transitions.Data.Transitions.First().Data.Conditions.First() as GrabbedCondition; Assert.True(ReferenceEquals(to, condition.Data.GrabbableProperty.Value.SceneObject)); // Cleanup Object.DestroyImmediate(go); yield return(null); }
public IEnumerator CompleteWhenGrabbedOnActivation() { // Setup object with mocked grabbed property and activate GameObject obj = new GameObject("T1"); obj.AddComponent <TouchedConditionTests.TouchablePropertyMock>(); GrabbablePropertyMock mockedProperty = obj.AddComponent <GrabbablePropertyMock>(); mockedProperty.SetGrabbed(true); yield return(null); GrabbedCondition condition = new GrabbedCondition(mockedProperty); condition.LifeCycle.Activate(); while (condition.IsCompleted == false) { yield return(null); condition.Update(); } // Assert that condition is now completed due IsGrabbed is true Assert.IsTrue(condition.IsCompleted); }
public IEnumerator ConditionNotCompleted() { // Setup object with mocked grabbed property and activate GameObject obj = new GameObject("T1"); obj.AddComponent <TouchedConditionTests.TouchablePropertyMock>(); GrabbablePropertyMock mock = obj.AddComponent <GrabbablePropertyMock>(); GrabbedCondition condition = new GrabbedCondition(mock); condition.LifeCycle.Activate(); yield return(null); // Assert after doing nothing the condition is not completed. Assert.IsFalse(condition.IsCompleted, "Condition should not be complete!"); }
public IEnumerator FastForwardDoesNotCompleteCondition() { // Given a condition, GameObject go = new GameObject("Meme"); go.AddComponent <TouchedConditionTests.TouchablePropertyMock>(); GrabbablePropertyMock mock = go.AddComponent <GrabbablePropertyMock>(); GrabbedCondition condition = new GrabbedCondition(mock); condition.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); bool wasGrabbed = false; bool wasUngrabbed = false; mock.Grabbed += (sender, args) => { wasGrabbed = true; mock.Ungrabbed += (sendery, argsy) => wasUngrabbed = true; }; 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); }
public IEnumerator AutoCompleteActive() { // Given a grabbed condition GameObject go = new GameObject("Meme"); go.AddComponent <TouchedConditionTests.TouchablePropertyMock>(); GrabbablePropertyMock mock = go.AddComponent <GrabbablePropertyMock>(); GrabbedCondition condition = new GrabbedCondition(mock); bool wasGrabbed = false; bool wasUngrabbed = false; mock.Grabbed += (sender, args) => { wasGrabbed = true; mock.Ungrabbed += (sendery, argsy) => wasUngrabbed = true; }; condition.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); condition.Update(); } // When you mark it autocomplete, condition.Autocomplete(); // Then it is completed, and the object was grabbed and immediately released. Assert.AreEqual(Stage.Active, condition.LifeCycle.Stage); Assert.IsTrue(condition.IsCompleted); Assert.IsTrue(wasGrabbed); Assert.IsTrue(wasUngrabbed); yield return(null); }