Пример #1
0
        public IEnumerator ShowFrameMarkers()
        {
            PlayableDirector director = EditorUtilityTest.NewSceneWithDirector();
            TimelineClip     clip     = EditorUtilityTest.CreateTestSISTimelineClip(director);
            StreamingImageSequencePlayableAsset sisAsset = clip.asset as StreamingImageSequencePlayableAsset;

            Assert.IsNotNull(sisAsset);
            yield return(null);

            //Show
            SISClipData clipData = sisAsset.GetBoundClipData();

            TrackAsset trackAsset = clip.GetParentTrack();

            clipData.RequestFrameMarkers(true, true);
            TimelineEditor.Refresh(RefreshReason.ContentsModified);
            yield return(null);

            Assert.AreEqual(TimelineUtility.CalculateNumFrames(clip), trackAsset.GetMarkerCount());
            yield return(null);


            //Undo showing FrameMarkers
            EditorUtilityTest.UndoAndRefreshTimelineEditor(); yield return(null);

            Assert.False(clipData.AreFrameMarkersRequested());
            Assert.AreEqual(0, trackAsset.GetMarkerCount());


            EditorUtilityTest.DestroyTestTimelineAssets(clip);
            yield return(null);
        }
Пример #2
0
        public IEnumerator ResizePlayableAsset()
        {
            PlayableDirector director = EditorUtilityTest.NewSceneWithDirector();
            TimelineClip     clip     = EditorUtilityTest.CreateTestSISTimelineClip(director);
            StreamingImageSequencePlayableAsset sisAsset = clip.asset as StreamingImageSequencePlayableAsset;

            Assert.IsNotNull(sisAsset);
            yield return(null);

            SISClipData clipData = sisAsset.GetBoundClipData();

            Assert.IsNotNull(clipData);

            clipData.RequestFrameMarkers(true, true);
            Undo.IncrementCurrentGroup(); //the base of undo is here. FrameMarkerVisibility is still true after undo
            TimelineEditor.Refresh(RefreshReason.ContentsModified);
            yield return(null);

            //Original length
            TrackAsset trackAsset = clip.GetParentTrack();

            Assert.AreEqual(TimelineUtility.CalculateNumFrames(clip), trackAsset.GetMarkerCount());
            double origClipDuration = clip.duration;

            //Resize longer
            EditorUtilityTest.ResizeSISTimelineClip(clip, origClipDuration + 3.0f); yield return(null);

            Assert.AreEqual(TimelineUtility.CalculateNumFrames(clip), trackAsset.GetMarkerCount());

            //Undo
            EditorUtilityTest.UndoAndRefreshTimelineEditor(); yield return(null);

            Assert.AreEqual(origClipDuration, clip.duration);
            Assert.AreEqual(TimelineUtility.CalculateNumFrames(clip), trackAsset.GetMarkerCount());

            //Resize shorter
            EditorUtilityTest.ResizeSISTimelineClip(clip, Mathf.Max(0.1f, ((float)(origClipDuration) - 3.0f))); yield return(null);

            Assert.AreEqual(TimelineUtility.CalculateNumFrames(clip), trackAsset.GetMarkerCount());

            //Undo
            EditorUtilityTest.UndoAndRefreshTimelineEditor(); yield return(null);

            Assert.AreEqual(origClipDuration, clip.duration);
            Assert.AreEqual(TimelineUtility.CalculateNumFrames(clip), trackAsset.GetMarkerCount());


            EditorUtilityTest.DestroyTestTimelineAssets(clip);
            yield return(null);
        }
