Ejemplo n.º 1
0
 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);
     });
 }
Ejemplo n.º 2
0
        public override void OnBuildTrackContextMenu(GenericMenu menu, TrackAsset track, ITimelineState state)
        {
            base.OnBuildTrackContextMenu(menu, track, state);
            bool           flag      = false;
            AnimationTrack animTrack = track as AnimationTrack;

            if (animTrack != null)
            {
                if (animTrack.CanConvertFromClipMode() || animTrack.CanConvertToClipMode())
                {
                    bool flag2 = animTrack.CanConvertFromClipMode();
                    bool flag3 = animTrack.CanConvertToClipMode();
                    if (flag2)
                    {
                        menu.AddItem(EditorGUIUtility.TextContent("Convert To Infinite Clip"), false, delegate(object parentTrack)
                        {
                            animTrack.ConvertFromClipMode(state.timeline);
                        }, track);
                        flag = true;
                    }
                    if (flag3)
                    {
                        menu.AddItem(EditorGUIUtility.TextContent("Convert To Clip Track"), false, delegate(object parentTrack)
                        {
                            animTrack.ConvertToClipMode();
                            state.Refresh();
                        }, track);
                    }
                }
            }
            if (!track.isSubTrack)
            {
                if (flag)
                {
                    menu.AddSeparator("");
                }
                menu.AddItem(EditorGUIUtility.TextContent("Add Override Track"), false, delegate(object parentTrack)
                {
                    AnimationTrackDrawer.AddSubTrack(state, typeof(AnimationTrack), "Override " + track.subTracks.Count.ToString(), track);
                }, track);
            }
        }
        internal static bool MoveClipToTrack(TimelineClip clip, TrackAsset track)
        {
            bool result;

            if (clip == null || track == null || clip.parentTrack == track)
            {
                result = false;
            }
            else
            {
                TimelineUndo.PushUndo(clip.parentTrack, "Move Clip");
                TimelineUndo.PushUndo(track, "Move Clip");
                AnimationTrack animationTrack = track as AnimationTrack;
                if (animationTrack != null)
                {
                    animationTrack.ConvertToClipMode();
                }
                TrackAsset parentTrack = clip.parentTrack;
                clip.parentTrack = track;
                parentTrack.CalculateExtrapolationTimes();
                result = true;
            }
            return(result);
        }
Ejemplo n.º 4
0
        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);
        }