示例#1
0
//----------------------------------------------------------------------------------------------------------------------
        //Called when a clip is changed by the Editor. (TrimStart, TrimEnd, etc)
        public override void OnClipChanged(TimelineClip clip)
        {
            base.OnClipChanged(clip);

            StreamingImageSequencePlayableAsset sisAsset = clip.asset as StreamingImageSequencePlayableAsset;

            if (null == sisAsset)
            {
                Debug.LogError("[SIS] Clip Internal Error: Invalid Asset");
                return;
            }

            EditorCurveBinding curveBinding = StreamingImageSequencePlayableAsset.GetTimeCurveBinding();
            AnimationCurve     curve        = ExtendedClipEditorUtility.ValidateTimelineClipCurve(clip, curveBinding);

            //Always set the curve to clipData
            ExtendedClipEditorUtility.SetClipDataCurve <SISClipData>(sisAsset, curve);
        }
示例#2
0
//----------------------------------------------------------------------------------------------------------------------

    /// <summary>
    /// StreamingImageSequencePlayableAsset GUI Drawing
    /// </summary>
    public override void OnInspectorGUI() {
        if (null == m_asset)
            return;
        

        using (new EditorGUILayout.VerticalScope (GUI.skin.box))  {

            m_resolutionFoldout = EditorGUILayout.Foldout(m_resolutionFoldout, "Resolution");
            if (m_resolutionFoldout) {
                ImageDimensionInt res = m_asset.GetResolution();
                EditorGUILayout.LabelField("Width",  $"{res.Width } px");
                EditorGUILayout.LabelField("Height",  $"{res.Height } px");
            }
            GUILayout.Space(4f);
        }
        
        GUILayout.Space(4f);

        using (new EditorGUILayout.VerticalScope(GUI.skin.box))
        {
            GUILayout.Label("Folder", "BoldLabel");
            GUILayout.Space(4f);
            DrawFolderGUI();
        }
        GUILayout.Space(4f);

        using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
            int numImages = m_asset.GetNumImages();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Images: " + numImages, "BoldLabel");            
            if (GUILayout.Button("Reload", GUILayout.Width(50))) {
                m_asset.Reload();
            }
            EditorGUILayout.EndHorizontal();
            
            using (new EditorGUI.DisabledScope(0 == numImages)) {
                if (0 == numImages)
                    EditorGUILayout.IntField("FPS", 0);
                else {
                    TimelineClip clip = m_asset.GetBoundClipData()?.GetOwner();
                    //There is no assigned clip if the playableAsset is not loaded in TimelineWindow
                    if (null != clip) {                         
                                                
                        EditorGUIDrawerUtility.DrawUndoableGUI(clip.GetParentTrack(), "Change FPS", 
                            /*guiFunc=*/ ()=> {
                                float fps = SISPlayableAssetUtility.CalculateFPS(m_asset);
                                float val = EditorGUILayout.FloatField("FPS", fps); 
                                return Mathf.Max(0.1f, val);
                            }, 
                            /*updateFunc=*/ (float newFPS) => {
                                SISPlayableAssetUtility.SetFPS(m_asset, newFPS);                                
                            }
                        );
                    }                    
                }
            }
            
            GUILayout.Space(4f);
            m_imageListFoldout = EditorGUILayout.Foldout(m_imageListFoldout, "Images");
            if (m_imageListFoldout) {
                DoImageGUI();
            }
        }

        if (null == TimelineEditor.selectedClip) 
            return;
        
        GUILayout.Space(15);
        //Frame markers
        if (TimelineEditor.selectedClip.asset == m_asset) {
            using (new EditorGUILayout.HorizontalScope()) {
                InspectorUtility.DrawFrameMarkersGUI(m_asset);
                if (GUILayout.Button("Reset", GUILayout.Width(50f))) {
                    m_asset.ResetPlayableFrames();
                }
            }
        }
        GUILayout.Space(15);
        
        using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
            EditorGUILayout.LabelField("Background Colors");
            ++EditorGUI.indentLevel;
            
            EditorGUIDrawerUtility.DrawUndoableGUI(m_asset, "Change BG Color", 
                /*guiFunc=*/ ()=> EditorGUILayout.ColorField("In Timeline Window", m_asset.GetTimelineBGColor()), 
                /*updateFunc=*/ (Color newColor) => {                               
                    m_asset.SetTimelineBGColor(newColor);                                
                }
            );
            
            --EditorGUI.indentLevel;
            GUILayout.Space(15);
        }

        
        if (GUILayout.Button("Reset Curve (Not Undoable)")) {
            //AnimationUtility.SetEditorCurve(), which is called below, doesn't seem to be undoable
            EditorCurveBinding curveBinding = StreamingImageSequencePlayableAsset.GetTimeCurveBinding();                 
            ExtendedClipEditorUtility.ResetClipDataCurve(m_asset, curveBinding);
        }
    }
