public static void OnClipMenu(ITimelineState state, TimelineClip[] clips, GenericMenu menu)
 {
     if (!(state.currentDirector == null))
     {
         TimelineClip[] array = (from c in clips
                                 where c.asset as AnimationPlayableAsset != null && c.parentTrack.clips.Any((TimelineClip x) => x.start < c.start)
                                 select c).ToArray <TimelineClip>();
         TimelineClip[] array2 = (from c in clips
                                  where c.asset as AnimationPlayableAsset != null && c.parentTrack.clips.Any((TimelineClip x) => x.start > c.start)
                                  select c).ToArray <TimelineClip>();
         if (array.Any <TimelineClip>() || array2.Any <TimelineClip>())
         {
             if (array.Any <TimelineClip>())
             {
                 menu.AddItem(AnimationOffsetMenu.MatchPreviousMenuItem, false, delegate(object x)
                 {
                     AnimationOffsetMenu.MatchClipsToPrevious(state, (TimelineClip[])x);
                 }, array);
             }
             if (array2.Any <TimelineClip>())
             {
                 menu.AddItem(AnimationOffsetMenu.MatchNextMenuItem, false, delegate(object x)
                 {
                     AnimationOffsetMenu.MatchClipsToNext(state, (TimelineClip[])x);
                 }, array2);
             }
             menu.AddItem(AnimationOffsetMenu.ResetOffsetMenuItem, false, delegate
             {
                 AnimationOffsetMenu.ResetClipOffsets(state, clips);
             });
         }
     }
 }
 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);
     });
 }
        private void CreateNewMarker(ITimelineMarkerContainer container, ITimelineState state)
        {
            string uniqueName = ObjectNames.GetUniqueName((from x in container.GetMarkers()
                                                           select x.key).ToArray <string>(), "New Marker");

            this.CreateExistingMarker(uniqueName, container, state);
        }
            public bool IsInBothInfluenceZone(double currentTime, ITimelineState state)
            {
                float num  = state.TimeToPixel(currentTime);
                float num2 = state.TimeToPixel(this.time);

                return(num > num2 - MagnetEngine.k_MagnetInfluenceInPixels - MagnetEngine.k_Epsilon && num < num2 + MagnetEngine.k_MagnetInfluenceInPixels);
            }
Esempio n. 5
0
        private static void AddSubTrack(ITimelineState state, Type trackOfType, string trackName, TrackAsset track)
        {
            TrackAsset childAsset = state.timeline.CreateTrack(trackOfType, track, trackName);

            TimelineCreateUtilities.SaveAssetIntoObject(childAsset, track);
            track.SetCollapsed(false);
            state.Refresh();
        }
Esempio n. 6
0
 private static void SetTrackBinding(ITimelineState state, TrackAsset track, GameObject gameObjectToBind)
 {
     if (state != null)
     {
         state.previewMode = false;
         TimelineUtility.SetSceneGameObject(state.currentDirector, track, gameObjectToBind);
         state.rebuildGraph = true;
     }
 }
Esempio n. 7
0
        private void DoTrackBindingGUI(Rect rect, Rect headerRect, ITimelineState state)
        {
            float num = 130f;

            rect.set_y(rect.get_y() + (rect.get_height() - 16f) / 2f);
            rect.set_height(16f);
            rect.set_width(headerRect.get_xMax() - num - rect.get_xMin());
            Object genericBinding = state.currentDirector.GetGenericBinding(base.track);

            if (rect.Contains(Event.get_current().get_mousePosition()) && TimelineTrackGUI.IsDraggingEvent() && DragAndDrop.get_objectReferences().Length == 1)
            {
                this.HandleDragAndDrop(state, TimelineTrackGUI.GetRequiredBindingType(this.m_Bindings[0]));
            }
            else
            {
                TrackAsset track = base.track;
                switch (this.m_Bindings[0].get_streamType())
                {
                case 0:
                {
                    EditorGUI.BeginChangeCheck();
                    Animator animator = EditorGUI.ObjectField(rect, genericBinding, typeof(Animator), true) as Animator;
                    if (EditorGUI.EndChangeCheck())
                    {
                        TimelineTrackGUI.SetTrackBinding(state, track, (!(animator == null)) ? animator.get_gameObject() : null);
                    }
                    goto IL_1E8;
                }

                case 1:
                {
                    EditorGUI.BeginChangeCheck();
                    AudioSource objectToBind = EditorGUI.ObjectField(rect, genericBinding, typeof(AudioSource), true) as AudioSource;
                    if (EditorGUI.EndChangeCheck())
                    {
                        TimelineTrackGUI.SetTrackBinding(state, track, objectToBind);
                    }
                    goto IL_1E8;
                }

                case 3:
                    if (this.m_Bindings[0].get_sourceBindingType() != null && typeof(Object).IsAssignableFrom(this.m_Bindings[0].get_sourceBindingType()))
                    {
                        EditorGUI.BeginChangeCheck();
                        Object objectToBind2 = EditorGUI.ObjectField(rect, genericBinding, this.m_Bindings[0].get_sourceBindingType(), true);
                        if (EditorGUI.EndChangeCheck())
                        {
                            TimelineTrackGUI.SetTrackBinding(state, track, objectToBind2);
                        }
                    }
                    goto IL_1E8;
                }
                throw new NotImplementedException("");
                IL_1E8 :;
            }
        }
 private static void SelectMarkerInInspector(ITimelineState state, TimelineMarker newEvent)
 {
     EditorWindow.FocusWindowIfItsOpen <InspectorWindow>();
     SelectionManager.Clear();
     newEvent.selected = true;
     Object[] objects = new Object[]
     {
         EditorItemFactory.GetEditorMarker(newEvent)
     };
     Selection.set_objects(objects);
 }
 private static void ResetClipOffsets(ITimelineState state, TimelineClip[] clips)
 {
     for (int i = 0; i < clips.Length; i++)
     {
         TimelineClip timelineClip = clips[i];
         if (timelineClip.asset is AnimationPlayableAsset)
         {
             AnimationPlayableAsset animationPlayableAsset = (AnimationPlayableAsset)timelineClip.asset;
             animationPlayableAsset.ResetOffsets();
         }
     }
     state.rebuildGraph = true;
 }
