public static bool UnCollapseGroup(IEnumerable <TrackAsset> tracks)
        {
            if (!TrackHeadActive())
            {
                return(false);
            }

            var didUncollapse = false;

            foreach (TrackAsset track in tracks)
            {
                if (!track.GetChildTracks().Any())
                {
                    continue;
                }

                if (track.GetCollapsed())
                {
                    didUncollapse = true;
                    track.SetCollapsed(false);
                }
            }

            if (didUncollapse)
            {
                TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
                return(true);
            }

            return(SelectFirstClipStartingFrom(tracks.Last()));
        }
Ejemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.PropertyField(m_FrameRateProperty, Styles.FrameRate, GUILayout.MinWidth(k_MinWidth));
            var frameRate = m_FrameRateProperty.doubleValue;

            EditorGUILayout.PropertyField(m_DurationModeProperty, Styles.DurationMode, GUILayout.MinWidth(k_MinWidth));

            var durationMode = (TimelineAsset.DurationMode)m_DurationModeProperty.enumValueIndex;
            var inputEvent   = InputEvent.None;

            if (durationMode == TimelineAsset.DurationMode.FixedLength)
            {
                TimelineInspectorUtility.TimeField(m_FixedDurationProperty, Styles.Duration, false, frameRate, double.Epsilon, TimelineClip.kMaxTimeValue * 2, ref inputEvent);
            }
            else
            {
                var isMixed = targets.Length > 1;
                TimelineInspectorUtility.TimeField(Styles.Duration, ((TimelineAsset)target).duration, true, isMixed, frameRate, double.MinValue, double.MaxValue, ref inputEvent);
            }

            DrawIgnorePreviewProperty();

            var changed = EditorGUI.EndChangeCheck();

            serializedObject.ApplyModifiedProperties();
            if (changed)
            {
                TimelineEditor.Refresh(RefreshReason.WindowNeedsRedraw);
            }
        }
Ejemplo n.º 3
0
        internal static UndoPropertyModification[] ProcessPlayableAssetModification(UndoPropertyModification[] modifications, WindowState state, bool allowAdd)
        {
            // can't record without a director since the asset being modified might be a scene instance
            if (state == null || state.editSequence.director == null)
            {
                return(modifications);
            }

            var remaining = new List <UndoPropertyModification>();

            foreach (UndoPropertyModification mod in modifications)
            {
                if (!ProcessPlayableAssetModification(mod, state, allowAdd))
                {
                    remaining.Add(mod);
                }
            }

            if (remaining.Count != modifications.Length)
            {
                TimelineEditor.Refresh(RefreshReason.ContentsModified);
            }

            return(remaining.ToArray());
        }
Ejemplo n.º 4
0
        public static void Insert(TimelineAsset asset, double at, double amount, double tolerance)
        {
            var tracks = asset.flattenedTracks.Where(x => x.lockedInHierarchy == false).ToList();
            // gather all clips
            var clips   = tracks.SelectMany(x => x.clips).Where(x => (x.start - at) >= -tolerance).ToList();
            var markers = tracks.SelectMany(x => x.GetMarkers()).Where(x => (x.time - at) >= -tolerance).ToList();

            // push undo on the tracks for the clips that are being modified
            UndoExtensions.RegisterClips(clips, kInsertTime);

            // push the clips
            foreach (var clip in clips)
            {
                clip.start += amount;
            }

            // push undos and move the markers
            UndoExtensions.RegisterMarkers(markers, kInsertTime);
            foreach (var marker in markers)
            {
                marker.time += amount;
            }

            TimelineEditor.Refresh(RefreshReason.ContentsModified);
        }
