예제 #1
0
        public IEnumerator CreatePlayableAsset()
        {
            PlayableDirector director = EditorUtilityTest.NewSceneWithDirector();
            TimelineClip     clip     = EditorUtilityTest.CreateTestSISTimelineClip(director);
            StreamingImageSequencePlayableAsset sisAsset = clip.asset as StreamingImageSequencePlayableAsset;

            Assert.IsNotNull(sisAsset);

            //Test the track immediately
            StreamingImageSequenceTrack track = clip.GetParentTrack() as StreamingImageSequenceTrack;

            Assert.IsNotNull(track);
            Assert.IsNotNull(track.GetActivePlayableAsset());

            yield return(null);

            int numImages = sisAsset.GetNumImages();

            Assert.IsTrue(numImages > 0);



            //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);
        }
예제 #2
0
//----------------------------------------------------------------------------------------------------------------------
        /// <inheritdoc/>
        public override ClipDrawOptions GetClipOptions(TimelineClip clip)
        {
            ClipDrawOptions 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.GetNumImages() <= 0)
            {
                clipOptions.errorText = NO_PICTURES_ASSIGNED_ERROR;
            }
            clipOptions.tooltip = folder;

#if AT_USE_TIMELINE_GE_1_6_0
            clipOptions.hideScaleIndicator = true;
#endif

            return(clipOptions);
        }
예제 #3
0
        public IEnumerator ReloadPlayableAsset()
        {
            PlayableDirector director = EditorUtilityTest.NewSceneWithDirector();
            TimelineClip     clip     = EditorUtilityTest.CreateTestSISTimelineClip(director);
            StreamingImageSequencePlayableAsset sisAsset = clip.asset as StreamingImageSequencePlayableAsset;

            Assert.IsNotNull(sisAsset);

            string folder = sisAsset.GetFolder();

            Assert.IsNotNull(folder);
            int numOriginalImages = sisAsset.GetNumImages();

            Assert.Greater(numOriginalImages, 0);


            List <WatchedFileInfo> testImages       = sisAsset.FindImages(folder);
            List <string>          copiedImagePaths = new List <string>(testImages.Count);

            foreach (WatchedFileInfo imageFile in testImages)
            {
                string fileName = imageFile.GetName();
                string src      = Path.Combine(folder, fileName);
                string dest     = Path.Combine(folder, "Copied_" + fileName);
                File.Copy(src, dest, true);
                copiedImagePaths.Add(dest);
            }

            yield return(null);

            sisAsset.Reload();

            yield return(null);

            Assert.AreEqual(numOriginalImages * 2, sisAsset.GetNumImages());

            //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.GetNumImages());
                }

                //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);
        }
예제 #5
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));
        }
예제 #7
0
        public IEnumerator ImportFromStreamingAssets()
        {
            PlayableDirector director = EditorUtilityTest.NewSceneWithDirector();
            TimelineClip     clip     = EditorUtilityTest.CreateTestSISTimelineClip(director);
            StreamingImageSequencePlayableAsset sisAsset = clip.asset as StreamingImageSequencePlayableAsset;

            Assert.IsNotNull(sisAsset);

            //Copy test data to streamingAssetsPath
            const string DEST_FOLDER_NAME      = "ImportFromStreamingAssetsTest";
            string       streamingAssetsFolder = AssetUtility.NormalizeAssetPath(Application.streamingAssetsPath);
            string       destFolderGUID        = AssetDatabase.CreateFolder(streamingAssetsFolder, DEST_FOLDER_NAME);
            string       destFolder            = AssetDatabase.GUIDToAssetPath(destFolderGUID);
            int          numImages             = sisAsset.GetNumImages();

            for (int i = 0; i < numImages; ++i)
            {
                string src = sisAsset.GetImageFilePath(i);
                Assert.IsNotNull(src);
                string dest = Path.Combine(destFolder, Path.GetFileName(src));
                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, 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
            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;
            }
            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);
        }
예제 #9
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)";
        }