Esempio n. 10
0
        private void HandleDragAndDrop(ITimelineState state, Type requiredComponent)
        {
            DragAndDropVisualMode dragAndDropVisualMode = 32;

            if (requiredComponent != null && requiredComponent.IsInstanceOfType(DragAndDrop.get_objectReferences()[0]))
            {
                dragAndDropVisualMode = 2;
                if (Event.get_current().get_type() == 10)
                {
                    TimelineTrackGUI.SetTrackBinding(state, base.track, DragAndDrop.get_objectReferences()[0]);
                }
            }
            else if (typeof(Component).IsAssignableFrom(requiredComponent))
            {
                GameObject gameObjectBeingDragged = DragAndDrop.get_objectReferences()[0] as GameObject;
                if (gameObjectBeingDragged != null)
                {
                    dragAndDropVisualMode = 2;
                    if (Event.get_current().get_type() == 10)
                    {
                        Component component = gameObjectBeingDragged.GetComponent(requiredComponent);
                        if (component == null)
                        {
                            string      str         = requiredComponent.ToString().Split(".".ToCharArray()).Last <string>();
                            GenericMenu genericMenu = new GenericMenu();
                            genericMenu.AddItem(EditorGUIUtility.TextContent("Create " + str + " on " + gameObjectBeingDragged.get_name()), false, delegate(object nullParam)
                            {
                                Undo.AddComponent(gameObjectBeingDragged, requiredComponent);
                                TimelineTrackGUI.SetTrackBinding(state, this.track, gameObjectBeingDragged);
                            }, null);
                            genericMenu.AddSeparator("");
                            genericMenu.AddItem(EditorGUIUtility.TextContent("Cancel"), false, delegate(object userData)
                            {
                            }, null);
                            genericMenu.ShowAsContext();
                        }
                        else
                        {
                            TimelineTrackGUI.SetTrackBinding(state, base.track, gameObjectBeingDragged);
                        }
                    }
                }
            }
            DragAndDrop.set_visualMode(dragAndDropVisualMode);
            if (dragAndDropVisualMode == 2)
            {
                DragAndDrop.AcceptDrag();
            }
        }
        private static bool EnforcePreviewMode(ITimelineState state)
        {
            state.previewMode = true;
            bool result;

            if (!state.previewMode)
            {
                Debug.LogError("Match clips cannot be completed because preview mode cannot be enabed");
                result = false;
            }
            else
            {
                result = true;
            }
            return(result);
        }
            public bool IsInInfluenceZone(double currentTime, ITimelineState state, AttractedEdge direction)
            {
                float num  = state.TimeToPixel(currentTime);
                float num2 = state.TimeToPixel(this.time);
                bool  result;

                if (direction == AttractedEdge.Left)
                {
                    result = (num > num2 - MagnetEngine.k_Epsilon && num < num2 + MagnetEngine.k_MagnetInfluenceInPixels);
                }
                else
                {
                    result = (num > num2 - MagnetEngine.k_MagnetInfluenceInPixels - MagnetEngine.k_Epsilon && num < num2);
                }
                return(result);
            }
 internal static void MatchClipsToNext(ITimelineState state, TimelineClip[] clips)
 {
     if (AnimationOffsetMenu.EnforcePreviewMode(state))
     {
         clips = (from x in clips
                  orderby x.start descending
                  select x).ToArray <TimelineClip>();
         TimelineClip[] array = clips;
         for (int i = 0; i < array.Length; i++)
         {
             TimelineClip timelineClip = array[i];
             TimelineUndo.PushUndo(timelineClip.asset, "Match Clip");
             GameObject sceneGameObject = TimelineUtility.GetSceneGameObject(state.currentDirector, timelineClip.parentTrack);
             TimelineAnimationUtilities.MatchNext(timelineClip, sceneGameObject.get_transform(), state.currentDirector);
         }
     }
 }
