예제 #1
0
        public static void AddToMenu(GenericMenu menu, WindowState state)
        {
            var tracks = SelectionManager.SelectedTracks().ToArray();

            if (tracks.Length == 0)
            {
                return;
            }

            actions.ForEach(action =>
            {
                var subMenuPath  = string.Empty;
                var categoryAttr = GetCategoryAttribute(action);

                if (categoryAttr != null)
                {
                    subMenuPath = categoryAttr.Category;
                    if (!subMenuPath.EndsWith("/"))
                    {
                        subMenuPath += "/";
                    }
                }

                string displayName   = GetDisplayName(action);
                string menuItemName  = subMenuPath + displayName;
                var separator        = GetSeparator(action);
                var canBeAddedToMenu = !TypeUtility.IsHiddenInMenu(action.GetType());

                if (canBeAddedToMenu)
                {
                    Vector2?currentMousePosition = null;
                    if (Event.current != null)
                    {
                        currentMousePosition = Event.current.mousePosition;
                    }

                    action.mousePosition = currentMousePosition;
                    var displayState     = action.GetDisplayState(state, tracks);
                    action.mousePosition = null;

                    if (displayState == MenuActionDisplayState.Visible)
                    {
                        menu.AddItem(new GUIContent(menuItemName), action.IsChecked(state, tracks), f =>
                        {
                            action.Execute(state, tracks);
                        }, action);
                    }

                    if (displayState == MenuActionDisplayState.Disabled)
                    {
                        menu.AddDisabledItem(new GUIContent(menuItemName), action.IsChecked(state, tracks));
                    }

                    if (displayState != MenuActionDisplayState.Hidden && separator != null && separator.after)
                    {
                        menu.AddSeparator(subMenuPath);
                    }
                }
            });
        }
        public static void AddToMenu(GenericMenu menu, WindowState state)
        {
            var items = SelectionManager.SelectedItemOfType <T>().ToArray();

            if (items.Length < 1)
            {
                return;
            }

            var actionsToAdd = actions.Where(i => !TypeUtility.IsHiddenInMenu(i.GetType())).ToList();

            if (actionsToAdd.Any())
            {
                menu.AddSeparator(string.Empty);
            }
            else
            {
                return;
            }

            actionsToAdd.ForEach(action =>
            {
                action.AddSelfToMenu(menu, state, items);
            });
        }
예제 #3
0
        public static List <object> GetMenuEntries(WindowState state, Vector2 mousePos)
        {
            var ret = new List <object>();

            actions.ForEach(action =>
            {
                string subMenuPath;
                var categoryAttr = GetCategoryAttribute(action);

                if (categoryAttr == null)
                {
                    subMenuPath = string.Empty;
                }
                else
                {
                    subMenuPath = categoryAttr.Category;
                    if (!subMenuPath.EndsWith("/"))
                    {
                        subMenuPath += "/";
                    }
                }

                var displayName = GetDisplayName(action);
                action.SetMousePosition(mousePos);
                // The display state could be dependent on mouse position
                var displayState = action.GetDisplayState(state);
                action.ClearMousePosition();
                var menuItemName     = subMenuPath + displayName;
                var separator        = GetSeparator(action);
                var canBeAddedToMenu = !TypeUtility.IsHiddenInMenu(action.GetType()) && displayState != MenuActionDisplayState.Hidden;

                if (canBeAddedToMenu)
                {
                    if (separator != null && separator.before)
                    {
                        ret.Add(subMenuPath);
                    }

                    if (displayState == MenuActionDisplayState.Visible)
                    {
                        var entry = new MenuEntryPair(new GUIContent(menuItemName), action);
                        ret.Add(entry);
                    }

                    if (displayState == MenuActionDisplayState.Disabled)
                    {
                        ret.Add(new GUIContent(menuItemName));
                    }

                    if (separator != null && separator.after)
                    {
                        ret.Add(subMenuPath);
                    }
                }
            });

            return(ret);
        }
        public static void AddToMenu(GenericMenu menu, WindowState state)
        {
            var items = SelectionManager.SelectedItemOfType <T>().ToArray();

            if (items.Length < 1 || !actions.Any())
            {
                return;
            }

            menu.AddSeparator("");
            actions.ForEach(action =>
            {
                if (!TypeUtility.IsHiddenInMenu(action.GetType()))
                {
                    action.AddSelfToMenu(menu, state, items);
                }
            });
        }
예제 #5
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);
            }
        }
예제 #6
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
                }
                    );
            }
        }