//----------------------------------------------------------------------------------------------------------------------

        /// <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)";
        }
        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 DrawBackground(TimelineClip clip, ClipBackgroundRegion region)
        {
            base.DrawBackground(clip, region);

            Rect rect = region.position;

            if (rect.width <= SISEditorConstants.MIN_PREVIEW_REGION_WIDTH)
            {
                return;
            }

            StreamingImageSequencePlayableAsset curAsset = clip.asset as StreamingImageSequencePlayableAsset;

            if (null == curAsset || !curAsset.HasImages())
            {
                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);
                });

                //For hiding frame marker automatically
                int    numFrames     = Mathf.RoundToInt((float)((region.endTime - region.startTime) * clipInfo.FramePerSecond));
                double widthPerFrame = rect.width / numFrames;
                TimelineClipSISData timelineClipSISData = curAsset.GetBoundTimelineClipSISData();
                if (null != timelineClipSISData)
                {
                    timelineClipSISData.SetTimelineWidthPerFrame(widthPerFrame);
                }
            }
        }