Пример #3
0
        public IEnumerator ResetFrameMarkers()
        {
            PlayableDirector director = EditorUtilityTest.NewSceneWithDirector();
            TimelineClip     clip     = EditorUtilityTest.CreateTestSISTimelineClip(director);
            StreamingImageSequencePlayableAsset sisAsset = clip.asset as StreamingImageSequencePlayableAsset;

            Assert.IsNotNull(sisAsset);
            yield return(null);

            SISClipData clipData = sisAsset.GetBoundClipData();

            Assert.IsNotNull(clipData);
            clipData.RequestFrameMarkers(true);
            yield return(null);

            //Change image to false
            StreamingImageSequenceTrack track = clip.GetParentTrack() as StreamingImageSequenceTrack;

            Assert.IsNotNull(track);
            foreach (var m in track.GetMarkers())
            {
                FrameMarker marker = m as FrameMarker;
                Assert.IsNotNull(marker);
                marker.SetFrameUsed(false);

                UnityEngine.Assertions.Assert.IsFalse(marker.IsFrameUsed());
            }
            yield return(null);

            sisAsset.ResetPlayableFrames();
            yield return(null);

            //Check if all markers have been reset to used
            foreach (var m in track.GetMarkers())
            {
                FrameMarker marker = m as FrameMarker;
                Assert.IsNotNull(marker);
                UnityEngine.Assertions.Assert.IsTrue(marker.IsFrameUsed());
            }
            yield return(null);


            EditorUtilityTest.DestroyTestTimelineAssets(clip);
            yield return(null);
        }
Пример #4
0
        public IEnumerator SetPlayableAssetFPS()
        {
            PlayableDirector director = EditorUtilityTest.NewSceneWithDirector();
            TimelineClip     clip     = EditorUtilityTest.CreateTestSISTimelineClip(director);
            StreamingImageSequencePlayableAsset sisAsset = clip.asset as StreamingImageSequencePlayableAsset;

            Assert.IsNotNull(sisAsset);

            //Make sure that we have some images
            int numImages = sisAsset.GetNumImages();

            Assert.IsTrue(numImages > 0);
            yield return(null);

            //Set animationCurve with half speed
            SISClipData sisClipData = sisAsset.GetBoundClipData();

            Assert.IsNotNull(sisClipData);
            float          origCurveDuration = sisClipData.CalculateCurveDuration();
            AnimationCurve halfSpeedCurve    = AnimationCurve.Linear(0, 0, origCurveDuration * 2, 1.0f);

            AnimationUtility.SetEditorCurve(clip.curves, StreamingImageSequencePlayableAsset.GetTimeCurveBinding(), halfSpeedCurve);
            yield return(null);

            float origFPS       = SISPlayableAssetUtility.CalculateFPS(sisAsset);
            float origDuration  = (float)clip.duration;
            float origTimeScale = (float)clip.timeScale;

            SetFPSAndCheck(sisAsset, origFPS * 8.0f);
            SetFPSAndCheck(sisAsset, origFPS / 16.0f);
            SetFPSAndCheck(sisAsset, origFPS * 0.25f);
            SetFPSAndCheck(sisAsset, origFPS * 4.0f);
            SetFPSAndCheck(sisAsset, origFPS);
            yield return(null);

            //Check if we are back
            Assert.IsTrue(Mathf.Approximately(origFPS, SISPlayableAssetUtility.CalculateFPS(sisAsset)));
            Assert.IsTrue(Mathf.Approximately(origDuration, (float)clip.duration));
            Assert.IsTrue(Mathf.Approximately(origTimeScale, (float)clip.timeScale));

            EditorUtilityTest.DestroyTestTimelineAssets(clip);
            yield return(null);
        }
        internal static void EditPlayableFrame(SISPlayableFrame playableFrame,
                                               StreamingImageSequencePlayableAsset sisPlayableAsset)
        {
            //Find the correct imageIndex. The number of frames in the clip may be more/less than the number of images
            int playableFrameIndex = playableFrame.GetIndex();
            int numPlayableFrames  = sisPlayableAsset.GetBoundClipData().GetNumPlayableFrames();

            int numImages = sisPlayableAsset.GetNumImages();
            int index     = Mathf.FloorToInt(playableFrameIndex * ((float)numImages / numPlayableFrames));

            string filePath = sisPlayableAsset.GetImageFilePath(index);

            if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
            {
                EditorUtility.DisplayDialog(StreamingImageSequenceConstants.DIALOG_HEADER,
                                            "Image does not exist: " + filePath,
                                            "Ok");
                return;
            }

            LaunchImageApplicationExternalTool(Path.GetFullPath(filePath));
        }
