private static void AddAssetOnTrack(Type typeOfClip, TrackAsset track, ITimelineState state) { state.AddStartFrameDelegate(delegate(ITimelineState istate, Event currentEvent) { ObjectSelector.get_get().Show(null, typeOfClip, null, false); ObjectSelector.get_get().objectSelectorID = 0; ObjectSelector.get_get().set_searchFilter(""); return(true); }); state.AddStartFrameDelegate(delegate(ITimelineState istate, Event currentEvent) { bool result; if (currentEvent.get_commandName() == "ObjectSelectorClosed") { AnimationTrack animationTrack = track as AnimationTrack; if (animationTrack && !animationTrack.inClipMode) { animationTrack.ConvertToClipMode(); } TimelineClip timelineClip = TimelineHelpers.CreateClipOnTrack(EditorGUIUtility.GetObjectPickerObject(), track, istate, TimelineHelpers.sInvalidMousePosition); if (timelineClip != null && timelineClip.asset != null) { TimelineCreateUtilities.SaveAssetIntoObject(timelineClip.asset, track); } result = true; } else { result = false; } return(result); }); }
public static TimelineClip CreateClip(this TrackAsset track, double time) { var attr = track.GetType().GetCustomAttributes(typeof(TrackClipTypeAttribute), true); if (attr.Length == 0) { return(null); } if (TimelineWindow.instance.state == null) { return(null); } if (attr.Length == 1) { var clipClass = (TrackClipTypeAttribute)attr[0]; var clip = TimelineHelpers.CreateClipOnTrack(clipClass.inspectedType, track, TimelineWindow.instance.state); clip.start = time; return(clip); } return(null); }
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); } }
public static TimelineClip CreateClip(this TrackAsset track, double time) { object[] customAttributes = track.GetType().GetCustomAttributes(typeof(TrackClipTypeAttribute), true); TimelineClip result; if (customAttributes.Length == 0) { result = null; } else if (TimelineWindow.instance.state == null) { result = null; } else if (customAttributes.Length == 1) { TrackClipTypeAttribute trackClipTypeAttribute = (TrackClipTypeAttribute)customAttributes[0]; TimelineClip timelineClip = TimelineHelpers.CreateClipOnTrack(trackClipTypeAttribute.inspectedType, track, TimelineWindow.instance.state); timelineClip.start = time; result = timelineClip; } else { result = null; } return(result); }
public override void OnBuildTrackContextMenu(GenericMenu menu, TrackAsset track, ITimelineState state) { if (track is ActivationTrack) { menu.AddItem(ActivationTrackDrawer.Styles.MenuText, false, delegate(object userData) { TimelineClip timelineClip = TimelineHelpers.CreateClipOnTrack(userData as Type, track, state); timelineClip.displayName = ActivationTrackDrawer.Styles.ClipText.get_text(); }, typeof(ActivationPlayableAsset)); } }
public virtual void OnBuildTrackContextMenu(GenericMenu menu, TrackAsset trackAsset, ITimelineState state) { bool flag = trackAsset is AnimationTrack || trackAsset is AudioTrack; if (flag) { List <Type> list = TimelineHelpers.GetTypesHandledByTrackType(TimelineHelpers.TrackTypeFromType(trackAsset.GetType())).ToList <Type>(); for (int i = 0; i < list.Count; i++) { Type assetType = list[i]; this.AddAddAssetMenuItem(menu, assetType, trackAsset, state); } } else if (TimelineHelpers.GetMediaTypeFromType(trackAsset.GetType()) == TimelineAsset.MediaType.Script) { Type customPlayableType = trackAsset.GetCustomPlayableType(); if (customPlayableType != null) { string displayName = TrackDrawer.GetDisplayName(customPlayableType); GUIContent gUIContent = new GUIContent("Add " + displayName + " Clip"); menu.AddItem(new GUIContent(gUIContent), false, delegate(object userData) { TimelineHelpers.CreateClipOnTrack(userData as Type, trackAsset, state); }, customPlayableType); } } ITimelineMarkerContainer markerContainer = trackAsset as ITimelineMarkerContainer; if (markerContainer != null) { menu.AddItem(TrackDrawer.Styles.newMarker, false, delegate { this.CreateNewMarker(markerContainer, state); }); IEnumerable <string> enumerable = (from x in markerContainer.GetMarkers() select x.key).Distinct <string>(); if (enumerable.Any <string>()) { using (IEnumerator <string> enumerator = enumerable.GetEnumerator()) { while (enumerator.MoveNext()) { string key = enumerator.Current; menu.AddItem(new GUIContent(TrackDrawer.Styles.addMarker.get_text() + key), false, delegate { this.CreateExistingMarker(key, markerContainer, state); }); } } } } }
protected void AddCreateAssetMenuItem(GenericMenu menu, Type assetType, TrackAsset track, ITimelineState state) { if (!assetType.IsAbstract) { menu.AddItem(EditorGUIUtility.TextContent("Create " + ObjectNames.NicifyVariableName(assetType.Name) + " Clip"), false, delegate(object typeOfClip) { if (this.trackMenuContext.clipTimeCreation == TrackDrawer.TrackMenuContext.ClipTimeCreation.Mouse) { TimelineHelpers.CreateClipOnTrack(typeOfClip as Type, track, state, this.trackMenuContext.mousePosition); } else { TimelineHelpers.CreateClipOnTrack(typeOfClip as Type, track, state); } this.trackMenuContext.clipTimeCreation = TrackDrawer.TrackMenuContext.ClipTimeCreation.TimeCursor; }, assetType); } }
public override void OnBuildTrackContextMenu(GenericMenu menu, TrackAsset trackAsset, ITimelineState state) { Type[] allStandalonePlayableAssets = TimelineHelpers.GetAllStandalonePlayableAssets(); Type[] array = allStandalonePlayableAssets; for (int i = 0; i < array.Length; i++) { Type type = array[i]; if (!type.IsDefined(typeof(HideInMenuAttribute), true) && !type.IsDefined(typeof(IgnoreOnPlayableTrackAttribute), true)) { string displayName = TrackDrawer.GetDisplayName(type); GUIContent gUIContent = new GUIContent("Add Clip/" + displayName); menu.AddItem(gUIContent, false, delegate(object userData) { TimelineHelpers.CreateClipOnTrack(userData as Type, trackAsset, state); }, type); } } }
public static TimelineClip CreateClipOnTrack(Type playableAssetType, TrackAsset parentTrack, ITimelineState state, Vector2 mousePosition) { TimelineClip result; if (!typeof(IPlayableAsset).IsAssignableFrom(playableAssetType) || !typeof(ScriptableObject).IsAssignableFrom(playableAssetType)) { result = null; } else { ScriptableObject scriptableObject = ScriptableObject.CreateInstance(playableAssetType); if (scriptableObject == null) { throw new InvalidOperationException("Could not create an instance of the ScriptableObject type " + playableAssetType.Name); } scriptableObject.set_name(playableAssetType.Name); TimelineCreateUtilities.SaveAssetIntoObject(scriptableObject, parentTrack); result = TimelineHelpers.CreateClipOnTrack(scriptableObject, parentTrack, state, mousePosition); } return(result); }
public static TimelineClip CreateClipOnTrack(Type playableAssetType, TrackAsset parentTrack, ITimelineState state) { return(TimelineHelpers.CreateClipOnTrack(playableAssetType, parentTrack, state, TimelineHelpers.sInvalidMousePosition)); }
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 } ); } }