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);
            }
        }
Example #2
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);
            }
        }
Example #3
0
        void DrawNoSequenceGUI(WindowState windowState)
        {
            bool showCreateButton    = false;
            var  currentlySelectedGo = UnityEditor.Selection.activeObject != null ? UnityEditor.Selection.activeObject as GameObject : null;
            var  textContent         = DirectorStyles.noTimelineAssetSelected;
            var  existingDirector    = currentlySelectedGo != null?currentlySelectedGo.GetComponent <PlayableDirector>() : null;

            var existingAsset = existingDirector != null ? existingDirector.playableAsset : null;

            if (currentlySelectedGo != null && !TimelineUtility.IsPrefabOrAsset(currentlySelectedGo) && existingAsset == null)
            {
                showCreateButton = true;
                textContent      = new GUIContent(String.Format(DirectorStyles.createTimelineOnSelection.text, currentlySelectedGo.name, "a Director component and a Timeline asset"));
            }
            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();

            GUILayout.Label(textContent);

            if (showCreateButton)
            {
                GUILayout.BeginHorizontal();
                var textSize = GUI.skin.label.CalcSize(textContent);
                GUILayout.Space((textSize.x / 2.0f) - (WindowConstants.createButtonWidth / 2.0f));
                if (GUILayout.Button("Create", GUILayout.Width(WindowConstants.createButtonWidth)))
                {
                    var    message         = DirectorStyles.createNewTimelineText.text + " '" + currentlySelectedGo.name + "'";
                    string newSequencePath = EditorUtility.SaveFilePanelInProject(DirectorStyles.createNewTimelineText.text, currentlySelectedGo.name + "Timeline", "playable", message, ProjectWindowUtil.GetActiveFolderPath());
                    if (!string.IsNullOrEmpty(newSequencePath))
                    {
                        var newAsset = CreateInstance <TimelineAsset>();
                        AssetDatabase.CreateAsset(newAsset, newSequencePath);

                        Undo.IncrementCurrentGroup();

                        if (existingDirector == null)
                        {
                            existingDirector = Undo.AddComponent <PlayableDirector>(currentlySelectedGo);
                        }

                        existingDirector.playableAsset = newAsset;
                        SetCurrentTimeline(existingDirector);
                        var newTrack = TimelineHelpers.CreateTrack <AnimationTrack>();

                        windowState.previewMode = false;
                        TimelineUtility.SetSceneGameObject(windowState.editSequence.director, newTrack, currentlySelectedGo);
                    }

                    // If we reach this point, the state of the pannel has changed; skip the rest of this GUI phase
                    // Fixes: case 955831 - [OSX] NullReferenceException when creating a timeline on a selected object
                    GUIUtility.ExitGUI();
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
        }
Example #4
0
        static void AddLayeredTrackCommands(List <MenuActionItem> menuItems, ICollection <TrackAsset> tracks)
        {
            if (tracks.Count == 0)
            {
                return;
            }

            var layeredType = tracks.First().GetType();

            // animation tracks have a special menu.
            if (layeredType == typeof(AnimationTrack))
            {
                return;
            }

            // must implement ILayerable
            if (!typeof(UnityEngine.Timeline.ILayerable).IsAssignableFrom(layeredType))
            {
                return;
            }

            if (tracks.Any(t => t.GetType() != layeredType))
            {
                return;
            }

            // only supported on the master track no nesting.
            if (tracks.Any(t => t.isSubTrack))
            {
                return;
            }

            var enabled  = tracks.All(t => t != null && !t.lockedInHierarchy) && !TimelineWindow.instance.state.editSequence.isReadOnly;
            int priority = MenuOrder.TrackAddMenu.AddLayerTrack;

            GenericMenu.MenuFunction menuCallback = () =>
            {
                foreach (var track in tracks)
                {
                    TimelineHelpers.CreateTrack(layeredType, track, string.Format(Styles.layerName, track.GetChildTracks().Count() + 1));
                }
            };

            var entryName = Styles.addTrackLayer;

            menuItems.Add(
                new MenuActionItem()
            {
                category       = string.Empty,
                entryName      = entryName,
                shortCut       = string.Empty,
                isActiveInMode = true,
                isChecked      = false,
                priority       = priority++,
                state          = enabled ? MenuActionDisplayState.Visible : MenuActionDisplayState.Disabled,
                callback       = menuCallback
            }
                );
        }
Example #5
0
        public override bool Execute(WindowState state, TrackAsset[] tracks)
        {
            foreach (var animTrack in tracks.OfType <AnimationTrack>())
            {
                TimelineHelpers.CreateTrack(typeof(AnimationTrack), animTrack, "Override " + animTrack.GetChildTracks().Count());
            }

            return(true);
        }
        public override bool Execute(WindowState state, TrackAsset[] tracks)
        {
            foreach (var track in tracks)
            {
                TimelineHelpers.CreateTrack <GroupTrack>(track, "Track Sub-Group");
            }

            state.Refresh();

            return(true);
        }
        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);
                }
            }
        }
Example #8
0
 static void AddSubTrack(WindowState state, Type trackOfType, string trackName, TrackAsset track)
 {
     TimelineHelpers.CreateTrack(trackOfType, track, trackName);
 }
Example #9
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
                }
                    );
            }
        }