Esempio n. 14
0
        public static double FindBestInsertionTime(ITimelineState state, TimelineClip clip, TrackAsset track, Vector2 mousePosition)
        {
            double       droppedTime  = state.SnapToFrameIfRequired((double)state.ScreenSpacePixelToTimeAreaTime(mousePosition.x));
            TimelineClip timelineClip = (from c in track.clips
                                         where c != clip && c.start - TimeUtility.kTimeEpsilon <= droppedTime
                                         orderby c.start
                                         select c).LastOrDefault <TimelineClip>();
            double result;

            if (timelineClip != null)
            {
                double num  = timelineClip.start + timelineClip.duration;
                double num2 = (double)state.TimeAreaPixelToTime(0f);
                if (num < num2)
                {
                    result = droppedTime;
                }
                else if (!float.IsPositiveInfinity(mousePosition.x) && droppedTime > num)
                {
                    result = droppedTime;
                }
                else
                {
                    result = num;
                }
            }
            else
            {
                timelineClip = (from c in track.clips
                                where c != clip
                                orderby c.start + c.duration
                                select c).LastOrDefault <TimelineClip>();
                if (timelineClip != null)
                {
                    result = timelineClip.start + timelineClip.duration;
                }
                else
                {
                    result = 0.0;
                }
            }
            return(result);
        }
Esempio n. 15
0
        public override bool DrawTrackHeaderButton(Rect rect, TrackAsset track, ITimelineState state)
        {
            AnimationTrack animationTrack = track as AnimationTrack;
            bool           flag           = animationTrack != null && animationTrack.avatarMask != null;

            if (flag)
            {
                GUIStyle   gUIStyle   = (!animationTrack.applyAvatarMask) ? DirectorStyles.Instance.avatarMaskOff : DirectorStyles.Instance.avatarMaskOn;
                GUIContent gUIContent = (!animationTrack.applyAvatarMask) ? AnimationTrackDrawer.Styles.s_AnimationButtonOffTooltip : AnimationTrackDrawer.Styles.s_AnimationButtonOnTooltip;
                if (GUI.Button(rect, gUIContent, gUIStyle))
                {
                    animationTrack.applyAvatarMask = !animationTrack.applyAvatarMask;
                    if (state != null)
                    {
                        state.rebuildGraph = true;
                    }
                }
            }
            return(flag);
        }
 public virtual void Delete(ITimelineState state)
 {
     if (this.m_DopeLines.get_index() >= 1)
     {
         if (this.m_ClipDataSource != null)
         {
             AnimationClip animationClip = this.m_ClipDataSource.animationClip;
             if (!(animationClip == null))
             {
                 int num = this.m_DopeLines.get_index() - 1;
                 EditorCurveBinding[] curveBindings = AnimationUtility.GetCurveBindings(animationClip);
                 if (num < curveBindings.Length)
                 {
                     TimelineUndo.PushUndo(animationClip, "Delete Curve");
                     AnimationUtility.SetEditorCurve(animationClip, curveBindings[this.m_DopeLines.get_index() - 1], null);
                     state.rebuildGraph = true;
                 }
             }
         }
     }
 }
Esempio n. 17
0
 public virtual bool DrawTrackHeaderButton(Rect rect, TrackAsset track, ITimelineState state)
 {
     return(false);
 }
Esempio n. 18
0
 public static TimelineClip CreateClipOnTrack(Type playableAssetType, TrackAsset parentTrack, ITimelineState state)
 {
     return(TimelineHelpers.CreateClipOnTrack(playableAssetType, parentTrack, state, TimelineHelpers.sInvalidMousePosition));
 }
