Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 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;
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }