コード例 #1
0
        static void AddMarkerMenuCommands(List <MenuActionItem> menu, IEnumerable <Type> markerTypes, Action <Type, Object> addMarkerCommand, bool enabled)
        {
            int builtInPriority = MenuPriority.AddItem.addMarker;
            int customPriority  = MenuPriority.AddItem.addCustomMarker;

            foreach (var markerType in markerTypes)
            {
                var    markerItemType = markerType;
                string category       = TimelineHelpers.GetItemCategoryName(markerItemType);
                menu.Add(
                    new MenuActionItem()
                {
                    category       = category,
                    entryName      = string.Format(Styles.addItemTemplate, TypeUtility.GetDisplayName(markerType)),
                    isActiveInMode = true,
                    priority       = TypeUtility.IsBuiltIn(markerType) ? builtInPriority++ : customPriority++,
                    state          = enabled ? ActionValidity.Valid : ActionValidity.Invalid,
                    callback       = () => addMarkerCommand(markerItemType, null)
                }
                    );

                foreach (var objectReference in TypeUtility.ObjectReferencesForType(markerType))
                {
                    var isSceneReference = objectReference.isSceneReference;
                    GenericMenu.MenuFunction menuCallback = () =>
                    {
                        Type assetDataType = objectReference.type;
                        ObjectSelector.get.titleContent = EditorGUIUtility.TrTextContent(string.Format(Styles.typeSelectorTemplate, TypeUtility.GetDisplayName(assetDataType)));
                        ObjectSelector.get.Show(null, assetDataType, null, isSceneReference, null, obj =>
                        {
                            if (obj != null)
                            {
                                addMarkerCommand(markerItemType, obj);
                            }
                        }, null);
                    };

                    menu.Add(
                        new MenuActionItem
                    {
                        category       = TimelineHelpers.GetItemCategoryName(markerItemType),
                        entryName      = string.Format(Styles.addItemFromAssetTemplate, TypeUtility.GetDisplayName(markerType), TypeUtility.GetDisplayName(objectReference.type)),
                        isActiveInMode = true,
                        priority       = TypeUtility.IsBuiltIn(markerType) ? builtInPriority++ : customPriority++,
                        state          = enabled ? ActionValidity.Valid : ActionValidity.Invalid,
                        callback       = menuCallback
                    }
                        );
                }
            }
        }
コード例 #2
0
        static void AddMarkerMenuCommands(List <MenuActionItem> menu, IEnumerable <Type> markerTypes, Action <Type, Object> addMarkerCommand, bool enabled)
        {
            int builtInPriority = MenuOrder.AddMarkerItemStart;
            int customPriority  = MenuOrder.AddCustomMarkerItemStart;

            foreach (var markerType in markerTypes)
            {
                var    markerItemType = markerType;
                string category       = TimelineHelpers.GetItemCategoryName(markerItemType);
                menu.Add(
                    new MenuActionItem()
                {
                    category       = category,
                    entryName      = string.Format(Styles.addItemTemplate, TypeUtility.GetDisplayName(markerType)),
                    shortCut       = string.Empty,
                    isActiveInMode = true,
                    isChecked      = false,
                    priority       = TypeUtility.IsBuiltIn(markerType) ? builtInPriority++ : customPriority++,
                    state          = enabled ? MenuActionDisplayState.Visible : MenuActionDisplayState.Disabled,
                    callback       = () => addMarkerCommand(markerItemType, null)
                }
                    );

                foreach (var objectReference in TypeUtility.ObjectReferencesForType(markerType))
                {
                    var isSceneReference = objectReference.isSceneReference;
                    GenericMenu.MenuFunction menuCallback = () =>
                    {
                        var dataType = markerItemType;
                        ObjectSelector.get.Show(null, dataType, null, isSceneReference, null, (obj) => addMarkerCommand(markerItemType, obj), null);
                        ObjectSelector.get.titleContent = EditorGUIUtility.TrTextContent(string.Format(Styles.typeSelectorTemplate, TypeUtility.GetDisplayName(dataType)));
                    };

                    menu.Add(
                        new MenuActionItem()
                    {
                        category       = TimelineHelpers.GetItemCategoryName(markerItemType),
                        entryName      = string.Format(Styles.addItemFromAssetTemplate, TypeUtility.GetDisplayName(markerType), TypeUtility.GetDisplayName(objectReference.type)),
                        shortCut       = string.Empty,
                        isActiveInMode = true,
                        isChecked      = false,
                        priority       = TypeUtility.IsBuiltIn(markerType) ? builtInPriority++ : customPriority++,
                        state          = enabled ? MenuActionDisplayState.Visible : MenuActionDisplayState.Disabled,
                        callback       = menuCallback
                    }
                        );
                }
            }
        }
