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); }
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); }
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); }
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; }
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; }
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; }
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; }
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); }
/// <inheritdoc /> public override Rect Draw(Rect rect, object currentValue, Action <object> changeValueCallback, GUIContent label) { ResourceAudio resourceAudio = currentValue as ResourceAudio; TextToSpeechAudio ttsAudio = currentValue as TextToSpeechAudio; if (resourceAudio != null) { if (resourceAudio.Path == null) { resourceAudio.Path = new LocalizedString(); changeValueCallback(resourceAudio); } ITrainingDrawer pathDrawer = DrawerLocator.GetDrawerForMember(resourceAudio.GetType().GetProperty("Path", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance), typeof(LocalizedString)); return(pathDrawer.Draw(rect, resourceAudio.Path, newPath => { resourceAudio.Path = (LocalizedString)newPath; changeValueCallback(resourceAudio); }, label)); } if (ttsAudio != null) { if (ttsAudio.Text == null) { ttsAudio.Text = new LocalizedString(); changeValueCallback(ttsAudio); } ITrainingDrawer pathDrawer = DrawerLocator.GetDrawerForMember(ttsAudio.GetType().GetProperty("Text", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance), typeof(LocalizedString)); return(pathDrawer.Draw(rect, ttsAudio.Text, newPath => { ttsAudio.Text = (LocalizedString)newPath; changeValueCallback(ttsAudio); }, label)); } return(base.Draw(rect, currentValue, changeValueCallback, label)); }
public IEnumerator ResourceAudio() { // Given we have a ResourceAudio instance, ResourceAudio audio = new ResourceAudio(new LocalizedString("TestPath")); ICourse course = new LinearTrainingBuilder("Training") .AddChapter(new LinearChapterBuilder("Chapter") .AddStep(new BasicStepBuilder("Step") .AddBehavior(new PlayAudioBehavior(audio, BehaviorExecutionStages.Activation)))) .Build(); // When we serialize and deserialize a training with it ICourse testCourse = Serializer.CourseFromByteArray(Serializer.CourseToByteArray(course)); // Then the path to audio resource should be the same. string audioPath1 = TestingUtils.GetField <LocalizedString>(((PlayAudioBehavior)course.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First()).Data.AudioData, "path").Key; string audioPath2 = TestingUtils.GetField <LocalizedString>(((PlayAudioBehavior)testCourse.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First()).Data.AudioData, "path").Key; Assert.AreEqual(audioPath1, audioPath2); return(null); }
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); }
private void Awake() { back_lighting = FindObjectOfType<BackgroundLighting>(); resource_audio = GetComponent<ResourceAudio>(); transform.Rotate(0, 0, Random.value * 360); }