コード例 #1
0
        public IEnumerator AudioIsPlayedOnDeactivation()
        {
            // Given a PlayAudioBehavior with activation mode "Deactivation",
            ResourceAudio audioData = new ResourceAudio(new LocalizedString("Sounds/test-sound", "Sounds/test-sound"));
            IBehavior     behavior  = new PlayAudioBehavior(audioData, BehaviorExecutionStages.Deactivation, audioSource);

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

            // When we activate and deactivate it,
            behavior.LifeCycle.Activate();

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

                behavior.Update();
            }

            behavior.LifeCycle.Deactivate();

            yield return(null);

            behavior.Update();

            // Then the audio is playing.
            Assert.IsTrue(audioSource.isPlaying);
        }
コード例 #2
0
        public IEnumerator BehaviorWithoutAudioClipIsDeactivatedImmediately()
        {
            // Given a PlayAudioBehavior with empty audio data and mode set to Deactivation
            ResourceAudio audioData = new ResourceAudio(null);
            IBehavior     behavior  = new PlayAudioBehavior(audioData, BehaviorExecutionStages.Deactivation, audioSource);

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


            // When behavior is activated
            behavior.LifeCycle.Activate();

            yield return(null);

            behavior.Update();

            behavior.LifeCycle.Deactivate();

            yield return(null);

            behavior.Update();

            // Then it immediately finishes its activation.
            Assert.AreEqual(Stage.Inactive, behavior.LifeCycle.Stage);
        }
コード例 #3
0
        public IEnumerator ActiveAfterAudioPlayed()
        {
            // Given a PlayAudioBehavior,
            ResourceAudio audioData = new ResourceAudio(new LocalizedString("Sounds/test-sound", "Sounds/test-sound"));
            IBehavior     behavior  = new PlayAudioBehavior(audioData, BehaviorExecutionStages.Activation, audioSource);

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

            // When we activate it and wait for the audio to play back,
            behavior.LifeCycle.Activate();

            float startTime = Time.time;

            while (audioSource.isPlaying)
            {
                Assert.AreEqual(Stage.Activating, behavior.LifeCycle.Stage);
                yield return(null);

                behavior.Update();
            }

            float duration = Time.time - startTime;

            // Then the audio is not playing and the behavior is active.
            Assert.AreEqual(audioData.AudioClip.length, duration, 0.1f);
            Assert.IsFalse(audioSource.isPlaying);
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
        }
コード例 #4
0
        public IEnumerator StillDeactivatingWhenPlayingAudio()
        {
            // Given a PlayAudioBehavior with activation mode "Deactivation",
            ResourceAudio audioData = new ResourceAudio(new LocalizedString("Sounds/test-sound", "Sounds/test-sound"));
            IBehavior     behavior  = new PlayAudioBehavior(audioData, BehaviorExecutionStages.Deactivation, audioSource);

            behavior.Configure(RuntimeConfigurator.Configuration.GetCurrentMode());

            // When we activate and deactivate it,
            behavior.LifeCycle.Activate();

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

                behavior.Update();
            }

            behavior.LifeCycle.Deactivate();

            yield return(null);

            behavior.Update();

            // Then that audio source is playing but behavior is deactivating.
            Assert.IsTrue(audioSource.isPlaying);
            Assert.AreEqual(Stage.Deactivating, behavior.LifeCycle.Stage);

            yield break;
        }
コード例 #5
0
        public IEnumerator AudioIsPlayed()
        {
            // Given a PlayAudioBehavior,
            ResourceAudio audioData = new ResourceAudio(new LocalizedString("Sounds/test-sound", "Sounds/test-sound"));
            IBehavior     behavior  = new PlayAudioBehavior(audioData, BehaviorExecutionStages.Activation, audioSource);

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

            // Then audio is played.
            Assert.IsTrue(audioSource.isPlaying);

            yield break;
        }
コード例 #6
0
        public IEnumerator FastForwardInactiveBehavior()
        {
            // Given a PlayAudioBehavior with activation mode "Activation",
            ResourceAudio audioData = new ResourceAudio(new LocalizedString("Sounds/test-sound", "Sounds/test-sound"));
            IBehavior     behavior  = new PlayAudioBehavior(audioData, BehaviorExecutionStages.Activation, audioSource);

            // 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;
        }
コード例 #7
0
        public IEnumerator FastForwardInactiveBehaviorAndActivateIt()
        {
            // Given a PlayAudioBehavior with activation mode "Activation",
            ResourceAudio audioData = new ResourceAudio(new LocalizedString("Sounds/test-sound", "Sounds/test-sound"));
            IBehavior     behavior  = new PlayAudioBehavior(audioData, BehaviorExecutionStages.Activation, audioSource);

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

            // Then it autocompletes immediately and audio is not playing.
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
            Assert.IsFalse(audioSource.isPlaying);

            yield break;
        }
