public static ToolboxTreeViewItem GetSeparator(int _height = 10)
        {
            ToolboxTreeViewItem separator = GetItem((rect, item) => { GUI.Box(rect, "", ToolboxTreeViewItem.SeparatorStyle); });

            separator.Height = _height;
            return(separator);
        }
        public static ToolboxTreeViewItem GetItem(string path, Action <Rect, ToolboxTreeViewItem> _drawer)
        {
            ToolboxTreeViewItem toolBoxItem = new ToolboxTreeViewItem();

            toolBoxItem.drawer = _drawer;
            toolBoxItem.depth  = 0;
            toolBoxItem.Path   = path;
            return(toolBoxItem);
        }
Exemple #3
0
        protected override TreeViewItem BuildRoot()
        {
            TreeViewItem root = new TreeViewItem(-1, -1, "Root");

            root.children = new List <TreeViewItem>();

            int id = 0;

            foreach (var item in items)
            {
                if (string.IsNullOrEmpty(item.Path))
                {
                    item.id = id;
                    id++;
                    item.depth = 0;
                    root.AddChild(item);
                }
                else
                {
                    string[]     path         = item.Path.Split('/');
                    TreeViewItem currentLayer = root;
                    for (int i = 0; i < path.Length; i++)
                    {
                        TreeViewItem child = currentLayer.children.Find(l => l.displayName == path[i]);
                        if (child == null)
                        {
                            child          = new ToolboxTreeViewItem(id, i, path[i]);
                            child.children = new List <TreeViewItem>();
                            id++;
                            currentLayer.AddChild(child);
                        }
                        currentLayer = child;
                    }
                    item.depth = path.Length;
                    item.id    = id;
                    id++;
                    currentLayer.AddChild(item);
                }
            }

            SetupDepthsFromParentsAndChildren(root);
            return(root);
        }
Exemple #4
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);
        }