Пример #1
0
        private void SaveSOAs(TimelineLiteAsset data)
        {
            string path = EditorUtility.SaveFilePanelInProject("Save", data.name + "_SO", "asset", "Null");

            if (!string.IsNullOrEmpty(path))
            {
                data.previousPath = path.Substring(0, path.LastIndexOf("."));
                EditorUtility.SetDirty(data);

                TimelineLiteSO so = AssetDatabase.LoadAssetAtPath <TimelineLiteSO>(data.previousPath + ".asset");
                if (so != null)
                {
                    so.TimelineLiteObjectData = data.Extract();
                    EditorUtility.SetDirty(so);
                }
                else
                {
                    so = ScriptableObject.CreateInstance(data.TargetSOType) as TimelineLiteSO;
                    so.TimelineLiteObjectData = data.Extract();
                    AssetDatabase.CreateAsset(so, data.previousPath + ".asset");
                }

                AssetDatabase.SaveAssets();
            }
        }
Пример #2
0
        public TrackAsset CreateTrack(Type _trackAssetType, string _path)
        {
#if UNITY_2018_1_OR_NEWER
            TimelineLiteAsset timelineLiteAsset = TimelineEditor.inspectedAsset as TimelineLiteAsset;
#else
            TimelineLiteAsset timelineLiteAsset = TimelineEditor.timelineAsset as TimelineLiteAsset;
#endif
            TrackAsset trackAsset = null;
            if (timelineLiteAsset != null)
            {
                string name = _path.Substring(_path.LastIndexOf("/") + 1);

                if (Selection.activeObject is UnityEngine.Timeline.GroupTrack)
                {
                    trackAsset = timelineLiteAsset.CreateTrack(_trackAssetType, Selection.activeObject as UnityEngine.Timeline.GroupTrack, name);
                }
                else
                {
                    trackAsset = timelineLiteAsset.CreateTrack(_trackAssetType, null, name);
                }
#if UNITY_2018_1_OR_NEWER
                TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
#endif
            }
            return(trackAsset);
        }
Пример #3
0
        protected override void DoubleClickedItem(int id)
        {
            TimelineLiteAssetTreeViewItem item = FindItem(id, rootItem) as TimelineLiteAssetTreeViewItem;

            if (item == null)
            {
                return;
            }
            TimelineLiteAsset data = item.UserData;

            Selection.activeObject = data;
        }
Пример #4
0
        protected override void RenameEnded(RenameEndedArgs args)
        {
            TimelineLiteAssetTreeViewItem item = FindItem(args.itemID, rootItem) as TimelineLiteAssetTreeViewItem;

            if (item == null)
            {
                return;
            }
            TimelineLiteAsset data = item.UserData;

            AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(data), args.newName);
            item.displayName = data.name;
        }
Пример #5
0
        private void SaveSO(TimelineLiteAsset data)
        {
            TimelineLiteSO so = AssetDatabase.LoadAssetAtPath <TimelineLiteSO>(data.previousPath + ".asset");

            if (so == null)
            {
                SaveSOAs(data);
            }
            else
            {
                so.TimelineLiteObjectData = data.Extract();
                EditorUtility.SetDirty(so);
                AssetDatabase.SaveAssets();
            }
        }
