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); } }
static void AddMarkerMenuCommands(GenericMenu menu, IEnumerable <Type> markerTypes, Func <Type, IMarker> addMarkerCommand, bool enabled) { foreach (var markerType in markerTypes) { var commandName = string.Format(Styles.addItemTemplate, TypeUtility.GetDisplayName(markerType)); AddCommandToMenu(menu, commandName, () => addMarkerCommand(markerType), enabled); if (!typeof(ScriptableObject).IsAssignableFrom(markerType)) { continue; } Action <Object> onObjectChanged = obj => { if (obj == null) { return; } var marker = addMarkerCommand(markerType); foreach (var field in ObjectReferenceField.FindObjectReferences(markerType)) { if (field.IsAssignable(obj)) { field.Assign(marker as ScriptableObject, obj, TimelineWindow.instance.state.editSequence.director); break; } } }; AddItemFromAssetCommands(menu, Styles.addItemFromAssetTemplate, markerType, onObjectChanged, enabled); } }
internal override void OnHeaderTitleGUI(Rect titleRect, string header) { if (targets.Length > 1) { var multiSelectTitle = string.Format(Styles.MultipleMarkerSelectionTitle, targets.Length); base.OnHeaderTitleGUI(titleRect, multiSelectTitle); return; } var marker = target as ScriptableObject; if (marker != null) { EditorGUI.BeginChangeCheck(); var newName = EditorGUI.DelayedTextField(titleRect, marker.name); if (EditorGUI.EndChangeCheck()) { TimelineUndo.PushUndo(marker, Styles.UndoCommand); marker.name = newName; } } else { var typeName = TypeUtility.GetDisplayName(target.GetType()); EditorGUILayout.LabelField(typeName); } }
internal override void OnHeaderTitleGUI(Rect titleRect, string header) { if (targets.Length > 1) { var multiSelectTitle = string.Format(Styles.MultipleMarkerSelectionTitle, targets.Length); base.OnHeaderTitleGUI(titleRect, multiSelectTitle); return; } var marker = target as Marker; if (marker != null) { if (marker.parent.GetShowMarkers() && TimelineUtility.IsCurrentSequenceValid() && !IsCurrentSequenceReadOnly()) { EditorGUI.BeginChangeCheck(); var newName = EditorGUI.DelayedTextField(titleRect, marker.name); if (EditorGUI.EndChangeCheck()) { UndoExtensions.RegisterMarker(marker, Styles.UndoCommand); marker.name = newName; } } else { base.OnHeaderTitleGUI(titleRect, marker.name); } } else { var typeName = TypeUtility.GetDisplayName(target.GetType()); EditorGUILayout.LabelField(typeName); } }
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 } ); } } }
public static IMarker CreateMarkerAtTime(TrackAsset parent, Type markerType, double time) { var marker = parent.CreateMarker(markerType, time); var obj = marker as ScriptableObject; if (obj != null) { obj.name = TypeUtility.GetDisplayName(markerType); } SelectionManager.Add(marker); return(marker); }
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 } ); } } }
static void AddItemFromAssetCommands(GenericMenu menu, string commandNameTemplate, Type itemType, Action <Object> onObjectChanged, bool enabled) { foreach (var objectReference in TypeUtility.ObjectReferencesForType(itemType)) { var isSceneReference = objectReference.isSceneReference; GenericMenu.MenuFunction2 menuCallback = userData => { var dataType = (Type)userData; ObjectSelector.get.Show(null, dataType, null, isSceneReference, null, onObjectChanged, null); ObjectSelector.get.titleContent = EditorGUIUtility.TrTextContent(string.Format(Styles.typeSelectorTemplate, TypeUtility.GetDisplayName(dataType))); }; var menuItemContent = string.Format(commandNameTemplate, TypeUtility.GetDisplayName(itemType), TypeUtility.GetDisplayName(objectReference.type)); AddCommandToMenu(menu, menuItemContent, menuCallback, objectReference.type, enabled); } }
public static IMarker CreateMarkerOnTrack(Type markerType, Object assignableObject, TrackAsset parentTrack, double candidateTime) { WindowState state = null; if (TimelineWindow.instance != null) { state = TimelineWindow.instance.state; } var newMarker = parentTrack.CreateMarker(markerType, candidateTime); //Throws if marker is not an object var obj = newMarker as ScriptableObject; if (obj != null) { obj.name = TypeUtility.GetDisplayName(markerType); } if (assignableObject != null) { var director = state != null ? state.editSequence.director : null; foreach (var field in ObjectReferenceField.FindObjectReferences(markerType)) { if (field.IsAssignable(assignableObject)) { field.Assign(newMarker as ScriptableObject, assignableObject, director); break; } } } try { CustomTimelineEditorCache.GetMarkerEditor(newMarker).OnCreate(newMarker, null); } catch (Exception e) { Debug.LogException(e); } return(newMarker); }
public static IMarker CreateMarkerAtTime(TrackAsset parent, Type markerType, double time) { var marker = parent.CreateMarker(markerType, time); var obj = marker as ScriptableObject; if (obj != null) { obj.name = TypeUtility.GetDisplayName(markerType); } SelectionManager.Add(marker); try { CustomTimelineEditorCache.GetMarkerEditor(marker).OnCreate(marker, null); } catch (Exception e) { Debug.LogException(e); } return(marker); }
public static string GetTrackMenuName(System.Type trackType) { return(TypeUtility.GetDisplayName(trackType)); }
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 } ); } }