コード例 #8
0
        public IEnumerator ActivatingWhileAudioPlays()
        {
            // Given a PlayAudioBehavior,
            ResourceAudio audioData = new ResourceAudio(new LocalizedString("Sounds/test-sound", "Sounds/test-sound"));
            IBehavior     behavior  = new PlayAudioBehavior(audioData, BehaviorExecutionStages.Activation, audioSource);

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

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

            yield return(null);

            behavior.Update();

            // Then that audio source is playing but behavior is active.
            Assert.IsTrue(audioSource.isPlaying);
            Assert.AreEqual(Stage.Activating, behavior.LifeCycle.Stage);
        }
コード例 #9
0
        /// <inheritdoc />
        public override IBehavior GetNewItem()
        {
            DelayBehavior delayBehavior = new DelayBehavior(5f);

            delayBehavior.Data.Name = "Wait for";

            PlayAudioBehavior audioBehavior = new PlayAudioBehavior(new TextToSpeechAudio(new LocalizedString()), BehaviorExecutionStages.Activation);

            audioBehavior.Data.Name = "Play Audio";

            BehaviorSequence behaviorSequence = new BehaviorSequence(true, new List <IBehavior>
            {
                delayBehavior,
                audioBehavior
            });

            behaviorSequence.Data.Name       = "Audio Hint";
            behaviorSequence.Data.IsBlocking = false;

            return(behaviorSequence);
        }
        public IEnumerator PlayAudioOnDectivationBehavior()
        {
            // Given a training with PlayAudioOnDeactivationBehavior and some ResourceData,
            ICourse training1 = new LinearTrainingBuilder("Training")
                                .AddChapter(new LinearChapterBuilder("Chapter")
                                            .AddStep(new BasicStepBuilder("Step")
                                                     .AddBehavior(new PlayAudioBehavior(new ResourceAudio(new LocalizedString("TestPath")), BehaviorExecutionStages.Activation))))
                                .Build();

            // When we serialize and deserialize it,
            ICourse training2 = Serializer.CourseFromByteArray(Serializer.CourseToByteArray(training1));

            PlayAudioBehavior behavior1 = training1.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as PlayAudioBehavior;
            PlayAudioBehavior behavior2 = training2.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as PlayAudioBehavior;

            // Then path to audio file should not change.
            Assert.IsNotNull(behavior1);
            Assert.IsNotNull(behavior2);
            Assert.AreEqual(TestingUtils.GetField <LocalizedString>(behavior1.Data.AudioData, "path").Key, TestingUtils.GetField <LocalizedString>(behavior2.Data.AudioData, "path").Key);

            return(null);
        }
コード例 #11
0
        public IEnumerator IsDeactivatedAfterPlayingAudio()
        {
            // Given a PlayAudioBehavior with activation mode "Deactivation",
            ResourceAudio audioData = new ResourceAudio(new LocalizedString("Sounds/test-sound", "Sounds/test-sound"));
            IBehavior     behavior  = new PlayAudioBehavior(audioData, BehaviorExecutionStages.Deactivation, audioSource);

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

            // When we activate and deactivate it and wait until the clip stops playing,
            behavior.LifeCycle.Activate();

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

                behavior.Update();
            }

            behavior.LifeCycle.Deactivate();

            float startTime = Time.time;

            while (audioSource.isPlaying)
            {
                yield return(null);

                behavior.Update();
            }

            float duration = Time.time - startTime;

            // Then the behavior is deactivated after the clip's duration has elapsed, within a margin of error.
            Assert.AreEqual(audioData.AudioClip.length, duration, 0.1f);
            Assert.IsFalse(audioSource.isPlaying);
            Assert.AreEqual(Stage.Inactive, behavior.LifeCycle.Stage);
        }
        public IEnumerator LocalizedString()
        {
            // Given a LocalizedString
            LocalizedString original = new LocalizedString("Test1{0}{1}", "Test2", "Test3", "Test4");

            Step step = new Step("");

            step.Data.Behaviors.Data.Behaviors.Add(new PlayAudioBehavior(new ResourceAudio(original), BehaviorExecutionStages.Activation));
            ICourse course = new Course("", new Chapter("", step));

            // When we serialize and deserialize a training with it
            ICourse           deserializedCourse   = Serializer.CourseFromByteArray(Serializer.CourseToByteArray(course));
            PlayAudioBehavior deserializedBehavior = deserializedCourse.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as PlayAudioBehavior;
            // ReSharper disable once PossibleNullReferenceException
            LocalizedString deserialized = ((ResourceAudio)deserializedBehavior.Data.AudioData).Path;

            // Then deserialized training should has different instance of LocalizedString but with the same values.
            Assert.IsFalse(ReferenceEquals(original, deserialized));
            Assert.AreEqual(original.Key, deserialized.Key);
            Assert.AreEqual(original.DefaultText, deserialized.DefaultText);
            Assert.IsTrue(original.FormatParams.SequenceEqual(deserialized.FormatParams));

            yield return(null);
        }