Пример #1
0
        static void AddTrackMenuCommands(GenericMenu newTrackMenu, TrackAsset parentTrack, TimelineGroupGUI parentGroup, WindowState state)
        {
            // Add Group or SubGroup
            var title = parentTrack == null?L10n.Tr("Track Group") : L10n.Tr("Track Sub-Group");

            var disabled = (parentTrack != null && parentTrack.lockedInHierarchy) || state.editSequence.isReadOnly;

            GenericMenu.MenuFunction command = () =>
            {
                SelectionManager.Clear();
                TimelineHelpers.CreateTrack <GroupTrack>(parentTrack, title);
            };

            AddCommandToMenu(newTrackMenu, title, command, !disabled);
            newTrackMenu.AddSeparator("");

            var allTypes    = TypeUtility.AllTrackTypes().Where(x => x != typeof(GroupTrack) && !TypeUtility.IsHiddenInMenu(x)).ToList();
            var builtIn     = allTypes.Where(x => x.Assembly.Equals(typeof(TimelineAsset).Assembly)).OrderBy(i => i.FullName).ToList();
            var customTypes = allTypes.Except(builtIn).ToList();

            foreach (var t in builtIn)
            {
                AddNewTrackMenuCommand(newTrackMenu, parentTrack, parentGroup, t, state);
            }

            if (builtIn.Any() && customTypes.Any())
            {
                newTrackMenu.AddSeparator("");
            }

            foreach (var t in customTypes)
            {
                AddNewTrackMenuCommand(newTrackMenu, parentTrack, parentGroup, t, state);
            }
        }
Пример #2
0
        public static void AddMenuItems(GenericMenu menu, GroupTrack track)
        {
            var state = TimelineWindow.instance.state;

            var trackTypes = TypeUtility.AllTrackTypes();

            foreach (var t in trackTypes)
            {
                if (t == typeof(GroupTrack))
                {
                    continue;
                }

                GenericMenu.MenuFunction2 menuFunc = trackType =>
                {
                    track.SetCollapsed(false);

                    state.GetWindow().AddTrack((System.Type)trackType, track);
                    var uiTrack = FindGUITrack(track);
                    if (uiTrack != null)
                    {
                        TimelineWindow.instance.treeView.data.SetExpanded(uiTrack, true);
                    }
                };

                object lastUserData = t;
                var    category     = TimelineHelpers.GetTrackCategoryName(t);
                if (!string.IsNullOrEmpty(category))
                {
                    category += "/";
                }

                var content = EditorGUIUtility.TrTextContent("Add " + category + TimelineHelpers.GetTrackMenuName(t));
                if (track.lockedInHierarchy)
                {
                    menu.AddDisabledItem(content, false);
                }
                else
                {
                    menu.AddItem(content, false, menuFunc, lastUserData);
                }
            }
        }
        public static void AddMenuItems(GenericMenu menu, GroupTrack track)
        {
            var state = TimelineWindow.instance.state;

            var trackTypes = TypeUtility.AllTrackTypes();

            foreach (var t in trackTypes)
            {
                if (t == typeof(GroupTrack))
                {
                    continue;
                }

                GenericMenu.MenuFunction2 menuFunc = trackType =>
                {
                    TimelineHelpers.CreateTrack((System.Type)trackType, track);
                };

                object lastUserData = t;
                var    category     = TimelineHelpers.GetTrackCategoryName(t);
                if (!string.IsNullOrEmpty(category))
                {
                    category += "/";
                }

                var content = EditorGUIUtility.TrTextContent("Add " + category + TimelineHelpers.GetTrackMenuName(t));
                if (track.lockedInHierarchy || state.editSequence.isReadOnly)
                {
                    menu.AddDisabledItem(content, false);
                }
                else
                {
                    menu.AddItem(content, false, menuFunc, lastUserData);
                }
            }
        }
Пример #4
0
        public static void BuildNewTracksContextMenu(List <MenuActionItem> menuItems, ICollection <TrackAsset> parentTracks, WindowState state, string format = null)
        {
            if (parentTracks == null)
            {
                parentTracks = new TrackAsset[0];
            }

            if (string.IsNullOrEmpty(format))
            {
                format = "{0}";
            }

            // Add Group or SubGroup
            var title     = string.Format(format, parentTracks.Any(t => t != null) ? Styles.trackSubGroup : Styles.trackGroup);
            var menuState = ActionValidity.Valid;

            if (state.editSequence.isReadOnly)
            {
                menuState = ActionValidity.Invalid;
            }
            if (parentTracks.Any() && parentTracks.Any(t => t != null && t.lockedInHierarchy))
            {
                menuState = ActionValidity.Invalid;
            }

            GenericMenu.MenuFunction command = () =>
            {
                SelectionManager.Clear();
                if (parentTracks.Count == 0)
                {
                    Selection.Add(TimelineHelpers.CreateTrack <GroupTrack>(null, title));
                }

                foreach (var parentTrack in parentTracks)
                {
                    Selection.Add(TimelineHelpers.CreateTrack <GroupTrack>(parentTrack, title));
                }

                TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
            };

            menuItems.Add(
                new MenuActionItem()
            {
                category       = string.Empty,
                entryName      = title,
                isActiveInMode = true,
                priority       = MenuPriority.AddItem.addGroup,
                state          = menuState,
                isChecked      = false,
                callback       = command
            }
                );


            var allTypes = TypeUtility.AllTrackTypes().Where(x => x != typeof(GroupTrack) && !TypeUtility.IsHiddenInMenu(x)).ToList();

            int builtInPriority = MenuPriority.AddItem.addTrack;
            int customPriority  = MenuPriority.AddItem.addCustomTrack;

            foreach (var trackType in allTypes)
            {
                var trackItemType = trackType;

                command = () =>
                {
                    SelectionManager.Clear();

                    if (parentTracks.Count == 0)
                    {
                        SelectionManager.Add(TimelineHelpers.CreateTrack((Type)trackItemType, null));
                    }

                    foreach (var parentTrack in parentTracks)
                    {
                        SelectionManager.Add(TimelineHelpers.CreateTrack((Type)trackItemType, parentTrack));
                    }
                };

                menuItems.Add(
                    new MenuActionItem()
                {
                    category       = TimelineHelpers.GetTrackCategoryName(trackType),
                    entryName      = string.Format(format, TimelineHelpers.GetTrackMenuName(trackItemType)),
                    isActiveInMode = true,
                    priority       = TypeUtility.IsBuiltIn(trackType) ? builtInPriority++ : customPriority++,
                    state          = menuState,
                    callback       = command
                }
                    );
            }
        }