Пример #6
0
        protected virtual TimelineLitesTreeView BuildAssetsListTreeView()
        {
            TimelineLitesTreeView projecListTreeView = new TimelineLitesTreeView(TreeViewState, searchText, this);

            // 查找所有使用此类的ScriptableObjects
            string[] guids = AssetDatabase.FindAssets("t:" + TimelineLiteAssetType);

            for (int i = 0; i < guids.Length; i++)
            {
                string                        assetPath         = AssetDatabase.GUIDToAssetPath(guids[i]);
                TimelineLiteAsset             asset             = AssetDatabase.LoadAssetAtPath <TimelineLiteAsset>(assetPath);
                TimelineLiteAssetTreeViewItem assetTreeViewItem = new TimelineLiteAssetTreeViewItem(asset);
                projecListTreeView.AddItem(asset.GetType().Name, assetTreeViewItem);
            }
            return(projecListTreeView);
        }
        protected virtual void OnSceneGUI(SceneView _sceneView)
        {
            if (Playable == null)
            {
                return;
            }

#if UNITY_2018_1_OR_NEWER
            TimelineLiteAsset inspectedAsset = TimelineEditor.inspectedAsset as TimelineLiteAsset;
#else
            TimelineLiteAsset inspectedAsset = UnityEditor.Timeline.TimelineEditor.timelineAsset as TimelineLiteAsset;
#endif
            if (inspectedAsset == null)
            {
                return;
            }

            // 始终调用
            foreach (var trackAsset in inspectedAsset.GetOutputTracks())
            {
                TLBasicTrackAsset basicTrackAsset = trackAsset as TLBasicTrackAsset;
                if (basicTrackAsset == null)
                {
                    continue;
                }
                foreach (var timelineClip in basicTrackAsset.GetClips())
                {
                    ISceneGUI asset = timelineClip.asset as ISceneGUI;
                    if (asset != null)
                    {
                        asset.SceneGUI(Playable, timelineClip, indicatorFrame);
                    }
                }
            }

#if UNITY_2019_1_OR_NEWER
            // 只有选中后调用
            foreach (var timelineClip in TimelineEditor.selectedClips)
            {
                ISceneGUI asset = timelineClip.asset as ISceneGUI;
                if (asset != null)
                {
                    asset.SceneGUISelected(Playable, timelineClip, indicatorFrame);
                }
            }
#endif
        }
Пример #8
0
        protected override void SingleClickedItem(int id)
        {
            base.SingleClickedItem(id);
            TimelineLiteAssetTreeViewItem item = FindItem(id, rootItem) as TimelineLiteAssetTreeViewItem;

            if (item == null)
            {
                return;
            }
            TimelineLiteAsset data = item.UserData;

            if (data != null && UnityEditor.Timeline.TimelineEditor.inspectedAsset != data)
            {
                AssetDatabase.OpenAsset(data);
                Window.Focus();
            }
        }
Пример #9
0
        protected override void SelectionChanged(IList <int> selectedIds)
        {
            base.SelectionChanged(selectedIds);
            if (selectedIds.Count <= 0)
            {
                return;
            }
            TimelineLiteAssetTreeViewItem item = FindItem(selectedIds[0], rootItem) as TimelineLiteAssetTreeViewItem;

            if (item == null)
            {
                return;
            }
            TimelineLiteAsset data = item.UserData;

            if (data != null && UnityEditor.Timeline.TimelineEditor.timelineAsset != data)
            {
                AssetDatabase.OpenAsset(data);
                Window.Focus();
            }
        }
Пример #10
0
        public virtual void BuildAssetContextMenu(IList <int> selection, GenericMenu genericMenu)
        {
            if (selection.Count > 0)
            {
                if (selection.Count == 1)
                {
                    TimelineLiteAssetTreeViewItem item = projecListTreeView.FindItem(selection[0]) as TimelineLiteAssetTreeViewItem;
                    if (item != null)
                    {
                        TimelineLiteAsset data = item.UserData;
                        BuildSingleAssetItemMenu(data, genericMenu);
                    }
                }
                else
                {
                    genericMenu.AddItem(new GUIContent("批量另存为SO"), false, () => SaveSOSelectionAs(selection));
                }

                genericMenu.AddItem(new GUIContent("删除所选"), false, () => DeleteSelection(selection));
            }
        }