コード例 #3
0
        static void AddClipMenuCommands(List <MenuActionItem> menuItems, ICollection <TrackAsset> tracks, double candidateTime)
        {
            if (!tracks.Any())
            {
                return;
            }

            var trackAsset = tracks.First();
            var trackType  = trackAsset.GetType();

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

            var enabled           = tracks.All(t => t != null && !t.lockedInHierarchy) && !TimelineWindow.instance.state.editSequence.isReadOnly;
            var assetTypes        = TypeUtility.GetPlayableAssetsHandledByTrack(trackType);
            var visibleAssetTypes = TypeUtility.GetVisiblePlayableAssetsHandledByTrack(trackType);

            // skips the name if there is only a single type
            var commandNameTemplate = assetTypes.Count() == 1 ? Styles.addSingleItemFromAssetTemplate : Styles.addItemFromAssetTemplate;
            int builtInPriority     = MenuPriority.AddItem.addClip;
            int customPriority      = MenuPriority.AddItem.addCustomClip;

            foreach (var assetType in assetTypes)
            {
                var             assetItemType   = assetType;
                var             category        = TimelineHelpers.GetItemCategoryName(assetType);
                Action <Object> onObjectChanged = obj =>
                {
                    if (obj != null)
                    {
                        foreach (var t in tracks)
                        {
                            TimelineHelpers.CreateClipOnTrack(assetItemType, obj, t, candidateTime);
                        }
                    }
                };

                foreach (var objectReference in TypeUtility.ObjectReferencesForType(assetType))
                {
                    var isSceneReference = objectReference.isSceneReference;
                    var dataType         = objectReference.type;
                    GenericMenu.MenuFunction menuCallback = () =>
                    {
                        ObjectSelector.get.Show(null, dataType, null, isSceneReference, null, (obj) => onObjectChanged(obj), null);
                        ObjectSelector.get.titleContent = EditorGUIUtility.TrTextContent(string.Format(Styles.typeSelectorTemplate, TypeUtility.GetDisplayName(dataType)));
                    };

                    menuItems.Add(
                        new MenuActionItem()
                    {
                        category       = category,
                        entryName      = string.Format(commandNameTemplate, TypeUtility.GetDisplayName(assetType), TypeUtility.GetDisplayName(objectReference.type)),
                        isActiveInMode = true,
                        priority       = TypeUtility.IsBuiltIn(assetType) ? builtInPriority++ : customPriority++,
                        state          = enabled ? ActionValidity.Valid : ActionValidity.Invalid,
                        callback       = menuCallback
                    }
                        );
                }
            }

            foreach (var assetType in visibleAssetTypes)
            {
                var assetItemType = assetType;
                var category      = TimelineHelpers.GetItemCategoryName(assetType);
                var commandName   = string.Format(Styles.addItemTemplate, TypeUtility.GetDisplayName(assetType));
                GenericMenu.MenuFunction command = () =>
                {
                    foreach (var t in tracks)
                    {
                        TimelineHelpers.CreateClipOnTrack(assetItemType, t, candidateTime);
                    }
                };

                menuItems.Add(
                    new MenuActionItem()
                {
                    category       = category,
                    entryName      = commandName,
                    isActiveInMode = true,
                    priority       = TypeUtility.IsBuiltIn(assetItemType) ? builtInPriority++ : customPriority++,
                    state          = enabled ? ActionValidity.Valid : ActionValidity.Invalid,
                    callback       = command
                }
                    );
            }
        }