TimelineRecorderTests.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections;
  2. using System.IO;
  3. using NUnit.Framework;
  4. using UnityEditor;
  5. using UnityEditor.Recorder;
  6. using UnityEditor.Recorder.Input;
  7. using UnityEditor.Recorder.Timeline;
  8. using UnityEngine.Playables;
  9. using UnityEngine.TestTools;
  10. using UnityEngine.Timeline;
  11. namespace UnityEngine.Recorder.Tests
  12. {
  13. class TimelineRecorderTests
  14. {
  15. [UnityTest]
  16. public IEnumerator TimelineRecorder_ShouldHaveProperPublicAPI()
  17. {
  18. var timeline = ScriptableObject.CreateInstance<TimelineAsset>();
  19. var track = timeline.CreateTrack<RecorderTrack>(null, "AAA");
  20. var clip = track.CreateClip<RecorderClip>();
  21. clip.start = 1.0f;
  22. clip.duration = 3.0f;
  23. var recorderSettings = ScriptableObject.CreateInstance<MovieRecorderSettings>();
  24. var expectedOutputFile = Application.dataPath + "/../RecordingTests/movie_test_from_timeline_001.mp4";
  25. recorderSettings.OutputFile = Application.dataPath + "/../RecordingTests/movie_test_from_timeline_" + DefaultWildcard.Take;
  26. recorderSettings.ImageInputSettings = new GameViewInputSettings
  27. {
  28. OutputWidth = 640,
  29. OutputHeight = 480
  30. };
  31. recorderSettings.OutputFormat = MovieRecorderSettings.VideoRecorderOutputFormat.MP4;
  32. recorderSettings.VideoBitRateMode = VideoBitrateMode.Low;
  33. var recorderClip = (RecorderClip) clip.asset;
  34. recorderClip.settings = recorderSettings;
  35. var director = new GameObject("director").AddComponent<PlayableDirector>();
  36. director.playableAsset = timeline;
  37. timeline.durationMode = TimelineAsset.DurationMode.FixedLength;
  38. timeline.fixedDuration = 5.0f;
  39. if (File.Exists(expectedOutputFile))
  40. File.Delete(expectedOutputFile);
  41. director.Play();
  42. new GameObject("Camera").AddComponent<Camera>().transform.localPosition = new Vector3(0.0f, 0.0f, -10.0f);
  43. new GameObject("Light").AddComponent<Light>().type = LightType.Directional;
  44. var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
  45. cube.transform.localPosition = new Vector3(0.0f, -5.0f, 0.0f);
  46. var runTimeSeconds = clip.start + clip.duration + 0.5f;
  47. while (director.time < runTimeSeconds)
  48. {
  49. cube.transform.localPosition = cube.transform.localPosition + Vector3.up * 0.02f;
  50. yield return null;
  51. }
  52. Assert.IsTrue(File.Exists(expectedOutputFile));
  53. File.Delete(expectedOutputFile);
  54. Assert.Pass();
  55. }
  56. }
  57. }