Пример #6
0
        void SetFPSAndCheck(StreamingImageSequencePlayableAsset sisAsset, float newFPS)
        {
            SISClipData sisClipData = sisAsset.GetBoundClipData();

            Assert.IsNotNull(sisClipData);
            TimelineClip clip = sisClipData.GetOwner();

            Assert.IsNotNull(clip);


            float prevFPS          = SISPlayableAssetUtility.CalculateFPS(sisAsset);
            float prevClipDuration = (float)clip.duration;
            float prevTimeScale    = (float)clip.timeScale;

            Assert.Greater(prevFPS, 0);
            float fpsMultiplier = newFPS / prevFPS;

            Assert.Greater(fpsMultiplier, 0);
            float timeMultiplier = 1.0f / fpsMultiplier;

            SISPlayableAssetUtility.SetFPS(sisAsset, newFPS);
            Assert.IsTrue(Mathf.Approximately(prevClipDuration * timeMultiplier, (float)clip.duration));
            Assert.IsTrue(Mathf.Approximately(prevTimeScale * fpsMultiplier, (float)clip.timeScale));
        }
Пример #7
0
//----------------------------------------------------------------------------------------------------------------------

        /// <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;
            }

            //[Note-sin: 2021-2-25] Track can be null during copy and paste
            if (null != track)
            {
                //This callback occurs before the clip is assigned to the track, but we need the track for creating curves.
                clip.TryMoveToTrack(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)
            {
                int numImages = asset.GetNumImages();
                if (numImages > 0)
                {
                    SISUserSettings userSettings = SISUserSettings.GetInstance();

                    clip.duration    = (double)(numImages) / (userSettings.GetDefaultSISPlayableAssetFPS());
                    clip.displayName = Path.GetFileName(asset.GetFolder());
                }

                ExtendedClipEditorUtility.CreateTimelineClipCurve(clip, StreamingImageSequencePlayableAsset.GetTimeCurveBinding());
            }

            if (null == clonedFrom)
            {
                asset.BindClipData(new SISClipData(clip));
                return;
            }

            //Duplicate/Split process
            StreamingImageSequencePlayableAsset clonedFromAsset = clonedFrom.asset as StreamingImageSequencePlayableAsset;

            Assert.IsNotNull(clonedFromAsset);

            SISClipData otherSISData = clonedFromAsset.GetBoundClipData();

            if (null == otherSISData)
            {
                asset.BindClipData(new SISClipData(clip)); //[Note-sin: 2021-2-25] can be null during copy and paste
                return;
            }

            SISClipData sisData = new SISClipData(clip, otherSISData);

            asset.BindClipData(sisData);
            clip.displayName = clonedFrom.displayName + " (Cloned)";
        }
Пример #8
0
        public IEnumerator UncheckFrameMarkers()
        {
            PlayableDirector director = EditorUtilityTest.NewSceneWithDirector();
            TimelineClip     clip     = EditorUtilityTest.CreateTestSISTimelineClip(director);
            StreamingImageSequencePlayableAsset sisAsset = clip.asset as StreamingImageSequencePlayableAsset;

            Assert.IsNotNull(sisAsset);
            yield return(null);

            SISClipData clipData = sisAsset.GetBoundClipData();

            Assert.IsNotNull(clipData);
            clipData.RequestFrameMarkers(true, true);
            yield return(null);

            double timePerFrame = TimelineUtility.CalculateTimePerFrame(clip);
            int    numImages    = sisAsset.GetNumImages();

            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
            EditorCurveBinding curveBinding = StreamingImageSequencePlayableAsset.GetTimeCurveBinding();

            ExtendedClipEditorUtility.ResetClipDataCurve(sisAsset, curveBinding);
            yield return(null);

            sisAsset.ResetPlayableFrames();
            yield return(null);

            StreamingImageSequenceTrack track = clip.GetParentTrack() 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;
            }
            Assert.AreEqual(numImages, 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);
        }