Ejemplo n.º 5
0
        public static TrackAsset CreateTrack(TimelineAsset asset, Type type, TrackAsset parent = null, string name = null)
        {
            if (asset == null)
            {
                return(null);
            }

            var track = asset.CreateTrack(type, parent, name);

            if (track != null)
            {
                if (parent != null)
                {
                    parent.SetCollapsed(false);
                }

                var editor = CustomTimelineEditorCache.GetTrackEditor(track);
                try
                {
                    editor.OnCreate(track, null);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
                TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
            }

            return(track);
        }
Ejemplo n.º 6
0
        internal bool Execute(ActionContext context, Func <ITimelineItem, ITimelineItem, double> gapBetweenItems)
        {
            List <ITimelineItem> items = new List <ITimelineItem>();

            items.AddRange(context.clips.Select(p => p.ToItem()));
            items.AddRange(context.markers.Select(p => p.ToItem()));
            List <ItemsPerTrack> selectedItems = items.ToItemsPerTrack().ToList();

            if (selectedItems.Any())
            {
                var requestedTime   = CalculateDuplicateTime(selectedItems, gapBetweenItems);
                var duplicatedItems = TimelineHelpers.DuplicateItemsUsingCurrentEditMode(TimelineEditor.inspectedDirector, TimelineEditor.inspectedDirector, selectedItems, requestedTime, "Duplicate Items");

                TimelineHelpers.FrameItems(duplicatedItems);
                SelectionManager.RemoveTimelineSelection();
                foreach (var item in duplicatedItems)
                {
                    SelectionManager.Add(item);
                }
            }

            var tracks = context.tracks.ToArray();

            if (tracks.Length > 0)
            {
                tracks.Invoke <DuplicateTracks>();
            }

            TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
            return(true);
        }
        public static bool CollapseGroup()
        {
            if (TrackHeadActive())
            {
                var quit = false;
                foreach (var track in SelectionManager.SelectedTracks())
                {
                    if (!track.GetChildTracks().Any())
                    {
                        continue;
                    }
                    if (!quit && !track.GetCollapsed())
                    {
                        quit = true;
                    }
                    track.SetCollapsed(true);
                }
                if (quit)
                {
                    TimelineEditor.Refresh(RefreshReason.ContentsModified);
                    return(true);
                }

                var selectedTrack = SelectionManager.SelectedTracks().LastOrDefault();
                var parent        = selectedTrack != null ? selectedTrack.parent as TrackAsset : null;
                if (parent)
                {
                    SelectionManager.SelectOnly(parent);
                    FrameTrackHeader(GetVisibleTracks().First(x => x.track == parent));
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 8
0
        public override bool Execute(IEnumerable <TrackAsset> tracks)
        {
            tracks = tracks.RemoveTimelineMarkerTrackFromList(TimelineEditor.inspectedAsset);
            if (tracks.Any())
            {
                SelectionManager.RemoveTimelineSelection();
            }

            foreach (var track in TrackExtensions.FilterTracks(tracks))
            {
                var newTrack = track.Duplicate(TimelineEditor.inspectedDirector, TimelineEditor.inspectedDirector);
                //Add all duplicated tracks to selection
                SelectionManager.Add(newTrack);
                foreach (var childTrack in newTrack.GetFlattenedChildTracks())
                {
                    SelectionManager.Add(childTrack);
                }

                //Duplicate bindings for tracks and subtracks
                if (TimelineEditor.inspectedDirector != null)
                {
                    DuplicateBindings(track, newTrack, TimelineEditor.inspectedDirector);
                }
            }

            TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);

            return(true);
        }
Ejemplo n.º 9
0
        public static void Insert(TimelineAsset asset, double at, double amount, double tolerance)
        {
            var tracks = asset.flattenedTracks.Where(x => x.lockedInHierarchy == false).ToList();
            // gather all clips
            var clips   = tracks.SelectMany(x => x.clips).Where(x => (x.start - at) >= -tolerance).ToList();
            var markers = tracks.SelectMany(x => x.GetMarkers()).Where(x => (x.time - at) >= -tolerance).ToList();

            // push undo on the tracks for the clips that are being modified
            foreach (var t in clips.Select(x => x.parentTrack).Distinct())
            {
                TimelineUndo.PushUndo(t, kInsertTime);
            }

            // push the clips
            foreach (var clip in clips)
            {
                clip.start += amount;
            }

            // push undos and move the markers
            foreach (var marker in markers)
            {
                var obj = marker as UnityEngine.Object;
                if (obj != null)
                {
                    TimelineUndo.PushUndo(obj, kInsertTime);
                }
                marker.time += amount;
            }

            TimelineEditor.Refresh(RefreshReason.ContentsModified);
        }
        public static bool CollapseGroup(IEnumerable <TrackAsset> tracks)
        {
            if (!TrackHeadActive())
            {
                return(false);
            }

            var didCollapse = false;

            foreach (TrackAsset track in tracks)
            {
                if (!track.GetChildTracks().Any())
                {
                    continue;
                }

                if (!track.GetCollapsed())
                {
                    didCollapse = true;
                    track.SetCollapsed(true);
                }
            }

            if (didCollapse)
            {
                TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
                return(true);
            }

            return(SelectAndShowParentTrack(tracks.LastOrDefault()));
        }
Ejemplo n.º 11
0
        public override bool Execute(IEnumerable <TrackAsset> tracks)
        {
            tracks = tracks.RemoveTimelineMarkerTrackFromList(TimelineEditor.inspectedAsset);
            if (tracks.Any())
            {
                SelectionManager.RemoveTimelineSelection();
            }

            foreach (var track in TrackExtensions.FilterTracks(tracks))
            {
                var newTrack = track.Duplicate(TimelineEditor.inspectedDirector, TimelineEditor.inspectedDirector);
                SelectionManager.Add(newTrack);
                foreach (var childTrack in newTrack.GetFlattenedChildTracks())
                {
                    SelectionManager.Add(childTrack);
                }

                if (TimelineEditor.inspectedDirector != null)
                {
                    var binding = TimelineEditor.inspectedDirector.GetGenericBinding(track);
                    if (binding != null)
                    {
                        TimelineUndo.PushUndo(TimelineEditor.inspectedDirector, L10n.Tr("Duplicate"));
                        TimelineEditor.inspectedDirector.SetGenericBinding(newTrack, binding);
                    }
                }
            }

            TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);

            return(true);
        }
Ejemplo n.º 12
0
        public static void FinishTrim()
        {
            s_CurrentTrimItem = null;

            TimelineCursors.ClearCursor();
            ClearEditMode();

            TimelineEditor.Refresh(RefreshReason.ContentsModified);
        }
Ejemplo n.º 13
0
        public virtual void OnPlayableAssetChangedInInspector()
        {
            if (m_ShouldRebuild)
            {
                TimelineEditor.Refresh(RefreshReason.ContentsModified);
            }

            m_ShouldRebuild = false;
        }
        public void GoToNextKeyframe(PropertyModification[] modifications)
        {
            if (modifications.Length == 0 || modifications[0].target == null)
            {
                return;
            }

            TimelineRecording.NextKey(modifications[0].target, modifications, state);
            TimelineEditor.Refresh(RefreshReason.SceneNeedsUpdate);
        }
Ejemplo n.º 15
0
 static void AddMarkersCallback(ICollection <TrackAsset> targets, Type markerType, double time, Object obj)
 {
     SelectionManager.Clear();
     foreach (var target in targets)
     {
         var marker = TimelineHelpers.CreateMarkerOnTrack(markerType, obj, target, time);
         SelectionManager.Add(marker);
     }
     TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
 }
Ejemplo n.º 16
0
        public override bool Execute(IEnumerable <TimelineClip> clips)
        {
            bool success = ClipModifier.Split(clips, TimelineEditor.inspectedSequenceTime, TimelineEditor.inspectedDirector);

            if (success)
            {
                TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
            }
            return(success);
        }
Ejemplo n.º 17
0
        public override bool Execute(WindowState state, TrackAsset[] tracks)
        {
            foreach (var animTrack in tracks.OfType <AnimationTrack>())
            {
                animTrack.ConvertFromClipMode(state.editSequence.asset);
            }

            TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);

            return(true);
        }
Ejemplo n.º 18
0
        public override bool Execute(IEnumerable <TrackAsset> tracks)
        {
            foreach (var animTrack in tracks.OfType <AnimationTrack>())
            {
                animTrack.ConvertFromClipMode(TimelineEditor.inspectedAsset);
            }

            TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);

            return(true);
        }
        public override bool Execute(IEnumerable <TrackAsset> tracks)
        {
            foreach (var animTrack in tracks.OfType <AnimationTrack>())
            {
                ConvertToRecordableClip(animTrack);
            }

            TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);

            return(true);
        }