示例#3
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)";
        }
示例#4
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);
        }
示例#5
0
//---------------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Import a timeline file exported from DCC tools into the scene in the Timeline object
        /// </summary>
        /// <param name="jsTimelinePath">The path of the file</param>
        /// <param name="destFolder">The dest folder of the imported files</param>
        public static void ImportTimeline(string jsTimelinePath, string destFolder = "")
        {
            // prepare asset name, paths, etc
            string assetName      = Path.GetFileNameWithoutExtension(jsTimelinePath);
            string timelineFolder = Path.GetDirectoryName(jsTimelinePath);

            if (string.IsNullOrEmpty(timelineFolder))
            {
                Debug.LogError("Can't get directory name for: " + jsTimelinePath);
                return;
            }
            timelineFolder = Path.Combine(timelineFolder, destFolder, assetName).Replace("\\", "/");

            //Check if we are exporting from external asset
            if (!timelineFolder.StartsWith("Assets/"))
            {
                timelineFolder = Path.Combine("Assets", destFolder, assetName);
            }

            Directory.CreateDirectory(timelineFolder);
            string        strJson     = File.ReadAllText(jsTimelinePath);
            TimelineParam container   = JsonUtility.FromJson <TimelineParam>(strJson);
            string        assetFolder = container.assetFolder;

            if (string.IsNullOrEmpty(assetFolder))
            {
                assetFolder = Path.GetDirectoryName(jsTimelinePath);
            }

            //delete existing objects in the scene that is pointing to the Director
            string           timelinePath = Path.Combine(timelineFolder, assetName + "_Timeline.playable").Replace("\\", "/");
            PlayableDirector director     = RemovePlayableFromDirectorsInScene(timelinePath);

            if (null == director)
            {
                GameObject directorGo = new GameObject(assetName);
                director = directorGo.AddComponent <PlayableDirector>();
            }

            //Create timeline asset
            TimelineAsset asset = ScriptableObject.CreateInstance <TimelineAsset>();

            AssetEditorUtility.OverwriteAsset(asset, timelinePath);

            director.playableAsset = asset;
            string strHome = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

            int numTracks = container.Tracks.Length;

            for (int index = numTracks - 1; index >= 0; index--)
            {
                var    track          = container.Tracks[index];
                string strFootagePath = track.Footage;
                // remove '~' if necessary
                if (strFootagePath.StartsWith("~"))
                {
                    strFootagePath = strHome + strFootagePath.Substring(1);
                }
                if (!Path.IsPathRooted(strFootagePath))
                {
                    strFootagePath = Path.Combine(assetFolder, strFootagePath);
                }
                string        strFootageName = Path.GetFileNameWithoutExtension(strFootagePath);
                string        strJsonFootage = File.ReadAllText(strFootagePath);
                AEFootageInfo footageInfo    = JsonUtility.FromJson <AEFootageInfo>(strJsonFootage);

                int numImages = footageInfo.Pictures.Count;
                if (numImages > 0)
                {
                    List <string> originalImagePaths = new List <string>(footageInfo.Pictures);

                    for (int xx = 0; xx < numImages; ++xx)
                    {
                        string fileName = footageInfo.Pictures[xx];
                        // replace '~' with the path to home (for Linux environment
                        if (fileName.StartsWith("~"))
                        {
                            fileName = strHome + fileName.Substring(1);
                        }
                        footageInfo.Pictures[xx] = Path.GetFileName(fileName);
                    }

                    string destFootageFolder = Application.streamingAssetsPath;
                    destFootageFolder = Path.Combine(destFootageFolder, strFootageName).Replace("\\", "/");
                    Directory.CreateDirectory(destFootageFolder); //make sure the directory exists
                    footageInfo.Folder = AssetUtility.NormalizeAssetPath(destFootageFolder);

                    for (int i = 0; i < numImages; ++i)
                    {
                        string destFilePath = Path.Combine(destFootageFolder, footageInfo.Pictures[i]);
                        if (File.Exists(destFilePath))
                        {
                            File.Delete(destFilePath);
                        }

                        string srcFilePath = Path.GetFullPath(Path.Combine(assetFolder, originalImagePaths[i])).Replace("\\", "/");
                        FileUtil.CopyFileOrDirectory(srcFilePath, destFilePath);
                    }
                }

                //Convert to WatchedFileInfo
                List <WatchedFileInfo> imageFiles = WatchedFileInfo.CreateList(footageInfo.Folder, footageInfo.Pictures);

                StreamingImageSequencePlayableAsset sisAsset = ScriptableObject.CreateInstance <StreamingImageSequencePlayableAsset>();
                sisAsset.InitFolderInEditor(footageInfo.Folder, imageFiles, footageInfo.Resolution);

                string playableAssetPath = Path.Combine(timelineFolder, strFootageName + "_StreamingImageSequence.playable");
                AssetEditorUtility.OverwriteAsset(sisAsset, playableAssetPath);

                StreamingImageSequenceTrack movieTrack = asset.CreateTrack <StreamingImageSequenceTrack>(null, strFootageName);
                TimelineClip clip = movieTrack.CreateDefaultClip();
                clip.asset    = sisAsset;
                clip.start    = track.Start;
                clip.duration = track.Duration;
                clip.CreateCurves("Curves: " + clip.displayName);

                SISClipData sisData = new SISClipData(clip);
                sisAsset.BindClipData(sisData);
                ExtendedClipEditorUtility.ResetClipDataCurve(sisAsset, StreamingImageSequencePlayableAsset.GetTimeCurveBinding());


                if (Object.FindObjectOfType(typeof(UnityEngine.EventSystems.EventSystem)) == null)
                {
                    var es = new GameObject();
                    es.AddComponent <UnityEngine.EventSystems.EventSystem>();
                    es.AddComponent <UnityEngine.EventSystems.StandaloneInputModule>();
                    es.name = "EventSystem";
                }
                GameObject canvasObj = null;
                Canvas     canvas    = Object.FindObjectOfType(typeof(Canvas)) as Canvas;
                if (canvas != null)
                {
                    canvasObj = canvas.gameObject;
                }
                else
                {
                    canvasObj = UIUtility.CreateCanvas().gameObject;
                }

                Transform directorT = director.gameObject.transform;
                directorT.SetParent(canvasObj.transform);
                directorT.localPosition = new Vector3(0.0f, 0.0f, 0.0f);

                GameObject imageGo = null;
                Transform  imageT  = directorT.Find(strFootageName);
                if (null == imageT)
                {
                    imageGo = new GameObject(strFootageName);
                    imageT  = imageGo.transform;
                }
                else
                {
                    imageGo = imageT.gameObject;
                }

                Image image = imageGo.GetOrAddComponent <Image>();
                StreamingImageSequenceRenderer renderer = imageGo.GetOrAddComponent <StreamingImageSequenceRenderer>();

                RectTransform rectTransform = imageGo.GetComponent <RectTransform>();
                rectTransform.SetParent(directorT);
                rectTransform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
                rectTransform.sizeDelta     = new Vector2(footageInfo.Resolution.Width,
                                                          footageInfo.Resolution.Height);

                director.SetGenericBinding(movieTrack, renderer);
                EditorUtility.SetDirty(director);
            }

            //cause crash if this is called inside of OnImportAsset()
            UnityEditor.EditorApplication.delayCall += () => {
                AssetDatabase.Refresh();
                if (null != director)
                {
                    Selection.activeGameObject = director.gameObject;
                }
            };
        }