Пример #11
0
        protected override void RowGUI(RowGUIArgs args)
        {
            TimelineLiteAssetTreeViewItem assetItem = args.item as TimelineLiteAssetTreeViewItem;

            if (assetItem == null)
            {
                base.RowGUI(args);
                return;
            }
            if (args.isRenaming)
            {
                return;
            }
            TimelineLiteAsset asset = assetItem.UserData;

            Rect rect = args.rowRect;

            rect.x     = 20;
            rect.width = args.rowRect.width - 20;
            GUI.Label(rect, asset.name);

            rect.x     = args.rowRect.width - 25;
            rect.width = 25;
            if (!EditorApplication.isPlaying || TimelineLiteEditorWindow.Playable == null)
            {
                EditorGUI.BeginDisabledGroup(true);
            }

            if (GUI.Button(rect, playIcon, (GUIStyle)"toolbarbutton"))
            {
                TimelineLiteEditorWindow.Playable.Play(
                    Activator.CreateInstance(asset.TargetObjectType, asset.Extract()) as ITimelineLiteObject);
                Repaint();
            }

            if (!EditorApplication.isPlaying || TimelineLiteEditorWindow.Playable == null)
            {
                EditorGUI.EndDisabledGroup();
            }
        }
        protected virtual void OnDrawGizmos()
        {
#if UNITY_2018_1_OR_NEWER
            TimelineLiteAsset inspectedAsset = TimelineEditor.inspectedAsset as TimelineLiteAsset;
#else
            TimelineLiteAsset inspectedAsset = UnityEditor.Timeline.TimelineEditor.timelineAsset as TimelineLiteAsset;
#endif
            if (inspectedAsset == null)
            {
                return;
            }

            // 始终调用
            foreach (var trackAsset in inspectedAsset.GetOutputTracks())
            {
                TLBasicTrackAsset basicTrackAsset = trackAsset as TLBasicTrackAsset;
                if (basicTrackAsset == null)
                {
                    continue;
                }
                foreach (var timelineClip in trackAsset.GetClips())
                {
                    IDrawGizmos asset = timelineClip.asset as IDrawGizmos;
                    if (asset != null)
                    {
                        asset.DrawGizmos_Lite(Playable, timelineClip, IndicatorFrame);
                    }
                }
            }

            foreach (var timelineClip in TimelineEditor.selectedClips)
            {
                IDrawGizmos asset = timelineClip.asset as IDrawGizmos;
                if (asset != null)
                {
                    asset.DrawGizmosSelected_Lite(Playable, timelineClip, IndicatorFrame);
                }
            }
        }
Пример #13
0
        /// <summary> SO </summary>
        private void SaveSOSelectionAs(IList <int> _selection)
        {
            string path = EditorUtility.OpenFolderPanel("批量另存为", Application.dataPath, "");

            if (!string.IsNullOrEmpty(path))
            {
                path = path.Replace(Application.dataPath, "Assets");
                foreach (var id in _selection)
                {
                    TimelineLiteAssetTreeViewItem item = projecListTreeView.FindItem(id) as TimelineLiteAssetTreeViewItem;
                    if (item == null)
                    {
                        continue;
                    }
                    TimelineLiteAsset data = item.UserData;

                    data.previousPath = path + "/" + data.name + "_SO";
                    EditorUtility.SetDirty(data);

                    TimelineLiteSO so = AssetDatabase.LoadAssetAtPath <TimelineLiteSO>(data.previousPath + ".asset");
                    if (so != null)
                    {
                        so.TimelineLiteObjectData = data.Extract();
                        EditorUtility.SetDirty(so);
                    }
                    else
                    {
                        so = ScriptableObject.CreateInstance(data.TargetSOType) as TimelineLiteSO;
                        so.TimelineLiteObjectData = data.Extract();
                        AssetDatabase.CreateAsset(so, data.previousPath + ".asset");
                    }
                }

                AssetDatabase.SaveAssets();
            }
        }
