public IEnumerator CreatePlayableAsset() { PlayableDirector director = EditorUtilityTest.NewSceneWithDirector(); TimelineClip clip = EditorUtilityTest.CreateTestTimelineClip(director); StreamingImageSequencePlayableAsset sisAsset = clip.asset as StreamingImageSequencePlayableAsset; Assert.IsNotNull(sisAsset); //Test the track immediately StreamingImageSequenceTrack track = clip.parentTrack as StreamingImageSequenceTrack; Assert.IsNotNull(track); Assert.IsNotNull(track.GetActivePlayableAsset()); yield return(null); IList <string> imageFileNames = sisAsset.GetImageFileNames(); Assert.IsNotNull(imageFileNames); Assert.IsTrue(imageFileNames.Count > 0); Assert.IsTrue(sisAsset.HasImages()); //Test that there should be no active PlayableAsset at the time above what exists in the track. director.time = clip.start + clip.duration + 1; yield return(null); Assert.IsNull(track.GetActivePlayableAsset()); EditorUtilityTest.DestroyTestTimelineAssets(clip); yield return(null); }
//---------------------------------------------------------------------------------------------------------------------- /// <inheritdoc/> public override void OnCreate(TimelineClip clip, TrackAsset track, TimelineClip clonedFrom) { StreamingImageSequencePlayableAsset asset = clip.asset as StreamingImageSequencePlayableAsset; if (null == asset) { Debug.LogError("Asset is not a StreamingImageSequencePlayableAsset: " + clip.asset); return; } StreamingImageSequenceTrack sisTrack = track as StreamingImageSequenceTrack; Assert.IsNotNull(sisTrack); //This callback occurs before the clip is assigned to the track, but we need the track for creating curves. clip.parentTrack = track; //If we have a default asset, and clonedFrom is NULL, which means this is created by user interaction, //such as Folder D&D UnityEditor.DefaultAsset timelineDefaultAsset = asset.GetTimelineDefaultAsset(); if (null != timelineDefaultAsset && null == clonedFrom) { InitializeAssetFromDefaultAsset(asset, timelineDefaultAsset); } //If the clip already has curves (because of cloning, etc), then we don't set anything if (null == clip.curves) { if (asset.HasImages()) { clip.duration = asset.GetImageFileNames().Count * 0.125; // 8fps (standard limited animation) clip.displayName = Path.GetFileName(asset.GetFolder()); } clip.CreateCurves("Curves: " + clip.displayName); } TimelineClipSISData sisData = null; asset.InitTimelineClipCurve(clip); if (null == clonedFrom) { sisData = new TimelineClipSISData(clip); asset.BindTimelineClipSISData(sisData); return; } //Duplicate/Split process StreamingImageSequencePlayableAsset clonedFromAsset = clonedFrom.asset as StreamingImageSequencePlayableAsset; Assert.IsNotNull(clonedFromAsset); TimelineClipSISData otherSISData = clonedFromAsset.GetBoundTimelineClipSISData(); sisData = new TimelineClipSISData(clip, otherSISData); asset.BindTimelineClipSISData(sisData); clip.displayName = clonedFrom.displayName + " (Cloned)"; }
//---------------------------------------------------------------------------------------------------------------------- void DrawPreviewImage(ref PreviewDrawInfo drawInfo, TimelineClip clip, StreamingImageSequencePlayableAsset sisAsset) { int imageIndex = sisAsset.LocalTimeToImageIndex(clip, drawInfo.LocalTime); IList <string> imageFileNames = sisAsset.GetImageFileNames(); //Load string imagePath = sisAsset.GetImageFilePath(imageIndex); ImageLoader.GetImageDataInto(imagePath, StreamingImageSequenceConstants.IMAGE_TYPE_PREVIEW , out ImageData readResult); switch (readResult.ReadStatus) { case StreamingImageSequenceConstants.READ_STATUS_LOADING: break; case StreamingImageSequenceConstants.READ_STATUS_SUCCESS: { Texture2D tex = PreviewTextureFactory.GetOrCreate(imagePath, ref readResult); if (null != tex) { Graphics.DrawTexture(drawInfo.DrawRect, tex); } break; } default: { ImageLoader.RequestLoadPreviewImage(imagePath, (int)drawInfo.DrawRect.width, (int)drawInfo.DrawRect.height); break; } } }
//---------------------------------------------------------------------------------------------------------------------- /// <inheritdoc/> public override ClipDrawOptions GetClipOptions(TimelineClip clip) { var clipOptions = base.GetClipOptions(clip); StreamingImageSequencePlayableAsset asset = clip.asset as StreamingImageSequencePlayableAsset; if (null == asset) { Debug.LogError("Asset is not a StreamingImageSequencePlayableAsset: " + clip.asset); return(clipOptions); } string folder = asset.GetFolder(); if (string.IsNullOrEmpty(folder)) { clipOptions.errorText = NO_FOLDER_ASSIGNED_ERROR; } else if (!Directory.Exists(folder)) { clipOptions.errorText = FOLDER_MISSING_ERROR; } else if (asset.GetImageFileNames() == null) { clipOptions.errorText = NO_PICTURES_ASSIGNED_ERROR; } clipOptions.tooltip = folder; return(clipOptions); }
public IEnumerator ReloadPlayableAsset() { PlayableDirector director = EditorUtilityTest.NewSceneWithDirector(); TimelineClip clip = EditorUtilityTest.CreateTestTimelineClip(director); StreamingImageSequencePlayableAsset sisAsset = clip.asset as StreamingImageSequencePlayableAsset; Assert.IsNotNull(sisAsset); string folder = sisAsset.GetFolder(); Assert.IsNotNull(folder); int numOriginalImages = sisAsset.GetImageFileNames().Count; Assert.Greater(numOriginalImages, 0); List <string> testImages = ImageFolderPlayableAsset.FindImageFileNames(folder); List <string> copiedImagePaths = new List <string>(testImages.Count); foreach (string imageFileName in testImages) { string src = Path.Combine(folder, imageFileName); string dest = Path.Combine(folder, "Copied_" + imageFileName); File.Copy(src, dest); copiedImagePaths.Add(dest); } yield return(null); sisAsset.Reload(); yield return(null); Assert.AreEqual(numOriginalImages * 2, sisAsset.GetImageFileNames().Count); //Cleanup foreach (string imagePath in copiedImagePaths) { File.Delete(imagePath); } EditorUtilityTest.DestroyTestTimelineAssets(clip); yield return(null); }
public void Import() { EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects); string fullPath = "Packages/com.unity.streaming-image-sequence/Tests/Data/AeConvert.jstimeline"; Assert.IsTrue(File.Exists(fullPath)); string destFolder = "TestRunner"; JstimelineImporter.ImportTimeline(fullPath, destFolder); //Check if the generated director is valid PlayableDirector[] directors = Object.FindObjectsOfType <PlayableDirector>(); Assert.AreEqual(1, directors.Length); PlayableDirector pd = directors[0]; TimelineAsset timelineAsset = pd.playableAsset as TimelineAsset; Assert.IsNotNull(timelineAsset); Assert.AreEqual(timelineAsset.outputTrackCount, 1); foreach (TrackAsset trackAsset in timelineAsset.GetOutputTracks()) { StreamingImageSequenceTrack imageSequenceTrack = trackAsset as StreamingImageSequenceTrack; Assert.IsNotNull(imageSequenceTrack); foreach (TimelineClip clip in imageSequenceTrack.GetClips()) { Assert.IsNotNull(clip.asset); StreamingImageSequencePlayableAsset playableAsset = clip.asset as StreamingImageSequencePlayableAsset; Assert.IsNotNull(playableAsset); Assert.AreEqual(10, playableAsset.GetImageFileNames().Count); } //Make sure a StreamingImageSequenceRenderer is bound to the trackAsset StreamingImageSequenceRenderer r = pd.GetGenericBinding(trackAsset) as StreamingImageSequenceRenderer; Assert.IsNotNull(r); } //Delete created assets string destAssetsFolder = "Assets/" + destFolder; string[] createdAssets = AssetDatabase.FindAssets("", new[] { destAssetsFolder }); Assert.Greater(createdAssets.Length, 0); foreach (string guid in createdAssets) { string assetPath = AssetDatabase.GUIDToAssetPath(guid); AssetDatabase.DeleteAsset(assetPath); } Directory.Delete(destAssetsFolder); }
public IEnumerator ImportFromStreamingAssets() { PlayableDirector director = EditorUtilityTest.NewSceneWithDirector(); TimelineClip clip = EditorUtilityTest.CreateTestTimelineClip(director); StreamingImageSequencePlayableAsset sisAsset = clip.asset as StreamingImageSequencePlayableAsset; Assert.IsNotNull(sisAsset); //Copy test data to streamingAssetsPath const string DEST_FOLDER_NAME = "ImportFromStreamingAssetsTest"; string streamingAssetsFolder = AssetEditorUtility.NormalizeAssetPath(Application.streamingAssetsPath); string destFolderGUID = AssetDatabase.CreateFolder(streamingAssetsFolder, DEST_FOLDER_NAME); string destFolder = AssetDatabase.GUIDToAssetPath(destFolderGUID); string srcFolder = sisAsset.GetFolder(); IList <string> imageFileNames = sisAsset.GetImageFileNames(); foreach (string imageFileName in imageFileNames) { string src = Path.Combine(srcFolder, imageFileName); string dest = Path.Combine(destFolder, imageFileName); File.Copy(src, dest, true); } AssetDatabase.Refresh(); yield return(null); ImageSequenceImporter.ImportImages(destFolder, sisAsset); yield return(null); Assert.AreEqual(destFolder, sisAsset.GetFolder()); //Cleanup AssetDatabase.DeleteAsset(destFolder); EditorUtilityTest.DestroyTestTimelineAssets(clip); yield return(null); }
public IEnumerator UncheckFrameMarkers() { PlayableDirector director = EditorUtilityTest.NewSceneWithDirector(); TimelineClip clip = EditorUtilityTest.CreateTestTimelineClip(director); StreamingImageSequencePlayableAsset sisAsset = clip.asset as StreamingImageSequencePlayableAsset; Assert.IsNotNull(sisAsset); TimelineClipSISData timelineClipSISData = sisAsset.GetBoundTimelineClipSISData(); timelineClipSISData.RequestFrameMarkers(true); yield return(null); double timePerFrame = TimelineUtility.CalculateTimePerFrame(clip); int numImages = sisAsset.GetImageFileNames().Count; clip.timeScale = 3.75f; //use scaling EditorUtilityTest.ResizeSISTimelineClip(clip, (timePerFrame * numImages)); yield return(null); int numFrames = TimelineUtility.CalculateNumFrames(clip); Assert.AreEqual(numImages, numFrames); //Reset: make sure that the curve is a simple straight line from 0 to 1 StreamingImageSequencePlayableAsset.ResetTimelineClipCurve(clip); yield return(null); sisAsset.ResetPlayableFrames(); yield return(null); StreamingImageSequenceTrack track = clip.parentTrack as StreamingImageSequenceTrack; Assert.IsNotNull(track); List <FrameMarker> frameMarkers = new List <FrameMarker>(); int i = 0; foreach (var m in track.GetMarkers()) { FrameMarker marker = m as FrameMarker; Assert.IsNotNull(marker); frameMarkers.Add(marker); int imageIndex = sisAsset.GlobalTimeToImageIndex(clip, marker.time); Assert.AreEqual(i, imageIndex); ++i; } //Uncheck and see if the unchecked images became ignored frameMarkers[4].SetFrameUsed(false); frameMarkers[5].SetFrameUsed(false); Assert.AreEqual(3, sisAsset.GlobalTimeToImageIndex(clip, frameMarkers[4].time)); Assert.AreEqual(3, sisAsset.GlobalTimeToImageIndex(clip, frameMarkers[5].time)); frameMarkers[7].SetFrameUsed(false); frameMarkers[8].SetFrameUsed(false); Assert.AreEqual(6, sisAsset.GlobalTimeToImageIndex(clip, frameMarkers[7].time)); Assert.AreEqual(6, sisAsset.GlobalTimeToImageIndex(clip, frameMarkers[8].time)); EditorUtilityTest.DestroyTestTimelineAssets(clip); yield return(null); }