Beispiel #1
0
        public static TimelineAsset GetCurrentActiveTimeline()
        {
            var timeline_win = TimelineUtils.GetTimelineWindow();
            var asset        = timeline_win.GetType().GetProperty("timeline");
            var timeline     = asset.GetValue(timeline_win, null) as TimelineAsset;

            return(timeline);
        }
Beispiel #2
0
        public static void ToggleLockWindow()
        {
            var          window       = TimelineUtils.GetTimelineWindow();
            PropertyInfo propertyInfo = window.GetType().GetProperty("locked");
            bool         value        = (bool)propertyInfo.GetValue(window, null);

            propertyInfo.SetValue(window, !value, null);
            window.Repaint();
        }
Beispiel #3
0
        public static void SetTimeline(TimelineAsset timeline, PlayableDirector director)
        {
            var window = TimelineUtils.GetTimelineWindow();

#if UNITY_2018_2_OR_NEWER
            var method = window.GetType().GetMethod("SetCurrentTimeline", new[] { typeof(PlayableDirector), typeof(TimelineClip) });
            var retVal = method.Invoke(window, new object[] { director, null });
#else
            var method = window.GetType().GetMethod("SetCurrentTimeline", new [] { typeof(TimelineAsset), typeof(PlayableDirector) });
            method.Invoke(window, new object[] { timeline, director });
#endif
            Verify(retVal);
        }
        private void OnGUI()
        {
            GUILayout.Space(10);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Replacing [ " + selectedClips.Count + " ] anim clip(s) with...");

            if (GUILayout.Button("Get Selection", GUILayout.MaxWidth(100)))
            {
                GetSelectionClip();
            }

            GUILayout.EndHorizontal();
            GUILayout.Space(10);

            if (selectedClips.Count == 0)
            {
                return;
            }

            newClip = (AnimationClip)EditorGUILayout.ObjectField("Animation Clip", newClip, typeof(AnimationClip), false);
            GUILayout.Space(10);

            if (GUILayout.Button("REPLACE ANIMATION CLIP", GUILayout.Height(30)))
            {
                if (newClip == null)
                {
                    UnityEngine.Debug.LogError("No Animation Clip. Make sure you put in one");
                    return;
                }

                var selectedTrack  = TimelineUtils.GetTrackBasedOnClip(selectedClips[0]) as AnimationTrack;
                var timeline_asset = selectedTrack.timelineAsset;

                var director = TimelineUtils.GetDirectorFromTimeline(timeline_asset);

                Undo.RecordObject(director.playableAsset, "Replace Animation Clip");

                for (int i = 0; i < selectedClips.Count; i++)
                {
                    Replace(selectedClips[i], newClip, selectedTrack, timeline_asset);
                }

                InitAnimList();

                TimelineUtils.ToggleLockWindow();
                TimelineUtils.SetTimeline(timeline_asset, director);
                Selection.activeObject = director.gameObject;
                TimelineUtils.ToggleLockWindow();
            }
        }
        void GetSelectionClip()
        {
            var selections = Selection.objects;

            if (selectedClips.Count > 1)
            {
                selectedClips = new List <TimelineClip>();
            }

            for (int i = 0; i < selections.Length; i++)
            {
                var selectedClip = TimelineUtils.GetClip(selections[i]);
                selectedClips.Add(selectedClip);
            }
        }
Beispiel #6
0
        public static void AlignClipsToTail(UnityEngine.Object[] objects)
        {
            Undo.RecordObjects(objects, "Align Clips to Tail");

            List <double>       startTimeList = new List <double>();
            List <TimelineClip> clipList      = new List <TimelineClip>();

            foreach (var obj in objects)
            {
                var selectedClip = TimelineUtils.GetClip(obj);
                clipList.Add(selectedClip);
                startTimeList.Add(selectedClip.end);
            }

            double highest = startTimeList.Max();

            foreach (var clip in clipList)
            {
                clip.start = highest - clip.duration;
            }
            TimelineUtils.GetTimelineWindow().Repaint();
        }
Beispiel #7
0
        public static void AlignClipsToHead(UnityEngine.Object[] objects)
        {
            Undo.RecordObjects(objects, "Align Clips to Head");

            List <double>       startTimeList = new List <double>();
            List <TimelineClip> clipList      = new List <TimelineClip>();

            foreach (var obj in objects)
            {
                var selectedClip = TimelineUtils.GetClip(obj);
                clipList.Add(selectedClip);
                startTimeList.Add(selectedClip.start);
            }

            double lowest = startTimeList.Min();

            foreach (var clip in clipList)
            {
                clip.start = lowest;
            }
            TimelineUtils.GetTimelineWindow().Repaint();
        }
Beispiel #8
0
        public static void SnapToNext(UnityEngine.Object[] objects)
        {
            Undo.RecordObjects(objects, "Snap To Next's Start");
            List <TimelineClip> selectedClips = new List <TimelineClip>();

            for (int i = 0; i < objects.Length; i++)
            {
                var selectedClip = TimelineUtils.GetClip(objects[i]);
                selectedClips.Add(selectedClip);
            }

            selectedClips = selectedClips.OrderBy(c => c.start).ToList();
            selectedClips.Reverse();

            for (int i = 0; i < selectedClips.Count; i++)
            {
                var selectedClip  = selectedClips[i];
                var selectedTrack = GetTrackBasedOnClip(selectedClip);
                var clipsInTrack  = (Array)selectedTrack.GetClips();
                var index         = Array.IndexOf(clipsInTrack, selectedClip);

                // if found
                if (index > -1)
                {
                    // and not the last clip in track
                    if (index != clipsInTrack.Length - 1)
                    {
                        var nextClip = clipsInTrack.GetValue(index + 1) as TimelineClip;
                        selectedClip.start = nextClip.start - selectedClip.duration;
                    }
                }
                else
                {
                    UnityEngine.Debug.LogWarning("Clip not found");
                }
            }
            TimelineUtils.GetTimelineWindow().Repaint();
        }