Ejemplo n.º 20
0
        public override bool Execute(IEnumerable <TrackAsset> tracks)
        {
            foreach (var animTrack in tracks.OfType <AnimationTrack>())
            {
                animTrack.UnarmForRecord();
                animTrack.trackOffset = trackOffset;
            }

            TimelineEditor.Refresh(RefreshReason.ContentsModified);
            return(true);
        }
        public override void OnInspectorGUI()
        {
            if (target == null)
            {
                return;
            }

            serializedObject.Update();

            if (!m_TimelineWindow)
            {
                m_TimelineWindow = TimelineWindow.instance;
            }

            ShowAnimationClipField();
            ShowRecordableClipRename();
            ShowAnimationClipWarnings();

            EditorGUI.BeginChangeCheck();

            TransformOffsetsGUI();

            // extra checks are because the context menu may need to cause a re-evaluate
            bool changed = EditorGUI.EndChangeCheck() ||
                           m_LastPosition != m_PositionProperty.vector3Value ||
                           m_LastRotation != m_RotationProperty.vector3Value;

            m_LastPosition = m_PositionProperty.vector3Value;
            m_LastRotation = m_RotationProperty.vector3Value;

            if (changed)
            {
                // updates the changed properties and pushes them to the active playable
                serializedObject.ApplyModifiedProperties();
                ((AnimationPlayableAsset)target).LiveLink();

                // force an evaluate to happen next frame
                if (TimelineWindow.instance != null && TimelineWindow.instance.state != null)
                {
                    TimelineWindow.instance.state.Evaluate();
                }
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(m_ApplyFootIK, Styles.ApplyFootIK);
            EditorGUILayout.PropertyField(m_Loop, Styles.Loop);
            if (EditorGUI.EndChangeCheck())
            {
                TimelineEditor.Refresh(RefreshReason.ContentsModified);
            }

            serializedObject.ApplyModifiedProperties();
        }
        // Called when a prefab change is applied to the scene.
        // Redraw so control tracks that use prefabs can show changes
        void OnPrefabApplied(GameObject go)
        {
            if (!state.previewMode)
                return;

            // if we added a component this frame, then rebuild, otherwise just let
            //  the individual playable handle the prefab application
            if (Time.frameCount == m_ComponentAddedFrame)
                TimelineEditor.Refresh(RefreshReason.ContentsModified);
            else
                TimelineEditor.Refresh(RefreshReason.SceneNeedsUpdate);
        }
Ejemplo n.º 23
0
        public override bool Execute(WindowState state, TrackAsset[] tracks)
        {
            foreach (var animTrack in tracks.OfType <AnimationTrack>())
            {
                state.UnarmForRecord(animTrack);
                TimelineUndo.PushUndo(animTrack, "Set Transform Offsets");
                animTrack.trackOffset = trackOffset;
            }

            TimelineEditor.Refresh(RefreshReason.ContentsModified);
            return(true);
        }
Ejemplo n.º 24
0
        public static void SetLockState(IEnumerable <TrackAsset> tracks, bool shouldLock)
        {
            if (!tracks.Any())
            {
                return;
            }

            foreach (var track in tracks)
            {
                if (TimelineUtility.IsLockedFromGroup(track))
                {
                    continue;
                }

                if (track as GroupTrack == null)
                {
                    SetLockState(track.GetChildTracks().ToArray(), shouldLock);
                }

                TimelineUndo.PushUndo(track, L10n.Tr("Lock Tracks"));
                track.locked = shouldLock;
            }

            // find the tracks we've locked. unselect anything locked and remove recording.
            foreach (var track in tracks)
            {
                if (TimelineUtility.IsLockedFromGroup(track) || !track.locked)
                {
                    continue;
                }

                var flattenedChildTracks = track.GetFlattenedChildTracks();
                foreach (var i in track.clips)
                {
                    SelectionManager.Remove(i);
                }
                track.UnarmForRecord();
                foreach (var child in flattenedChildTracks)
                {
                    SelectionManager.Remove(child);
                    child.UnarmForRecord();
                    foreach (var clip in child.GetClips())
                    {
                        SelectionManager.Remove(clip);
                    }
                }
            }

            // no need to rebuild, just repaint (including inspectors)
            InspectorWindow.RepaintAllInspectors();
            TimelineEditor.Refresh(RefreshReason.WindowNeedsRedraw);
        }
        static WaveformPreview CreateWaveformPreview(AudioClip audioClip, Rect quantizedRect)
        {
            WaveformPreview preview     = WaveformPreviewFactory.Create((int)quantizedRect.width, audioClip);
            Color           waveColour  = GammaCorrect(DirectorStyles.Instance.customSkin.colorAudioWaveform);
            Color           transparent = waveColour;

            transparent.a           = 0;
            preview.backgroundColor = transparent;
            preview.waveColor       = waveColour;
            preview.SetChannelMode(WaveformPreview.ChannelMode.MonoSum);
            preview.updated += () => TimelineEditor.Refresh(RefreshReason.WindowNeedsRedraw);
            return(preview);
        }
Ejemplo n.º 26
0
        public override bool Execute(ActionContext context)
        {
            if (!CanPaste(context.invocationTime))
            {
                return(false);
            }

            PasteItems(context.invocationTime);
            PasteTracks();

            TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
            return(true);
        }
Ejemplo n.º 27
0
        public static void Lock(TrackAsset[] tracks, bool shouldlock)
        {
            if (tracks.Length == 0)
            {
                return;
            }

            foreach (var track in tracks.Where(t => !TimelineUtility.IsLockedFromGroup(t)))
            {
                TimelineUndo.PushUndo(track, L10n.Tr("Lock Tracks"));
                track.locked = shouldlock;
            }
            TimelineEditor.Refresh(RefreshReason.WindowNeedsRedraw);
        }
Ejemplo n.º 28
0
        static void ShowHide(IEnumerable <TrackAsset> tracks, bool shouldLock)
        {
            if (!tracks.Any())
            {
                return;
            }

            foreach (var track in tracks)
            {
                track.SetShowTrackMarkers(shouldLock);
            }

            TimelineEditor.Refresh(RefreshReason.WindowNeedsRedraw);
        }
        public static void ResetClipOffsets(TimelineClip[] clips)
        {
            foreach (var clip in clips)
            {
                var asset = clip.asset as AnimationPlayableAsset;
                if (asset != null)
                {
                    asset.ResetOffsets();
                }
            }

            InspectorWindow.RepaintAllInspectors();
            TimelineEditor.Refresh(RefreshReason.ContentsModified);
        }
        public static bool UnCollapseGroup()
        {
            if (TrackHeadActive())
            {
                var quit = false;
                foreach (var track in SelectionManager.SelectedTracks())
                {
                    if (!track.GetChildTracks().Any())
                    {
                        continue;
                    }

                    if (!quit && track.GetCollapsed())
                    {
                        quit = true;
                    }
                    track.SetCollapsed(false);
                }

                if (quit)
                {
                    TimelineEditor.Refresh(RefreshReason.ContentsModified);
                    return(true);
                }

                // Transition to Clip area
                var           visibleTracks = GetVisibleTracks().Select(x => x.track).ToList();
                var           idx           = visibleTracks.IndexOf(SelectionManager.SelectedTracks().Last());
                ITimelineItem item          = null;
                for (var i = idx; i < visibleTracks.Count; ++i)
                {
                    var items = visibleTracks[i].GetItems().OfType <ClipItem>();
                    if (!items.Any())
                    {
                        continue;
                    }
                    item = items.First();
                    break;
                }

                if (item != null)
                {
                    SelectionManager.SelectOnly(item);
                    TimelineHelpers.FrameItems(new[] { item });
                    return(true);
                }
            }
            return(false);
        }