static void AddNewTrackMenuCommand(GenericMenu menu, TrackAsset parentTrack, TimelineGroupGUI parentGroup, Type type, WindowState state) { GenericMenu.MenuFunction2 lastMethod = trackType => { SelectionManager.Clear(); TimelineHelpers.CreateTrack((Type)trackType, parentTrack); }; var category = TimelineHelpers.GetTrackCategoryName(type); if (!string.IsNullOrEmpty(category)) { category += "/"; } var name = category + TimelineHelpers.GetTrackMenuName(type); var disabled = (parentTrack != null && parentTrack.lockedInHierarchy) || state.editSequence.isReadOnly; bool addenu = true; var attr = Attribute.GetCustomAttribute(type, typeof(TrackAttribute)) as TrackAttribute; if (attr != null) { addenu = !attr.onlyInSub; } if (addenu) { AddCommandToMenu(menu, name, lastMethod, type, !disabled); } }
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); } } }
static void AddNewTrackMenuCommand(GenericMenu menu, TrackAsset parentTrack, TimelineGroupGUI parentGroup, Type type, WindowState state) { GenericMenu.MenuFunction2 lastMethod = trackType => { SelectionManager.Clear(); if (parentTrack is GroupTrack) { parentTrack.SetCollapsed(false); } var track = state.GetWindow().AddTrack((Type)trackType, parentGroup == null ? null : parentGroup.track); if (parentGroup != null) { state.GetWindow().treeView.data.SetExpanded(parentGroup, true); } if (track.GetType() == typeof(ActivationTrack)) { var clip = track.CreateClip(0); clip.displayName = ActivationTrackDrawer.Styles.ClipText.text; state.Refresh(); } }; var category = TimelineHelpers.GetTrackCategoryName(type); if (!string.IsNullOrEmpty(category)) { category += "/"; } var name = category + TimelineHelpers.GetTrackMenuName(type); var disabled = parentTrack != null && parentTrack.lockedInHierarchy; AddCommandToMenu(menu, name, lastMethod, type, !disabled); }
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); } } }
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 } ); } }