Esempio n. 19
0
        public static TimelineClip CreateClipOnTrack(Object asset, TrackAsset parentTrack, ITimelineState state, Vector2 mousePosition)
        {
            double       end          = parentTrack.end;
            TimelineClip timelineClip = parentTrack.CreateClipFromAsset(asset);

            if (timelineClip != null)
            {
                SelectionManager.Clear();
                timelineClip.timeScale = 1.0;
                if (!float.IsPositiveInfinity(mousePosition.x) && !float.IsPositiveInfinity(mousePosition.y))
                {
                    timelineClip.start = (double)state.ScreenSpacePixelToTimeAreaTime(mousePosition.x);
                }
                else
                {
                    timelineClip.start = state.SnapToFrameIfRequired(end);
                }
                timelineClip.start       = Math.Max(0.0, timelineClip.start);
                timelineClip.mixInCurve  = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
                timelineClip.mixOutCurve = AnimationCurve.EaseInOut(0f, 1f, 1f, 0f);
                SelectionManager.Add(timelineClip);
                parentTrack.CalculateExtrapolationTimes();
                state.Refresh();
            }
            return(timelineClip);
        }
Esempio n. 20
0
 public virtual bool DrawTrack(Rect trackRect, TrackAsset trackAsset, Vector2 visibleTime, ITimelineState state)
 {
     return(false);
 }
Esempio n. 21
0
        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);
        }
Esempio n. 22
0
 public override void OnBuildClipContextMenu(GenericMenu menu, TimelineClip[] clips, ITimelineState state)
 {
     AnimationOffsetMenu.OnClipMenu(state, clips, menu);
 }
Esempio n. 23
0
 public virtual void OnBuildClipContextMenu(GenericMenu menu, TimelineClip[] clips, ITimelineState state)
 {
 }
Esempio n. 24
0
        private void CreateExistingMarker(string key, ITimelineMarkerContainer container, ITimelineState state)
        {
            Vector3 mousePosition = (this.trackMenuContext.clipTimeCreation != TrackDrawer.TrackMenuContext.ClipTimeCreation.Mouse) ? TimelineHelpers.sInvalidMousePosition : this.trackMenuContext.mousePosition;
            double  time          = TrackDrawer.CalculateMarkerTimeForMousePosition(container as TrackAsset, state, mousePosition);

            TimelineUndo.PushUndo(container as Object, "Create Marker");
            TimelineMarker newEvent = container.CreateMarker(key, time);

            TrackDrawer.SelectMarkerInInspector(state, newEvent);
            state.Refresh();
        }
Esempio n. 25
0
        private static double CalculateMarkerTimeForMousePosition(TrackAsset trackAsset, ITimelineState state, Vector3 mousePosition)
        {
            double time = 0.0;

            if (!float.IsPositiveInfinity(mousePosition.x) && !float.IsPositiveInfinity(mousePosition.y))
            {
                time = (double)state.ScreenSpacePixelToTimeAreaTime(mousePosition.x);
            }
            else if (trackAsset != null)
            {
                time = trackAsset.end + 0.5;
            }
            return(Math.Max(0.0, state.SnapToFrameIfRequired(time)));
        }
Esempio n. 26
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);
            }
        }
Esempio n. 27
0
        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);
                            });
                        }
                    }
                }
            }
        }
        public override bool DrawTrack(Rect trackRect, TrackAsset trackAsset, Vector2 visibleTime, ITimelineState state)
        {
            this.m_TrackRect = trackRect;
            TimelineWindow.TimelineState timelineState = (TimelineWindow.TimelineState)state;
            bool result;

            if (!this.CanDraw(trackAsset, timelineState))
            {
                result = true;
            }
            else
            {
                if (timelineState.recording && timelineState.IsArmedForRecord(trackAsset))
                {
                    InfiniteTrackDrawer.DrawRecordBackground(trackRect);
                }
                GUI.Box(trackRect, GUIContent.none, DirectorStyles.Instance.infiniteTrack);
                Rect rect = trackRect;
                rect.set_yMin(rect.get_yMax());
                rect.set_height(15f);
                GUI.DrawTexture(rect, DirectorStyles.Instance.bottomShadow.get_normal().get_background(), 0);
                float[] keys = this.m_DataSource.GetKeys();
                if (keys != null && keys.Length > 0)
                {
                    float[] array = keys;
                    for (int i = 0; i < array.Length; i++)
                    {
                        float key = array[i];
                        this.DrawKeyFrame(key, timelineState);
                    }
                }
                result = true;
            }
            return(result);
        }
Esempio n. 29
0
 protected void AddAddAssetMenuItem(GenericMenu menu, Type assetType, TrackAsset track, ITimelineState state)
 {
     if (!assetType.IsAbstract)
     {
         menu.AddItem(EditorGUIUtility.TextContent(TrackDrawer.k_AddClipContent.get_text() + " " + ObjectNames.NicifyVariableName(assetType.Name)), false, delegate(object typeOfClip)
         {
             TrackDrawer.AddAssetOnTrack(typeOfClip as Type, track, state);
         }, assetType);
     }
 }
Esempio n. 30
0
 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);
     }
 }