Esempio n. 1
0
        public static void AddClipMenuCommands(GenericMenu menu, TrackAsset trackAsset, double candidateTime)
        {
            var assetTypes        = TypeUtility.GetPlayableAssetsHandledByTrack(trackAsset.GetType());
            var visibleAssetTypes = TypeUtility.GetVisiblePlayableAssetsHandledByTrack(trackAsset.GetType());

            if (assetTypes.Any() || visibleAssetTypes.Any())
            {
                menu.AddSeparator(string.Empty);
            }

            // skips the name if there is only a single type
            var commandNameTemplate = assetTypes.Count() == 1 ? Styles.addSingleItemFromAssetTemplate : Styles.addItemFromAssetTemplate;

            foreach (var assetType in assetTypes)
            {
                Action <Object> onObjectChanged = obj =>
                {
                    if (obj != null)
                    {
                        TimelineHelpers.CreateClipOnTrack(assetType, obj, trackAsset, candidateTime);
                    }
                };
                AddItemFromAssetCommands(menu, commandNameTemplate, assetType, onObjectChanged, !trackAsset.lockedInHierarchy && !TimelineWindow.instance.state.editSequence.isReadOnly);
            }

            foreach (var assetType in visibleAssetTypes)
            {
                var commandName = string.Format(Styles.addItemTemplate, TypeUtility.GetDisplayName(assetType));
                GenericMenu.MenuFunction command = () =>
                {
                    TimelineHelpers.CreateClipOnTrack(assetType, trackAsset, candidateTime);
                };
                AddCommandToMenu(menu, commandName, command, !trackAsset.lockedInHierarchy && !TimelineWindow.instance.state.editSequence.isReadOnly);
            }
        }
Esempio n. 2
0
        public static bool IsCompatibleWithClip(this TrackAsset track, TimelineClip clip)
        {
            if (track == null || clip == null || clip.asset == null)
            {
                return(false);
            }

            return(TypeUtility.GetPlayableAssetsHandledByTrack(track.GetType()).Contains(clip.asset.GetType()));
        }
Esempio n. 3
0
        public static TimelineClip CreateClipOnTrack(Object asset, TrackAsset parentTrack, double candidateTime, WindowState state)
        {
            if (parentTrack == null)
            {
                return(null);
            }

            // pick the first clip type available, unless there is one that matches the asset
            var clipType = TypeUtility.GetPlayableAssetsHandledByTrack(parentTrack.GetType()).FirstOrDefault();

            if (asset != null)
            {
                clipType = TypeUtility.GetAssetTypesForObject(parentTrack.GetType(), asset).FirstOrDefault();
            }

            if (clipType == null)
            {
                return(null);
            }

            return(CreateClipOnTrack(clipType, asset, parentTrack, candidateTime, state));
        }
Esempio n. 4
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
                }
                    );
            }
        }