//---------------------------------------------------------------------------------------------------------------------- void DrawPreviewImage(ref PreviewDrawInfo drawInfo, TimelineClip clip, RenderCachePlayableAsset renderCachePlayableAsset) { double normalizedLocalTime = drawInfo.LocalTime / clip.duration; IList <string> imageFileNames = renderCachePlayableAsset.GetImageFileNames(); Assert.IsNotNull(imageFileNames); int count = imageFileNames.Count; Assert.IsTrue(imageFileNames.Count > 0); int index = Mathf.RoundToInt(count * (float)normalizedLocalTime); index = Mathf.Clamp(index, 0, count - 1); //Load string imagePath = renderCachePlayableAsset.GetImageFilePath(index); if (!File.Exists(imagePath)) { return; } ImageLoader.GetImageDataInto(imagePath, StreamingImageSequenceConstants.IMAGE_TYPE_PREVIEW , out ImageData imageData); switch (imageData.ReadStatus) { case StreamingImageSequenceConstants.READ_STATUS_LOADING: break; case StreamingImageSequenceConstants.READ_STATUS_SUCCESS: { Texture2D tex = PreviewTextureFactory.GetOrCreate(imagePath, ref imageData); 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 void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { base.DrawBackground(clip, region); Rect rect = region.position; if (rect.width <= SISEditorConstants.MIN_PREVIEW_REGION_WIDTH) { return; } RenderCachePlayableAsset curAsset = clip.asset as RenderCachePlayableAsset; if (null == curAsset) { return; } IList <string> imageFileNames = curAsset.GetImageFileNames(); if (null == imageFileNames || imageFileNames.Count <= 0) { return; } if (Event.current.type == EventType.Repaint) { PreviewClipInfo clipInfo = new PreviewClipInfo() { Duration = clip.duration, TimeScale = clip.timeScale, ClipIn = clip.clipIn, FramePerSecond = clip.parentTrack.timelineAsset.editorSettings.fps, ImageDimensionRatio = curAsset.GetOrUpdateDimensionRatio(), VisibleLocalStartTime = region.startTime, VisibleLocalEndTime = region.endTime, VisibleRect = rect, }; PreviewUtility.EnumeratePreviewImages(ref clipInfo, (PreviewDrawInfo drawInfo) => { DrawPreviewImage(ref drawInfo, clip, curAsset); }); } }