コード例 #1
0
        public IEnumerator ChangeNameBeforeAwakeTest()
        {
            // Create reference
            GameObject obj = new GameObject("MyObject");

            obj.SetActive(false);
            TrainingSceneObject reference = obj.AddComponent <TrainingSceneObject>();

            reference.ChangeUniqueName("Test");

            reference.ChangeUniqueName("Test2");
            obj.SetActive(true);

            // Assert that reference is now registered at the registry.
            Assert.IsTrue(RuntimeConfigurator.Configuration.SceneObjectRegistry.ContainsGuid(reference.Guid));
            Assert.AreEqual(reference, RuntimeConfigurator.Configuration.SceneObjectRegistry.GetByGuid(reference.Guid));
            Assert.IsFalse(RuntimeConfigurator.Configuration.SceneObjectRegistry.ContainsName("Test"));
            Assert.IsTrue(RuntimeConfigurator.Configuration.SceneObjectRegistry.ContainsName("Test2"));
            Assert.AreEqual(reference, RuntimeConfigurator.Configuration.SceneObjectRegistry.GetByName("Test2"));

            // Clean up
            Object.DestroyImmediate(obj);

            yield return(null);
        }
コード例 #2
0
        public IEnumerator FastForwardInactiveBehavior()
        {
            // Given a complete scaling behavior with a positive duration,
            const float duration = 0.05f;

            GameObject          target           = new GameObject(targetName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(targetName);

            Vector3 endScale = target.transform.localScale + newScale;

            IBehavior behavior = new ScalingBehavior(new SceneObjectReference(targetName), endScale, duration);

            behavior.Configure(defaultMode);

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

            // Then it doesn't autocomplete because it hasn't been activated yet.
            Assert.AreEqual(Stage.Inactive, behavior.LifeCycle.Stage);
            Assert.IsFalse(target.transform.localScale == endScale);

            yield break;
        }
コード例 #3
0
        public IEnumerator BuildingTouchTest()
        {
            // Given you have a touchable property and a builder for a training with Touch default step
            GameObject          touchableGo = new GameObject("Touchable");
            TrainingSceneObject touchable   = touchableGo.AddComponent <TrainingSceneObject>();

            touchableGo.AddComponent <DummyTouchableProperty>();
            touchable.ChangeUniqueName("Touchable");

            LinearTrainingBuilder builder = new LinearTrainingBuilder("TestTraining")
                                            .AddChapter(new LinearChapterBuilder("TestChapter")
                                                        .AddStep(InteractionDefaultSteps.Touch("TestTouchStep", "Touchable")));

            // When you build a training with it
            IStep step = builder.Build().Data.FirstChapter.Data.FirstStep;

            // Then it has a step with a TouchCOndition
            Assert.True(step != null);
            Assert.True(step.Data.Name == "TestTouchStep");
            Assert.True(step.Data.Transitions.Data.Transitions.First().Data.Conditions.Count == 1);
            Assert.True(step.Data.Transitions.Data.Transitions.First().Data.Conditions.First() is TouchedCondition);
            Assert.True(ReferenceEquals((step.Data.Transitions.Data.Transitions.First().Data.Conditions.First() as TouchedCondition).Data.TouchableProperty.Value.SceneObject, touchable));

            // Cleanup
            Object.DestroyImmediate(touchableGo);

            return(null);
        }
コード例 #4
0
        public IEnumerator BuildingSnapZonePutTest()
        {
            // Given a snap zone and snappable property and a builder for a training with a PutIntoSnapZone default step
            GameObject          snapZoneGo = new GameObject("SnapZone");
            TrainingSceneObject snapZone   = snapZoneGo.AddComponent <TrainingSceneObject>();

            snapZoneGo.AddComponent <DummySnapZoneProperty>();
            snapZone.ChangeUniqueName("SnapZone");

            GameObject          putGo       = new GameObject("Puttable");
            TrainingSceneObject objectToPut = putGo.AddComponent <TrainingSceneObject>();

            putGo.AddComponent <DummySnappableProperty>();
            objectToPut.ChangeUniqueName("ToPut");

            LinearTrainingBuilder builder = new LinearTrainingBuilder("TestTraining")
                                            .AddChapter(new LinearChapterBuilder("TestChapter")
                                                        .AddStep(InteractionDefaultSteps.PutIntoSnapZone("TestSnapZonePutStep", "SnapZone", "ToPut")));

            // When you build a training with it
            IStep step = builder.Build().Data.FirstChapter.Data.FirstStep;

            // Then it has a step with a SnappedCondition
            Assert.True(step != null);
            Assert.True(step.Data.Name == "TestSnapZonePutStep");
            Assert.True(step.Data.Transitions.Data.Transitions.First().Data.Conditions.Count == 1);
            Assert.True(step.Data.Transitions.Data.Transitions.First().Data.Conditions.First() is SnappedCondition);
            Assert.True(ReferenceEquals((step.Data.Transitions.Data.Transitions.First().Data.Conditions.First() as SnappedCondition).Data.Target.Value.SceneObject, objectToPut));

            // Cleanup
            Object.DestroyImmediate(snapZoneGo);
            Object.DestroyImmediate(putGo);

            return(null);
        }
コード例 #5
0
        public IEnumerator FastForwardActivatingBehavior()
        {
            // Given an active ConfettiBehavior with activation mode "Activation",
            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToPrefab, areaRadius, duration, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

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

            // Then it autocompletes immediately.
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
        }
        public IEnumerator CreateByName()
        {
            // Given two training scene objects and a duration,
            GameObject          movedGo = new GameObject(movedName);
            TrainingSceneObject moved   = movedGo.AddComponent <TrainingSceneObject>();

            moved.ChangeUniqueName(movedName);

            GameObject          targetGo         = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = targetGo.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            float duration = 0.25f;

            // When we create MoveObjectBehavior and pass training scene objects by their unique name,
            MoveObjectBehavior moveObjectBehavior = new MoveObjectBehavior(movedName, positionProviderName, duration);

            // Then all properties of the MoveObjectBehavior are properly assigned
            Assert.AreEqual(moved, moveObjectBehavior.Data.Target.Value);
            Assert.AreEqual(positionProvider, moveObjectBehavior.Data.PositionProvider.Value);
            Assert.AreEqual(moveObjectBehavior.Data.Duration, duration);

            // Cleanup created game objects.
            Object.DestroyImmediate(movedGo);
            Object.DestroyImmediate(targetGo);

            yield return(null);
        }
コード例 #7
0
        public IEnumerator StillActivatingWhenPositiveDurationNotFinished()
        {
            // Given the position provider training object, some valid default settings, and the activation mode = Activation,
            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToPrefab, areaRadius, 2f, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            // When I activate that behavior,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            // And wait two update cycles,
            yield return(null);

            behavior.Update();

            yield return(null);

            behavior.Update();

            // Then the activation state of the behavior is "activating".
            Assert.AreEqual(Stage.Activating, behavior.LifeCycle.Stage);
        }
コード例 #8
0
        public IEnumerator ActivationWithSpawnedMachine()
        {
            // Given a positive duration, a position provider, some valid default settings, and the activation mode = Activation,
            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToPrefab, areaRadius, duration, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            // When I activate that behavior and wait until it's activating,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            string     prefabName = "Behavior" + pathToPrefab.Substring(pathToPrefab.LastIndexOf("/", StringComparison.Ordinal) + 1);
            GameObject machine    = GameObject.Find(prefabName);

            // Then the activation state of the behavior is "activating" and the ConfettiMachine exists in the scene.
            Assert.AreEqual(Stage.Activating, behavior.LifeCycle.Stage);
            Assert.IsTrue(machine != null);
        }
コード例 #9
0
        public IEnumerator UnregisterAllowsToPlaceTest()
        {
            // Create reference
            GameObject          obj1       = new GameObject("MyObject");
            TrainingSceneObject reference1 = obj1.AddComponent <TrainingSceneObject>();

            reference1.ChangeUniqueName("Test");

            RuntimeConfigurator.Configuration.SceneObjectRegistry.Unregister(reference1);

            // Create reference
            GameObject          obj2       = new GameObject("MyObject");
            TrainingSceneObject reference2 = obj2.AddComponent <TrainingSceneObject>();

            reference2.ChangeUniqueName("Test");

            // Assert that new added reference can be found
            Assert.IsTrue(RuntimeConfigurator.Configuration.SceneObjectRegistry.ContainsGuid(reference2.Guid));
            Assert.IsTrue(RuntimeConfigurator.Configuration.SceneObjectRegistry.ContainsName(reference2.UniqueName));
            Assert.AreEqual(reference2, RuntimeConfigurator.Configuration.SceneObjectRegistry.GetByName(reference2.UniqueName));

            // Clean up
            Object.DestroyImmediate(obj1);
            Object.DestroyImmediate(obj2);

            yield return(null);
        }
コード例 #10
0
ファイル: TrainingBuilderTests.cs プロジェクト: vued/Creator
        public IEnumerator BuildingUseTest()
        {
            // Given a usable property and a builder for a training with Use default step
            GameObject          usableGo = new GameObject("Usable");
            TrainingSceneObject usable   = usableGo.AddComponent <TrainingSceneObject>();

            usableGo.AddComponent <UsableProperty>();
            usable.ChangeUniqueName("Usable");

            LinearTrainingBuilder builder = new LinearTrainingBuilder("TestTraining")
                                            .AddChapter(new LinearChapterBuilder("TestChapter")
                                                        .AddStep(DefaultSteps.Use("TestUseStep", "Usable")));

            // When you build a training with it
            IStep step = builder.Build().Data.FirstChapter.Data.FirstStep;

            // Then it has a step with an UsedCondition
            Assert.True(step != null);
            Assert.True(step.Data.Name == "TestUseStep");
            Assert.True(step.Data.Transitions.Data.Transitions.First().Data.Conditions.Count == 1);
            Assert.True(step.Data.Transitions.Data.Transitions.First().Data.Conditions.First() is UsedCondition);
            Assert.True(ReferenceEquals((step.Data.Transitions.Data.Transitions.First().Data.Conditions.First() as UsedCondition).Data.UsableProperty.Value.SceneObject, usable));

            // Cleanup
            Object.DestroyImmediate(usableGo);

            return(null);
        }
コード例 #11
0
ファイル: TrainingBuilderTests.cs プロジェクト: vued/Creator
        public IEnumerator HighlightTest()
        {
            // Given we have a training scene object and a builder for a training with a step with highlight that object
            GameObject          go            = new GameObject("Highlightable");
            TrainingSceneObject highlightable = go.AddComponent <TrainingSceneObject>();

            highlightable.ChangeUniqueName("Highlightable");

            LinearTrainingBuilder builder = new LinearTrainingBuilder("TestTraining")
                                            .AddChapter(new LinearChapterBuilder("TestChapter")
                                                        .AddStep(new BasicStepBuilder("TestHighlightStep")
                                                                 .Highlight("Highlightable")));

            // When we build a training from it
            IStep step = builder.Build().Data.FirstChapter.Data.FirstStep;

            // Then we have a step with VRTKObjectHighlight behavior.
            Assert.True(step != null);
            Assert.True(step.Data.Name == "TestHighlightStep");
            Assert.True(step.Data.Behaviors.Data.Behaviors.First() is VRTKObjectHighlight);
            Assert.True(ReferenceEquals((step.Data.Behaviors.Data.Behaviors.First() as VRTKObjectHighlight).Data.Target.Value, highlightable));

            // Cleanup
            Object.DestroyImmediate(go);

            return(null);
        }
コード例 #12
0
ファイル: TrainingBuilderTests.cs プロジェクト: vued/Creator
        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);
        }