Пример #14
0
        protected virtual void BuildToolboxTreeView(ToolboxTreeView _treeView)
        {
            _treeView.AddItem(ToolboxTreeViewItem.GetSeparator(2));

            // 打开脚本,ping和选中保存按钮
            ToolboxTreeViewItem helpControl = ToolboxTreeViewItem.GetItem((rect, item) =>
            {
#if UNITY_2018_1_OR_NEWER
                TimelineLiteAsset timelineLiteAsset = TimelineEditor.inspectedAsset as TimelineLiteAsset;
#else
                TimelineLiteAsset timelineLiteAsset = TimelineEditor.timelineAsset as TimelineLiteAsset;
#endif
                EditorGUI.BeginDisabledGroup(timelineLiteAsset == null);
                rect.width = 30;
                if (GUI.Button(rect, csIcon))
                {
                    AssetDatabase.OpenAsset(MonoScript.FromScriptableObject(timelineLiteAsset));
                }
                rect.x += rect.width;

                if (GUI.Button(rect, pingIcon))
                {
                    Type type           = Utility_Reflection.GetType("UnityEditor.ProjectBrowser", "UnityEditor");
                    EditorWindow window = GetWindow(type);
                    EditorGUIUtility.PingObject(timelineLiteAsset);
                }
                rect.x += rect.width;
                if (GUI.Button(rect, selectIcon))
                {
                    Selection.activeObject = timelineLiteAsset;
                }
                rect.x    += rect.width;
                rect.width = 50;
                if (GUI.Button(rect, "Save"))
                {
                    GenericMenu genericMenu = new GenericMenu();
                    BuildSingleAssetItemMenu(timelineLiteAsset, genericMenu);
                    genericMenu.ShowAsContext();
                }
                EditorGUI.EndDisabledGroup();
            });

            helpControl.Height = 30;
            _treeView.AddItem(helpControl);

            _treeView.AddItem(ToolboxTreeViewItem.GetSeparator(2));

            // 创建轨道按钮
            ToolboxTreeViewItem editorControl = ToolboxTreeViewItem.GetItem((rect, item) =>
            {
#if UNITY_2018_1_OR_NEWER
                TimelineLiteAsset timelineLiteAsset = TimelineEditor.inspectedAsset as TimelineLiteAsset;
#else
                TimelineLiteAsset timelineLiteAsset = TimelineEditor.timelineAsset as TimelineLiteAsset;
#endif

                rect.width = 30;
                EditorGUI.BeginDisabledGroup(timelineLiteAsset == null);
                if (GUI.Button(rect, createTrackIcon))
                {
                    trackTypeMenu.ShowAsContext();
                }
                EditorGUI.EndDisabledGroup();
            });

            editorControl.Height = 30;
            _treeView.AddItem(editorControl);

            // 播放进度控制条和播放按钮
            ToolboxTreeViewItem progressControl = ToolboxTreeViewItem.GetItem((rect, item) =>
            {
#if UNITY_2018_1_OR_NEWER
                TimelineLiteAsset timelineLiteAsset = TimelineEditor.inspectedAsset as TimelineLiteAsset;
#else
                TimelineLiteAsset timelineLiteAsset = TimelineEditor.timelineAsset as TimelineLiteAsset;
#endif
                GUI.Box(rect, "");
                rect.height = 25;

                bool hasPlayable           = Playable != null;
                bool hasTimeline           = hasPlayable && Playable.Timeline != null;
                bool disable               = !hasPlayable || !hasTimeline;
                bool inspectorTimelineLite = timelineLiteAsset != null;

                if (!EditorApplication.isPlaying)
                {
                    // 非播放状态下只用来调整指针
                    EditorGUI.BeginDisabledGroup(!inspectorTimelineLite);
                    int frameCount   = inspectorTimelineLite ? (int)timelineLiteAsset.GetFrameCount() : 0;
                    int currentFrame = Mathf.Clamp(inspectorTimelineLite ? indicatorFrame : 0, 0, frameCount);
                    IndicatorFrame   = TimelineLiteUtility.ConvertToFrameIndex(EditorGUIExtension.ProgressBar(rect, currentFrame, 0, frameCount, currentFrame + "/" + frameCount, true));
                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    // 播放状态下可用来调整动画进度
                    EditorGUI.BeginDisabledGroup(!hasPlayable || playable.PlayStatus == PlayStatus.Stopped);
                    int frameCount   = hasTimeline ? Playable.Timeline.FrameCount : 0;
                    int currentFrame = hasTimeline ? Playable.CurrentFrame : 0;
                    IndicatorFrame   = TimelineLiteUtility.ConvertToFrameIndex(EditorGUIExtension.ProgressBar(rect, currentFrame, 0, frameCount, currentFrame + "/" + frameCount, true));
                    if (indicatorFrame != currentFrame)
                    {
                        Playable.Pause();
                        Playable.SetFrame(indicatorFrame);
                    }
                    EditorGUI.EndDisabledGroup();
                }

                rect.y     += 30;
                rect.height = 15;
                rect.x      = 0;
                rect.width  = rect.width / 4;
                if (EditorApplication.isPlaying)
                {
                    // 上一帧按钮
                    EditorGUI.BeginDisabledGroup(!hasPlayable || playable.PlayStatus != PlayStatus.Pausing);
                    if (GUI.Button(rect, EditorGUIUtility.IconContent("Animation.PrevKey"), (GUIStyle)"MiniToolbarButton"))
                    {
                        playable.SetFrame(playable.CurrentFrame - 1);
                    }
                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    // 非播放状态下
                    EditorGUI.BeginDisabledGroup(!inspectorTimelineLite);
                    if (GUI.Button(rect, EditorGUIUtility.IconContent("Animation.PrevKey"), (GUIStyle)"MiniToolbarButton"))
                    {
                        int frameCount = inspectorTimelineLite ? (int)timelineLiteAsset.GetFrameCount() : 0;
                        indicatorFrame = Mathf.Clamp(--indicatorFrame, 0, frameCount);
                    }
                    EditorGUI.EndDisabledGroup();
                }

                EditorGUI.BeginDisabledGroup(!EditorApplication.isPlaying);
                rect.x += rect.width;
                if (hasPlayable)
                {
                    switch (playable.PlayStatus)
                    {
                    case PlayStatus.Playing:
                        if (GUI.Button(rect, EditorGUIUtility.IconContent("PauseButton"), (GUIStyle)"MiniToolbarButton"))
                        {
                            playable.Pause();
                        }
                        break;

                    case PlayStatus.Pausing:
                        if (GUI.Button(rect, EditorGUIUtility.IconContent("PlayButton"), (GUIStyle)"MiniToolbarButton"))
                        {
                            playable.Resume();
                        }
                        break;

                    case PlayStatus.Stopped:
                        if (playable.Timeline != null)
                        {
                            if (GUI.Button(rect, EditorGUIUtility.IconContent("PlayButton"), (GUIStyle)"MiniToolbarButton"))
                            {
                                playable.Play();
                            }
                        }
                        else
                        {
                            EditorGUI.BeginDisabledGroup(!inspectorTimelineLite);
                            if (GUI.Button(rect, EditorGUIUtility.IconContent("PlayButton"), (GUIStyle)"MiniToolbarButton"))
                            {
                                TimelineLiteObjectData data            = timelineLiteAsset.Extract();
                                ITimelineLiteObject timelineLiteObject = Activator.CreateInstance(timelineLiteAsset.TargetObjectType, data) as ITimelineLiteObject;
                                Playable.Play(timelineLiteObject);
                            }
                            EditorGUI.EndDisabledGroup();
                        }
                        break;
                    }
                }
                else
                {
                    GUI.Button(rect, EditorGUIUtility.IconContent("PlayButton"), (GUIStyle)"MiniToolbarButton");
                }
                EditorGUI.EndDisabledGroup();

                // 下一帧按钮
                rect.x += rect.width;

                if (EditorApplication.isPlaying)
                {
                    EditorGUI.BeginDisabledGroup(!hasPlayable || playable.PlayStatus != PlayStatus.Pausing);
                    if (GUI.Button(rect, EditorGUIUtility.IconContent("Animation.NextKey"), (GUIStyle)"MiniToolbarButton"))
                    {
                        playable.SetFrame(playable.CurrentFrame + 1);
                    }
                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    EditorGUI.BeginDisabledGroup(!inspectorTimelineLite);
                    if (GUI.Button(rect, EditorGUIUtility.IconContent("Animation.NextKey"), (GUIStyle)"MiniToolbarButton"))
                    {
                        int currentFrame = inspectorTimelineLite ? indicatorFrame : 0;
                        int frameCount   = inspectorTimelineLite ? (int)timelineLiteAsset.GetFrameCount() : 0;
                        indicatorFrame   = Mathf.Clamp(++indicatorFrame, currentFrame, frameCount);
                    }
                    EditorGUI.EndDisabledGroup();
                }

                rect.x += rect.width;
                EditorGUI.BeginDisabledGroup(!hasPlayable || (playable.PlayStatus == PlayStatus.Stopped && playable.Timeline == null));
                if (GUI.Button(rect, EditorGUIUtility.IconContent("PreMatQuad"), (GUIStyle)"MiniToolbarButton"))
                {
                    playable.Play <ITimelineLiteObject>(null);
                }
                EditorGUI.EndDisabledGroup();
            });

            progressControl.Height = 50;
            _treeView.AddItem(progressControl);
        }
 public TimelineLiteAssetTreeViewItem(TimelineLiteAsset _userData)
 {
     userData = _userData;
 }
 public TimelineLiteAssetTreeViewItem(int id, int depth, TimelineLiteAsset _userData) : base(id, depth)
 {
     userData = _userData;
 }
 public TimelineLiteAssetTreeViewItem(int id, int depth, string displayName, TimelineLiteAsset _userData) : base(id, depth, displayName)
 {
     userData = _userData;
 }
        private void InspectorGUI()
        {
#if UNITY_2018_1_OR_NEWER
            TimelineLiteAsset currentTimelineLiteAsset = TimelineEditor.inspectedAsset as TimelineLiteAsset;
#else
            TimelineLiteAsset currentTimelineLiteAsset = TimelineEditor.timelineAsset as TimelineLiteAsset;
#endif
#if ODIN_INSPECTOR
            if (timelineLiteAsset != currentTimelineLiteAsset)
            {
                timelineLiteAsset = currentTimelineLiteAsset;
                if (timelineLiteAsset == null)
                {
                    propertyTree = null;
                }
                else
                {
                    propertyTree = Sirenix.OdinInspector.Editor.PropertyTree.Create(timelineLiteAsset);
                    propertyTree.DrawMonoScriptObjectField = true;
                }
            }
            else
            {
                if (propertyTree == null && timelineLiteAsset != null)
                {
                    propertyTree = Sirenix.OdinInspector.Editor.PropertyTree.Create(timelineLiteAsset);
                    propertyTree.DrawMonoScriptObjectField = true;
                }
            }
            if (propertyTree != null)
            {
#if ODIN_INSPECTOR_3
                propertyTree.BeginDraw(true);
                propertyTree.Draw();
                propertyTree.EndDraw();
#else
                Sirenix.OdinInspector.Editor.InspectorUtilities.BeginDrawPropertyTree(propertyTree, true);
                propertyTree.Draw();
                Sirenix.OdinInspector.Editor.InspectorUtilities.EndDrawPropertyTree(propertyTree);
#endif
            }
#else
            if (timelineLiteAsset != currentTimelineLiteAsset)
            {
                timelineLiteAsset = currentTimelineLiteAsset;
                if (timelineLiteAsset == null)
                {
                    serializedObject = null;
                }
                else
                {
                    serializedObject = new SerializedObject(timelineLiteAsset);
                }
            }
            else
            {
                if (serializedObject == null && timelineLiteAsset != null)
                {
                    serializedObject = new SerializedObject(timelineLiteAsset);
                }
            }

            if (serializedObject != null)
            {
                EditorGUI.BeginChangeCheck();
                SerializedProperty iterator = serializedObject.GetIterator();
                iterator.NextVisible(true);
                do
                {
                    EditorGUI.BeginDisabledGroup(iterator.name == "m_Script");
                    EditorGUILayout.PropertyField(iterator);
                    EditorGUI.EndDisabledGroup();
                } while (iterator.NextVisible(false));

                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
                serializedObject.Update();
            }
#endif
        }
Пример #19
0
 public virtual void BuildSingleAssetItemMenu(TimelineLiteAsset data, GenericMenu genericMenu)
 {
     genericMenu.AddItem(new GUIContent("保存SO"), false, () => SaveSO(data));
     genericMenu.AddItem(new GUIContent("另存为SO"), false, () => SaveSOAs(data));
 }