//Called when a clip is changed by the Editor. (TrimStart, TrimEnd, etc) public override void OnClipChanged(TimelineClip clip) { base.OnClipChanged(clip); ImageFolderPlayableAsset <T> imageFolderPlayableAsset = clip.asset as ImageFolderPlayableAsset <T>; Assert.IsNotNull(imageFolderPlayableAsset); imageFolderPlayableAsset.RefreshPlayableFrames(); }
//---------------------------------------------------------------------------------------------------------------------- /// <inheritdoc/> public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { base.DrawBackground(clip, region); Rect rect = region.position; if (rect.width <= SISEditorConstants.MIN_PREVIEW_REGION_WIDTH) { return; } ImageFolderPlayableAsset <T> curAsset = clip.asset as ImageFolderPlayableAsset <T>; if (null == curAsset) { return; } DrawBackgroundTexture(rect, curAsset.GetTimelineBGColor()); int numImages = curAsset.GetNumImages(); if (numImages <= 0) { return; } if (Event.current.type == EventType.Repaint) { PreviewClipInfo clipInfo = new PreviewClipInfo() { Duration = clip.duration, TimeScale = clip.timeScale, ClipIn = clip.clipIn, FramePerSecond = clip.GetParentTrack().timelineAsset.editorSettings.GetFPS(), ImageDimensionRatio = curAsset.GetOrUpdateDimensionRatio(), VisibleLocalStartTime = region.startTime, VisibleLocalEndTime = region.endTime, VisibleRect = rect, }; PreviewUtility.EnumeratePreviewImages(ref clipInfo, (PreviewDrawInfo drawInfo) => { DrawPreviewImageV(ref drawInfo, clip, curAsset); }); //For hiding frame marker automatically PlayableFrameClipData clipData = curAsset.GetBoundClipData(); if (null != clipData) { clipData.UpdateTimelineWidthPerFrame(rect.width, region.endTime - region.startTime, clipInfo.FramePerSecond, clipInfo.TimeScale); } } }
//---------------------------------------------------------------------------------------------------------------------- protected override void DrawPreviewImageV(ref PreviewDrawInfo drawInfo, TimelineClip clip, ImageFolderPlayableAsset <SISClipData> playableAsset) { StreamingImageSequencePlayableAsset sisAsset = playableAsset as StreamingImageSequencePlayableAsset; Assert.IsNotNull(sisAsset); int imageIndex = sisAsset.LocalTimeToImageIndex(clip, drawInfo.LocalTime); string imagePath = sisAsset.GetImageFilePath(imageIndex); PreviewUtility.DrawPreviewImage(ref drawInfo, imagePath); }
//--------------------------------------------------------------------------------------------------------------------- //Path can point to a file or a folder. //If it points to a file, then the folder will be automatically detected private static void FindFolderAndImages(string path, out string folder, out List <string> imagePaths) { Assert.IsFalse(string.IsNullOrEmpty(path)); //Convert path to folder here folder = path; FileAttributes attr = File.GetAttributes(path); if (!attr.HasFlag(FileAttributes.Directory)) { folder = Path.GetDirectoryName(folder); } imagePaths = ImageFolderPlayableAsset.FindImageFileNames(folder); }
//--------------------------------------------------------------------------------------------------------------------- //Path can point to a file or a folder. //If it points to a file, then the folder will be automatically detected private static void FindFolderAndImages(string path, out string folder, out List <WatchedFileInfo> imageFiles) { Assert.IsFalse(string.IsNullOrEmpty(path)); //Convert path to folder here folder = path; FileAttributes attr = File.GetAttributes(path); if (!attr.HasFlag(FileAttributes.Directory)) { folder = Path.GetDirectoryName(folder); } imageFiles = ImageFolderPlayableAsset.FindFiles(folder, StreamingImageSequencePlayableAsset.GetSupportedImageFilePatterns() ); }
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); }
//---------------------------------------------------------------------------------------------------------------------- protected override void DrawPreviewImageV(ref PreviewDrawInfo drawInfo, TimelineClip clip, ImageFolderPlayableAsset <RenderCacheClipData> renderCachePlayableAsset) { double normalizedLocalTime = drawInfo.LocalTime / clip.duration; int numImages = renderCachePlayableAsset.GetNumImages(); Assert.IsTrue(numImages > 0); //Can't round up, because if the time for the next frame hasn't been reached, then we should stick int index = Mathf.FloorToInt(numImages * (float)normalizedLocalTime); index = Mathf.Clamp(index, 0, numImages - 1); //Draw string imagePath = renderCachePlayableAsset.GetImageFilePath(index); PreviewUtility.DrawPreviewImage(ref drawInfo, imagePath); }
//---------------------------------------------------------------------------------------------------------------------- protected abstract void DrawPreviewImageV(ref PreviewDrawInfo drawInfo, TimelineClip clip, ImageFolderPlayableAsset <T> playableAsset);