コード例 #13
0
        public IEnumerator RunsInstantlyWhenDelayTimeIsZero()
        {
            // Given a complete scaling behavior with duration time == 0,
            const float duration = 0f;

            GameObject          target           = new GameObject(targetName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(targetName);

            Vector3 endScale = target.transform.localScale + newScale;

            IBehavior behavior = new ScalingBehavior(new SceneObjectReference(targetName), endScale, duration);

            behavior.Configure(defaultMode);

            // When we activate it and wait one update cycle,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            yield return(null);

            behavior.Update();

            // Then the behavior is activated immediately and the object is scaled correctly.
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
            Assert.IsTrue(target.transform.localScale == endScale);
        }
コード例 #14
0
        public IEnumerator FastForwardActivatingBehavior()
        {
            // Given an active and complete scaling behavior with a positive duration,
            const float duration = 0.05f;

            GameObject          target           = new GameObject(targetName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(targetName);

            Vector3 endScale = target.transform.localScale + newScale;

            IBehavior behavior = new ScalingBehavior(new SceneObjectReference(targetName), endScale, duration);

            behavior.Configure(defaultMode);

            behavior.LifeCycle.Activate();

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

            // Then the behavior is activated immediately and the object is scaled correctly.
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
            Assert.IsTrue(target.transform.localScale == endScale);

            yield break;
        }
        public IEnumerator FastForwardInactiveBehavior()
        {
            // Given MoveObjectBehavior that takes two training scene objects with different positions and rotations, and positive transition duration,
            float duration = 0.05f;

            GameObject          movedGo = new GameObject(movedName);
            TrainingSceneObject moved   = movedGo.AddComponent <TrainingSceneObject>();

            moved.ChangeUniqueName(movedName);

            GameObject positionProviderGo = new GameObject(positionProviderName);

            positionProviderGo.transform.position = new Vector3(1, 2, 50);
            positionProviderGo.transform.rotation = Quaternion.Euler(57, 195, 188);
            TrainingSceneObject target = positionProviderGo.AddComponent <TrainingSceneObject>();

            target.ChangeUniqueName(positionProviderName);

            MoveObjectBehavior behavior = new MoveObjectBehavior(moved, target, duration);

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

            // Then it doesn't autocomplete because it wasn't activated yet.
            Assert.AreEqual(Stage.Inactive, behavior.LifeCycle.Stage);

            // Cleanup created game objects.
            Object.DestroyImmediate(movedGo);
            Object.DestroyImmediate(positionProviderGo);

            yield return(null);
        }
コード例 #16
0
        public IEnumerator CreateByName()
        {
            // Given the path to the confetti machine prefab, the position provider name, the duration, the bool isAboveTrainee, the area radius, and the activation mode,
            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            BehaviorExecutionStages executionStages = BehaviorExecutionStages.ActivationAndDeactivation;

            // When we create ConfettiBehavior and pass training objects by their unique name,
            ConfettiBehavior confettiBehavior = new ConfettiBehavior(false, positionProviderName, pathToMockPrefab, areaRadius, duration, executionStages);

            confettiBehavior.Configure(defaultMode);

            // Then all properties of the MoveObjectBehavior are properly assigned.
            Assert.AreEqual(false, confettiBehavior.Data.IsAboveTrainee);
            Assert.AreEqual(positionProvider, confettiBehavior.Data.PositionProvider.Value);
            Assert.AreEqual(pathToMockPrefab, confettiBehavior.Data.ConfettiMachinePrefabPath);
            Assert.AreEqual(areaRadius, confettiBehavior.Data.AreaRadius);
            Assert.AreEqual(duration, confettiBehavior.Data.Duration);
            Assert.AreEqual(executionStages, confettiBehavior.Data.ExecutionStages);

            yield break;
        }
        public IEnumerator FastForwardInactiveBehaviorAndActivateIt()
        {
            // Given MoveObjectBehavior that takes two training scene objects with different positions and rotations, and positive transition duration,
            float duration = 0.05f;

            GameObject          movedGo = new GameObject(movedName);
            TrainingSceneObject moved   = movedGo.AddComponent <TrainingSceneObject>();

            moved.ChangeUniqueName(movedName);

            GameObject positionProviderGo = new GameObject(positionProviderName);

            positionProviderGo.transform.position = new Vector3(1, 2, 50);
            positionProviderGo.transform.rotation = Quaternion.Euler(57, 195, 188);
            TrainingSceneObject target = positionProviderGo.AddComponent <TrainingSceneObject>();

            target.ChangeUniqueName(positionProviderName);

            MoveObjectBehavior behavior = new MoveObjectBehavior(moved, target, duration);

            // When we mark it to fast-forward and activate it,
            behavior.LifeCycle.MarkToFastForward();
            behavior.LifeCycle.Activate();

            // Then it autocompletes immediately, and moved object position and rotation matches the ones of positionProvider.
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
            Assert.IsTrue((movedGo.transform.position - positionProviderGo.transform.position).sqrMagnitude < 0.001f);
            Assert.IsTrue(Quaternion.Dot(movedGo.transform.rotation, positionProviderGo.transform.rotation) > 0.999f);

            // Cleanup created game objects.
            Object.DestroyImmediate(movedGo);
            Object.DestroyImmediate(positionProviderGo);

            yield return(null);
        }
コード例 #18
0
        public IEnumerator NotExistingPrefab()
        {
            // Given the position provider training object, an invalid path to a not existing prefab, some valid default settings, and the activation mode = Activation,
            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToMockPrefab, areaRadius, duration, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            // When I activate that behavior and wait for one update cycle,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            yield return(null);

            behavior.Update();

            string     prefabName = "Behavior" + pathToMockPrefab.Substring(pathToMockPrefab.LastIndexOf("/", StringComparison.Ordinal) + 1);
            GameObject machine    = GameObject.Find(prefabName);

            // Then the activation state of the behavior is "active" and there is no confetti machine in the scene.
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
            Assert.AreEqual(null, machine);
        }
        public IEnumerator SamePosition()
        {
            // Given MoveObjectBehavior that takes two training scene objects with the same position and rotation, and positive transition duration,
            float duration = 0.05f;

            GameObject          movedGo = new GameObject(movedName);
            TrainingSceneObject moved   = movedGo.AddComponent <TrainingSceneObject>();

            moved.ChangeUniqueName(movedName);

            GameObject          targetGo = new GameObject(positionProviderName);
            TrainingSceneObject target   = targetGo.AddComponent <TrainingSceneObject>();

            target.ChangeUniqueName(positionProviderName);

            MoveObjectBehavior behavior = new MoveObjectBehavior(moved, target, duration);

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

            // When we activate the behavior,
            behavior.LifeCycle.Activate();

            yield return(null);

            behavior.Update();

            // Then it does not finish its activation immediately.
            Assert.IsTrue(behavior.LifeCycle.Stage == Stage.Activating);

            // Cleanup created game objects.
            Object.DestroyImmediate(movedGo);
            Object.DestroyImmediate(targetGo);

            yield return(null);
        }
コード例 #20
0
        public IEnumerator UnregisterOnDestroyTest()
        {
            // Create reference
            GameObject          obj       = new GameObject("MyObject");
            TrainingSceneObject reference = obj.AddComponent <TrainingSceneObject>();

            reference.ChangeUniqueName("Test");

            Object.DestroyImmediate(obj);

            // Assert that exception is thrown
            Assert.IsFalse(RuntimeConfigurator.Configuration.SceneObjectRegistry.ContainsName("Test"));

            yield return(null);
        }
        public IEnumerator PositiveDuration()
        {
            // Given MoveObjectBehavior that takes two training scene objects with different positions and rotations, and positive transition duration,
            float duration = 0.05f;

            GameObject          movedGo = new GameObject(movedName);
            TrainingSceneObject moved   = movedGo.AddComponent <TrainingSceneObject>();

            moved.ChangeUniqueName(movedName);

            GameObject positionProviderGo = new GameObject(positionProviderName);

            positionProviderGo.transform.position = new Vector3(1, 2, 50);
            positionProviderGo.transform.rotation = Quaternion.Euler(57, 195, 188);
            TrainingSceneObject target = positionProviderGo.AddComponent <TrainingSceneObject>();

            target.ChangeUniqueName(positionProviderName);

            MoveObjectBehavior behavior = new MoveObjectBehavior(moved, target, duration);

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

            // When I activate that behavior and wait for transition duration,
            behavior.LifeCycle.Activate();

            float startTime = Time.time;

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

                behavior.Update();
            }

            // Then behavior activation is completed, and moved object position and rotation matches positionProvider's.
            Assert.IsTrue(Time.time - startTime > duration);
            Assert.IsTrue((movedGo.transform.position - positionProviderGo.transform.position).sqrMagnitude < 0.001f);
            Assert.IsTrue(Quaternion.Dot(movedGo.transform.rotation, positionProviderGo.transform.rotation) > 0.999f);

            // Cleanup created game objects.
            Object.DestroyImmediate(movedGo);
            Object.DestroyImmediate(positionProviderGo);

            yield return(null);
        }
コード例 #22
0
        public IEnumerator DoneAfterTime()
        {
            // Given a complete scaling behavior with a positive duration,
            const float duration = 0.05f;

            GameObject          target           = new GameObject(targetName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(targetName);

            Vector3 endScale = target.transform.localScale + newScale;

            IBehavior behavior = new ScalingBehavior(new SceneObjectReference(targetName), endScale, duration);

            behavior.Configure(defaultMode);

            // When we activate the behavior and wait for it's delay time,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            yield return(null);

            behavior.Update();

            float startTime = Time.time;

            while (Time.time < startTime + duration)
            {
                Assert.AreEqual(Stage.Activating, behavior.LifeCycle.Stage);
                Assert.IsFalse(target.transform.localScale == endScale);
                yield return(null);

                behavior.Update();
            }

            // Then the behavior should be active and the object is scaled correctly.
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
            Assert.IsTrue(target.transform.localScale == endScale);
        }
コード例 #23
0
ファイル: LockBehaviorTests.cs プロジェクト: vued/Creator
        public IEnumerator CreateLockBehavior()
        {
            // Given an game object with a changed unique name,
            GameObject          gameObject   = new GameObject("Test");
            TrainingSceneObject targetObject = gameObject.AddComponent <TrainingSceneObject>();

            targetObject.ChangeUniqueName(targetName);

            // When we reference it by reference or unique name in the LockObjectBehavior,
            LockObjectBehavior lock1 = new LockObjectBehavior(targetObject);
            LockObjectBehavior lock2 = new LockObjectBehavior(targetName);

            // Then it is the same object.
            Assert.AreEqual(targetObject, lock1.Data.Target.Value);
            Assert.AreEqual(targetObject, lock2.Data.Target.Value);

            yield break;
        }
コード例 #24
0
        public IEnumerator CanBeFoundByUniqueNameTest()
        {
            // Create reference
            GameObject          obj       = new GameObject("MyObject");
            TrainingSceneObject reference = obj.AddComponent <TrainingSceneObject>();

            reference.ChangeUniqueName("Test");

            // Await end of frame
            yield return(new WaitForFixedUpdate());

            // Assert that reference is now registered at the registry.
            Assert.IsTrue(RuntimeConfigurator.Configuration.SceneObjectRegistry.ContainsName(reference.UniqueName));
            Assert.AreEqual(reference, RuntimeConfigurator.Configuration.SceneObjectRegistry.GetByName(reference.UniqueName));

            // Clean up
            Object.DestroyImmediate(obj);
        }
コード例 #25
0
        public IEnumerator ZeroDuration()
        {
            // Given a duration equals zero, a position provider, some valid default settings, and the activation mode = Activation,
            float newDuration = 0f;

            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToPrefab, areaRadius, newDuration, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            // When I activate that behavior,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            // Wait one update cycle,
            yield return(null);

            behavior.Update();

            // And wait one end cycle,
            yield return(null);

            behavior.Update();

            // Then behavior activation is immediately completed, and the confetti machine should be in the scene.
            string     prefabName = "Behavior" + pathToPrefab.Substring(pathToPrefab.LastIndexOf("/", StringComparison.Ordinal) + 1);
            GameObject machine    = GameObject.Find(prefabName);

            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
            Assert.IsTrue(machine == null);

            // Cleanup created game objects.
            Object.DestroyImmediate(target);
        }
コード例 #26
0
        public IEnumerator UnregisterRemovesReferenceTest()
        {
            // Create reference
            GameObject          obj       = new GameObject("MyObject");
            TrainingSceneObject reference = obj.AddComponent <TrainingSceneObject>();

            reference.ChangeUniqueName("Test");

            // Await end of frame
            yield return(new WaitForFixedUpdate());

            RuntimeConfigurator.Configuration.SceneObjectRegistry.Unregister(reference);
            // Assert that you cant find reference by guid or name
            Assert.IsFalse(RuntimeConfigurator.Configuration.SceneObjectRegistry.ContainsGuid(reference.Guid));
            Assert.IsFalse(RuntimeConfigurator.Configuration.SceneObjectRegistry.ContainsName(reference.UniqueName));

            // Clean up
            Object.DestroyImmediate(obj);
        }
コード例 #27
0
        public IEnumerator FastForwardInactiveBehavior()
        {
            // Given a ConfettiBehavior with activation mode "Activation",
            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToPrefab, areaRadius, duration, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

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

            // Then it doesn't autocomplete because it hasn't been activated yet.
            Assert.AreEqual(Stage.Inactive, behavior.LifeCycle.Stage);

            yield break;
        }
コード例 #28
0
        public IEnumerator CreateUnlockBehavior()
        {
            // Given an game object with a changed unique name,
            GameObject          gameObject   = new GameObject("Test");
            TrainingSceneObject targetObject = gameObject.AddComponent <TrainingSceneObject>();

            targetObject.ChangeUniqueName(targetName);

            // When we reference it by reference or unique name in the UnlockObjectBehavior,
            UnlockObjectBehavior unlock1 = new UnlockObjectBehavior(targetObject);
            UnlockObjectBehavior unlock2 = new UnlockObjectBehavior(targetName);

            // Then it is the same object.
            Assert.AreEqual(targetObject, unlock1.Data.Target.Value);
            Assert.AreEqual(targetObject, unlock2.Data.Target.Value);

            // Cleanup created game objects.
            Object.DestroyImmediate(gameObject);
            yield return(null);
        }
コード例 #29
0
        public IEnumerator RemovedMachineAfterPositiveDuration()
        {
            // Given a positive duration, a position provider, some valid default settings, and the activation mode = Activation,
            GameObject          target           = new GameObject(positionProviderName);
            TrainingSceneObject positionProvider = target.AddComponent <TrainingSceneObject>();

            positionProvider.ChangeUniqueName(positionProviderName);

            ConfettiBehavior behavior = new ConfettiBehavior(false, positionProvider, pathToPrefab, areaRadius, duration, BehaviorExecutionStages.Activation);

            behavior.Configure(defaultMode);

            // When I activate that behavior and wait for one update cycle,
            behavior.LifeCycle.Activate();

            while (behavior.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                behavior.Update();
            }

            yield return(null);

            behavior.Update();

            // And wait duration seconds,
            float startTime = Time.time;

            while (Time.time < startTime + duration + 0.1f)
            {
                yield return(null);

                behavior.Update();
            }

            // Then behavior activation is completed, and the confetti machine should be deleted.
            string prefabName = "Behavior" + pathToPrefab.Substring(pathToPrefab.LastIndexOf("/", StringComparison.Ordinal) + 1);

            Assert.IsTrue(GameObject.Find(prefabName) == null);
        }
コード例 #30
0
        public IEnumerator CantBeRegisteredTwiceTest()
        {
            // Create reference
            GameObject          obj       = new GameObject("MyObject");
            TrainingSceneObject reference = obj.AddComponent <TrainingSceneObject>();

            reference.ChangeUniqueName("Test");

            // Assert that exception is thrown
            Assert.Throws(typeof(AlreadyRegisteredException),
                          () =>
            {
                RuntimeConfigurator.Configuration.SceneObjectRegistry.Register(reference);
            },
                          "ReferenceAlreadyRegisteredException was not thrown!");

            // Clean up
            Object.DestroyImmediate(obj);

            yield return(null);
        }