public override DragAndDropVisualMode DoDrag(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, DropPosition dropPos) { m_Window.isDragging = false; var retMode = DragAndDropVisualMode.None; var trackDragData = DragAndDrop.GetGenericData(k_GenericDragId) as TimelineDragData; if (trackDragData != null) { retMode = HandleTrackDrop(parentItem, targetItem, perform, dropPos); if (retMode == DragAndDropVisualMode.Copy && targetItem != null && Event.current.type == EventType.DragUpdated) { var targetActor = targetItem as TimelineGroupGUI; if (targetActor != null) targetActor.isDropTarget = true; } } else if (DragAndDrop.objectReferences.Any()) { var objectsBeingDropped = DragAndDrop.objectReferences.OfType<UnityObject>(); var director = m_Window.state.editSequence.director; if (ShouldUseHierarchyDragAndDrop()) { // for object drawing var originalTarget = targetItem; TreeViewItem insertBeforeItem = null; HandleNestedItemGUI(ref parentItem, ref targetItem, ref insertBeforeItem); var track = GetTrack(targetItem); var parent = GetTrack(parentItem); var insertBefore = GetTrack(insertBeforeItem); retMode = HandleHierarchyPaneDragAndDrop(objectsBeingDropped, track, perform, m_Timeline, director, ResolveType, insertBefore); // fallback to old clip behaviour if (retMode == DragAndDropVisualMode.None) { retMode = HandleClipPaneObjectDragAndDrop(objectsBeingDropped, track, perform, m_Timeline, parent, director, m_Window.state.timeAreaShownRange.x, ResolveType, insertBefore); } // if we are rejected, clear any drop markers if (retMode == DragAndDropVisualMode.Rejected && targetItem != null) { ClearInsertionMarkers(originalTarget); ClearInsertionMarkers(targetItem); ClearInsertionMarkers(parentItem); ClearInsertionMarkers(insertBeforeItem); } } else { var candidateTime = TimelineHelpers.GetCandidateTime(m_Window.state, Event.current.mousePosition); retMode = HandleClipPaneObjectDragAndDrop(objectsBeingDropped, GetTrack(targetItem), perform, m_Timeline, GetTrack(parentItem), director, candidateTime, ResolveType); } } m_Window.isDragging = false; return retMode; }
/// Handles drag and drop of a mono script. public static DragAndDropVisualMode HandleClipPaneMonoScriptDragAndDrop(IEnumerable <MonoScript> scriptsBeingDropped, TrackAsset targetTrack, bool perform, TimelineAsset timeline, TrackAsset parent, PlayableDirector director, double candidateTime) { var playableAssetTypes = scriptsBeingDropped.Select(s => s.GetClass()).Where(TypeUtility.IsConcretePlayableAsset).Distinct(); if (!playableAssetTypes.Any()) { return(DragAndDropVisualMode.Rejected); } var targetTrackType = typeof(PlayableTrack); if (targetTrack != null) { targetTrackType = targetTrack.GetType(); } var trackAssetsTypes = TypeUtility.GetPlayableAssetsHandledByTrack(targetTrackType); var supportedTypes = trackAssetsTypes.Intersect(playableAssetTypes); if (!supportedTypes.Any()) { return(DragAndDropVisualMode.Rejected); } if (perform) { if (targetTrack == null) { targetTrack = TimelineHelpers.CreateTrack(timeline, targetTrackType, parent, string.Empty); } TimelineHelpers.CreateClipsFromTypes(supportedTypes, targetTrack, candidateTime); } return(DragAndDropVisualMode.Copy); }
public static void AddMenuItems(GenericMenu menu, GroupTrack track) { TimelineWindow.TimelineState state = TimelineWindow.instance.state; TrackType[] array = TimelineHelpers.GetMixableTypes(); array = (from x in array orderby(!x.trackType.Assembly.FullName.Contains("UnityEngine.Sequence")) ? 1 : 0 select x).ToArray <TrackType>(); TrackType[] array2 = array; for (int i = 0; i < array2.Length; i++) { TrackType trackType = array2[i]; if (trackType.trackType != typeof(GroupTrack)) { GenericMenu.MenuFunction2 menuFunction = delegate(object e) { track.SetCollapsed(false); state.GetWindow().AddTrack((e as TrackType).trackType, track, null); TimelineTrackBaseGUI timelineTrackBaseGUI = TimelineTrackBaseGUI.FindGUITrack(track); if (timelineTrackBaseGUI != null) { TimelineWindow.instance.treeView.data.SetExpanded(timelineTrackBaseGUI, true); } }; object obj = trackType; string text = TimelineHelpers.GetTrackCategoryName(trackType); if (!string.IsNullOrEmpty(text)) { text += "/"; } menu.AddItem(new GUIContent("Add " + text + TimelineHelpers.GetTrackMenuName(trackType)), false, menuFunction, obj); } } }
public DragAndDropVisualMode HandleGameObjectDrop(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, TreeViewDragging.DropPosition dropPos) { DragAndDropVisualMode result; if (parentItem != null || targetItem != null) { result = 0; } else if (!DragAndDrop.get_objectReferences().Any((Object x) => x is GameObject)) { result = 0; } else if (this.m_Window.state.currentDirector == null) { result = 32; } else { if (perform) { Object[] objectReferences = DragAndDrop.get_objectReferences(); for (int i = 0; i < objectReferences.Length; i++) { Object @object = objectReferences[i]; GameObject go = @object as GameObject; if (!(go == null)) { PrefabType prefabType = PrefabUtility.GetPrefabType(go); if (prefabType != 1 && prefabType != 2) { IEnumerable <TrackType> enumerable = from x in TimelineHelpers.GetMixableTypes() where x.requiresGameObjectBinding select x; GenericMenu genericMenu = new GenericMenu(); foreach (TrackType current in enumerable) { genericMenu.AddItem(new GUIContent(TimelineHelpers.GetTrackMenuName(current)), false, delegate(object e) { TrackAsset trackAsset = this.m_Window.AddTrack(((TrackType)e).trackType, null, string.Empty); if (trackAsset.GetType() == typeof(ActivationTrack)) { TimelineClip timelineClip = trackAsset.CreateClip(0.0); timelineClip.displayName = ActivationTrackDrawer.Styles.ClipText.get_text(); } this.m_Window.state.previewMode = false; TimelineUtility.SetSceneGameObject(this.m_Window.state.currentDirector, trackAsset, go); }, current); } genericMenu.ShowAsContext(); } this.m_Window.state.Refresh(); } } } result = 1; } return(result); }
public static DragAndDropVisualMode HandleHierarchyPaneDragAndDrop(IEnumerable <UnityObject> objectsBeingDropped, TrackAsset targetTrack, bool perform, TimelineAsset timeline, PlayableDirector director, TypeResolver typeResolver, TrackAsset insertBefore = null) { if (timeline == null) { return(DragAndDropVisualMode.Rejected); } // if we are over a target track, defer to track binding system (implemented in TrackGUIs), unless we are a groupTrack if (targetTrack != null && (targetTrack as GroupTrack) == null) { return(DragAndDropVisualMode.None); } if (targetTrack != null && targetTrack.lockedInHierarchy) { return(DragAndDropVisualMode.Rejected); } var tracksWithBinding = objectsBeingDropped.SelectMany(TypeUtility.GetTracksCreatableFromObject).Distinct(); if (!tracksWithBinding.Any()) { return(DragAndDropVisualMode.None); } if (perform) { System.Action <Type> onResolve = trackType => { foreach (var obj in objectsBeingDropped) { if (!obj.IsPrefab() && TypeUtility.IsTrackCreatableFromObject(obj, trackType)) { var newTrack = TimelineHelpers.CreateTrack(timeline, trackType, targetTrack, string.Empty); if (insertBefore != null) { if (targetTrack != null) { targetTrack.MoveLastTrackBefore(insertBefore); } else { timeline.MoveLastTrackBefore(insertBefore); } } TimelineHelpers.Bind(newTrack, obj, director); } } TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved); }; typeResolver(tracksWithBinding, onResolve, k_SelectTrackWithBinding); } return(DragAndDropVisualMode.Copy); }
public static DragAndDropVisualMode HandleClipPanePlayableAssetDragAndDrop(IEnumerable <IPlayableAsset> assetsBeingDropped, TrackAsset targetTrack, bool perform, TimelineAsset timeline, TrackAsset parent, PlayableDirector director, double candidateTime, TypeResolver typeResolver) { // get the list of supported track types var assetTypes = assetsBeingDropped.Select(x => x.GetType()).Distinct(); IEnumerable <Type> supportedTypes = null; if (targetTrack == null) { supportedTypes = TypeUtility.AllTrackTypes().Where(t => TypeUtility.GetPlayableAssetsHandledByTrack(t).Intersect(assetTypes).Any()).ToList(); } else { supportedTypes = Enumerable.Empty <Type>(); var trackAssetTypes = TypeUtility.GetPlayableAssetsHandledByTrack(targetTrack.GetType()); if (trackAssetTypes.Intersect(assetTypes).Any()) { supportedTypes = new[] { targetTrack.GetType() } } ; } if (!supportedTypes.Any()) { return(DragAndDropVisualMode.Rejected); } if (perform) { Action <Type> onResolved = (t) => { if (targetTrack == null) { targetTrack = TimelineHelpers.CreateTrack(timeline, t, parent, string.Empty); } var clipTypes = TypeUtility.GetPlayableAssetsHandledByTrack(targetTrack.GetType()); foreach (var asset in assetsBeingDropped) { if (clipTypes.Contains(asset.GetType())) { TimelineHelpers.CreateClipOnTrackFromPlayableAsset(asset, targetTrack, candidateTime); } } }; typeResolver(supportedTypes, onResolved, k_SelectTrackWithClip); } return(DragAndDropVisualMode.Copy); }
static bool HandleTrackAndItemCreation(IEnumerable<UnityEngine.Object> objectsBeingDropped, double candidateTime, TypeResolver typeResolver, TimelineAsset timeline, TrackAsset parent, IEnumerable<Type> validTrackTypes, TrackAsset insertBefore = null) { Action<Type> onResolved = t => { var newTrack = TimelineHelpers.CreateTrack(timeline, t, parent, string.Empty); if (insertBefore != null) { if (parent != null) parent.MoveLastTrackBefore(insertBefore); else timeline.MoveLastTrackBefore(insertBefore); } HandleItemCreation(objectsBeingDropped, newTrack, candidateTime, typeResolver, validTrackTypes.Count() == 1); // menu is popped if ambiguous clip choice and unambiguous track choice }; return typeResolver(validTrackTypes, t => onResolved(t), k_SelectTrackWithClip); // Did it create a track }
static void HandleItemCreation(IEnumerable <UnityEngine.Object> objectsBeingDropped, TrackAsset targetTrack, double candidateTime, TypeResolver typeResolver, bool allowMenu) { var assetTypes = objectsBeingDropped.Select(o => TypeUtility.GetAssetTypesForObject(targetTrack.GetType(), o) .Union(TypeUtility.MarkerTypesWithFieldForObject(o))).ToList(); Action <Type> onCreateItem = assetType => { if (typeof(PlayableAsset).IsAssignableFrom(assetType)) { TimelineHelpers.CreateClipsFromObjects(assetType, targetTrack, candidateTime, objectsBeingDropped); } else { TimelineHelpers.CreateMarkersFromObjects(assetType, targetTrack, candidateTime, objectsBeingDropped); } }; var flatAssetTypes = assetTypes.SelectMany(x => x).Distinct(); // If there is a one to one mapping between assets and timeline types, no need to go through the type resolution, not ambiguous. if (assetTypes.All(x => x.Count() <= 1)) { foreach (var type in flatAssetTypes) { onCreateItem(type); } } else { if (!allowMenu) // If we already popped a menu, and are presented with an ambiguous choice, take the first entry { flatAssetTypes = new[] { flatAssetTypes.First() }; } typeResolver(flatAssetTypes, onCreateItem, k_SelectClip); } }
public DragAndDropVisualMode HandleObjectDrop(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, TreeViewDragging.DropPosition dropPos) { DragAndDropVisualMode result; if (!perform) { List <Object> list = new List <Object>(); if (DragAndDrop.get_objectReferences().Any <Object>()) { list.AddRange(DragAndDrop.get_objectReferences()); using (List <Object> .Enumerator enumerator = list.GetEnumerator()) { while (enumerator.MoveNext()) { Object o = enumerator.Current; TrackType[] trackTypeHandle = TimelineHelpers.GetTrackTypeHandle(o.GetType()); if (!trackTypeHandle.Any <TrackType>() || trackTypeHandle.Any((TrackType t) => !TimelineDragging.ValidateObjectDrop(o))) { result = 0; return(result); } } } result = 1; } else if (DragAndDrop.get_paths().Any <string>()) { TimelineGroupGUI timelineGroupGUI = targetItem as TimelineGroupGUI; if (timelineGroupGUI == null) { result = 1; } else if (timelineGroupGUI.track == null) { result = 0; } else { TrackType tt = TimelineHelpers.TrackTypeFromType(timelineGroupGUI.track.GetType()); string[] paths = DragAndDrop.get_paths(); for (int i = 0; i < paths.Length; i++) { string text = paths[i]; list.AddRange(AssetDatabase.LoadAllAssetsAtPath(text)); } bool flag = (from o in list where o != null select o).Any((Object o) => TimelineHelpers.IsTypeSupportedByTrack(tt, o.GetType())); result = ((!flag) ? 0 : 1); } } else { result = 0; } } else { List <Object> list2 = new List <Object>(); list2.AddRange(DragAndDrop.get_objectReferences()); TrackAsset trackAsset = null; TimelineGroupGUI timelineGroupGUI2 = (TimelineGroupGUI)targetItem; if (targetItem != null && timelineGroupGUI2.track != null) { trackAsset = timelineGroupGUI2.track; } Vector2 mousePosition = Event.get_current().get_mousePosition(); foreach (Object current in list2) { if (!(current == null)) { if (current is TimelineAsset) { if (TimelineHelpers.IsCircularRef(this.m_Timeline, current as TimelineAsset)) { Debug.LogError("Cannot add " + current.get_name() + " to the sequence because it would cause a circular reference"); continue; } TimelineAsset timelineAsset = current as TimelineAsset; foreach (TrackAsset current2 in timelineAsset.tracks) { if (current2.mediaType == TimelineAsset.MediaType.Group) { this.m_Timeline.AddTrackInternal(current2); } } this.m_Window.state.Refresh(); EditorUtility.SetDirty(this.m_Timeline); } else if (current is TrackAsset) { this.m_Timeline.AddTrackInternal((TrackAsset)current); } else { TrackType trackType = null; TrackAsset trackAsset2 = null; TrackType[] trackTypeHandle2 = TimelineHelpers.GetTrackTypeHandle(current.GetType()); if (trackAsset != null) { TrackType[] array = trackTypeHandle2; for (int j = 0; j < array.Length; j++) { TrackType trackType2 = array[j]; if (trackAsset.GetType() == trackType2.trackType) { trackType = trackType2; break; } } } if (trackType == null) { if (trackTypeHandle2.Length == 1) { trackType = trackTypeHandle2[0]; } else if (trackTypeHandle2.Length > 1) { trackType = this.ResolveTypeAmbiguity(trackTypeHandle2); } } if (trackType == null) { continue; } if (!TimelineDragging.ValidateObjectDrop(current)) { continue; } if (trackAsset != null && trackAsset.GetType() == trackType.trackType) { trackAsset2 = trackAsset; } if (trackAsset2 == null) { trackAsset2 = this.m_Window.AddTrack(trackType.trackType, null, string.Empty); } if (trackAsset2 == null) { result = 0; return(result); } Object @object = TimelineDragging.TransformObjectBeingDroppedAccordingToTrackRules(trackAsset2, current); if (@object == null) { continue; } TimelineUndo.PushUndo(trackAsset2, "Create Clip"); AnimationTrack animationTrack = trackAsset2 as AnimationTrack; if (animationTrack != null) { animationTrack.ConvertToClipMode(); } TimelineClip timelineClip = TimelineHelpers.CreateClipOnTrack(@object, trackAsset2, this.m_Window.state, mousePosition); if (timelineClip != null) { float num = this.m_Window.state.TimeToPixel(1.0) - this.m_Window.state.TimeToPixel(0.0); mousePosition.x += (float)timelineClip.duration * num; if (timelineClip.asset is ScriptableObject) { string assetPath = AssetDatabase.GetAssetPath(timelineClip.asset); if (assetPath.Length == 0) { TimelineCreateUtilities.SaveAssetIntoObject(timelineClip.asset, trackAsset2); } } TimelineDragging.FrameClips(this.m_Window.state); trackAsset2.SetCollapsed(false); } } this.m_Window.state.Refresh(); EditorUtility.SetDirty(this.m_Timeline); } } result = 1; } return(result); }
public void CalculateLoopRects(Rect trackRect, TimelineWindow.TimelineState state, int currentClipHash) { if (this.clip.duration >= TimelineWindow.TimelineState.kTimeEpsilon) { if (this.clip.dirtyHash != currentClipHash) { float num = 0f; this.m_LoopRects.Clear(); double[] loopTimes = TimelineHelpers.GetLoopTimes(this.clip); double loopDuration = TimelineHelpers.GetLoopDuration(this.clip); this.m_MinLoopIndex = 0; if (!this.supportsLooping) { if (loopTimes.Length > 1) { double num2 = loopTimes[1]; float num3 = (float)(this.clip.duration - num2); this.m_LoopRects.Add(TimelineClipGUI.ProjectRectOnTimeline(new Rect((float)(num2 + this.clip.start), 0f, num3, 0f), trackRect, state)); } } else { int num4 = Array.BinarySearch <double>(loopTimes, (double)state.PixelToTime(trackRect.get_xMin())); int num5 = Array.BinarySearch <double>(loopTimes, (double)state.PixelToTime(trackRect.get_xMax())); num4 = ((num4 < 0) ? Math.Max(1, ~num4 - 2) : num4); num5 = ((num5 < 0) ? Math.Max(1, ~num5) : num5); this.m_MinLoopIndex = num4; int num6 = num5 - num4; if ((float)num6 * 4f < trackRect.get_width()) { for (int i = num4; i < num5; i++) { double num7 = loopTimes[i]; float num8 = Mathf.Min((float)(this.clip.duration - num7), (float)loopDuration); Rect item = TimelineClipGUI.ProjectRectOnTimeline(new Rect((float)(num7 + this.clip.start), 0f, num8, 0f), trackRect, state); if (item.get_xMin() > trackRect.get_xMax()) { break; } if (item.get_xMax() >= trackRect.get_xMin()) { this.m_LoopRects.Add(item); num += item.get_width(); } else { this.m_MinLoopIndex++; } } if ((float)this.m_LoopRects.Count * 4f >= trackRect.get_width()) { this.m_LoopRects.Clear(); } if (num < 2f) { this.m_LoopRects.Clear(); } } } } } }
public override void Draw(Rect headerRect, Rect trackRect, TimelineWindow.TimelineState state, float identWidth) { if (!(base.track == null)) { if (!this.m_IsRoot) { if (this.get_depth() == 1) { EditorGUI.DrawRect(headerRect, DirectorStyles.Instance.customSkin.colorSequenceBackground); } Rect rect = headerRect; rect.set_x(headerRect.get_xMax() - 20f); rect.set_y(headerRect.get_y()); rect.set_width(20f); trackRect.set_width(trackRect.get_width() + state.bindingAreaWidth); Rect rect2 = headerRect; if (base.isExpanded && this.get_children() != null && this.get_children().Count > 0) { rect2.set_height(rect2.get_height() + (base.GetChildrenHeight(this) + 1f)); } rect2.set_xMin(rect2.get_xMin() + identWidth); Color color = DirectorStyles.Instance.customSkin.colorGroup; if (base.track.mediaType == TimelineAsset.MediaType.Animation) { color = DirectorStyles.Instance.customSkin.colorAnimation; } else if (base.track.mediaType == TimelineAsset.MediaType.Audio) { color = DirectorStyles.Instance.customSkin.colorAudio; } else if (base.track.mediaType == TimelineAsset.MediaType.Video) { color = DirectorStyles.Instance.customSkin.colorVideo; } else if (base.track.mediaType == TimelineAsset.MediaType.Script) { color = DirectorStyles.Instance.customSkin.colorScripting; } this.m_TrackRect = trackRect; this.m_HeaderRect = headerRect; Color color2 = color; bool flag = SelectionManager.Contains(base.track); if (flag) { color2 = DirectorStyles.Instance.customSkin.colorSelection; } else if (base.isDropTarget) { color2 = DirectorStyles.Instance.customSkin.colorDropTarget; } else if (this.m_GroupDepth % 2 == 1) { float num; float num2; float num3; Color.RGBToHSV(color2, ref num, ref num2, ref num3); num3 += 0.06f; color2 = Color.HSVToRGB(num, num2, num3); } using (new GUIColorOverride(color2)) { GUI.Box(rect2, GUIContent.none, this.m_Styles.groupBackground); } Rect rect3 = headerRect; rect3.set_xMin(rect3.get_xMin() + (rect2.get_width() + identWidth)); rect3.set_width(trackRect.get_width()); rect3.set_height(rect2.get_height()); color2 = ((!flag) ? this.m_Styles.customSkin.colorGroupTrackBackground : this.m_Styles.customSkin.colorTrackBackgroundSelected); EditorGUI.DrawRect(rect3, color2); bool flag2 = base.track.GetCollapsed() != !base.isExpanded; if (flag2) { base.track.SetCollapsed(!base.isExpanded); } if (this.m_MustRecomputeUnions || (flag2 && base.track.GetCollapsed())) { this.RecomputeRectUnions(state); } if (!base.isExpanded && this.get_children() != null && this.get_children().Count > 0) { Rect parentRect = trackRect; foreach (TimelineClipUnion current in this.m_Unions) { current.Draw(parentRect, state); } } if (base.track.locked) { GUI.Button(trackRect, "Locked"); } Rect rect4 = headerRect; rect4.set_xMin(rect4.get_xMin() + (identWidth + 20f)); string text = (!(base.track != null)) ? "missing" : base.track.get_name(); rect4.set_width(this.m_Styles.groupFont.CalcSize(new GUIContent(text)).x); rect4.set_width(Math.Max(rect4.get_width(), 50f)); if (base.track != null && base.track is GroupTrack) { Color newColor = this.m_Styles.groupFont.get_normal().get_textColor(); if (flag) { newColor = Color.get_white(); } EditorGUI.BeginChangeCheck(); string text2; using (new StyleNormalColorOverride(this.m_Styles.groupFont, newColor)) { text2 = EditorGUI.DelayedTextField(rect4, GUIContent.none, base.track.GetInstanceID(), base.track.get_name(), this.m_Styles.groupFont); } if (EditorGUI.EndChangeCheck()) { base.track.set_name(text2); if (text2.Length == 0) { base.track.set_name(TimelineHelpers.GenerateUniqueActorName(state.timeline, "unnamed")); } this.set_displayName(base.track.get_name()); } } using (new StyleNormalColorOverride(this.m_Styles.trackHeaderFont, Color.get_white())) { if (GUI.Button(rect, "+", this.m_Styles.trackHeaderFont)) { this.OnAddTrackClicked(); } } if (this.IsTrackRecording(state)) { using (new GUIColorOverride(DirectorStyles.Instance.customSkin.colorTrackBackgroundRecording)) { GUI.Label(rect2, GUIContent.none, this.m_Styles.displayBackground); } } if (Event.get_current().get_type() == 7) { base.isDropTarget = false; } if (this.m_IsReferencedTrack) { Rect rect5 = trackRect; rect5.set_x(state.timeAreaRect.get_xMax() - 20f); rect5.set_y(rect5.get_y() + 5f); rect5.set_width(30f); GUI.Label(rect5, DirectorStyles.referenceTrackLabel, EditorStyles.get_label()); } } } }