using System; using System.Collections.Generic; using System.Linq; using UnityEngine.Playables; using UnityEngine.Timeline; namespace UnityEditor.Timeline { /// /// Information currently being edited in the Timeline Editor Window. /// public static class TimelineEditor { /// /// The PlayableDirector associated with the timeline currently being shown in the Timeline window. /// public static PlayableDirector inspectedDirector { get { return state == null ? null : state.editSequence.director; } } /// /// The PlayableDirector responsible for the playback of the timeline currently being shown in the Timeline window. /// public static PlayableDirector masterDirector { get { return state == null ? null : state.masterSequence.director; } } /// /// The TimelineAsset currently being shown in the Timeline window. /// public static TimelineAsset inspectedAsset { get { return state == null ? null : state.editSequence.asset; } } /// /// The TimelineAsset at the root of the hierarchy currently being shown in the Timeline window. /// public static TimelineAsset masterAsset { get { return state == null ? null : state.masterSequence.asset; } } /// /// The PlayableDirector currently being shown in the Timeline Editor Window. /// [Obsolete("playableDirector is ambiguous. Please select either inspectedDirector or masterDirector instead.", false)] public static PlayableDirector playableDirector { get { return inspectedDirector; } } /// /// The TimelineAsset currently being shown in the Timeline Editor Window. /// [Obsolete("timelineAsset is ambiguous. Please select either inspectedAsset or masterAsset instead.", false)] public static TimelineAsset timelineAsset { get { return inspectedAsset; } } /// /// /// Refreshes the different components affected by the currently inspected /// , based on the provided. /// /// /// For better performance, it is recommended that you invoke this method once, after you modify the /// . You should also combine reasons using the | operator. /// /// /// /// Note: This operation is not synchronous. It is performed during the next GUI loop. /// /// The reason why a refresh should be performed. public static void Refresh(RefreshReason reason) { if (state == null) return; if ((reason & RefreshReason.ContentsAddedOrRemoved) != 0) { state.Refresh(); } else if ((reason & RefreshReason.ContentsModified) != 0) { state.rebuildGraph = true; } else if ((reason & RefreshReason.SceneNeedsUpdate) != 0) { state.Evaluate(); } window.Repaint(); } static TimelineWindow window { get { return TimelineWindow.instance; } } static WindowState state { get { return window == null ? null : window.state; } } internal static readonly Clipboard clipboard = new Clipboard(); /// /// The list of clips selected in the TimelineEditor. /// public static TimelineClip[] selectedClips { get { return Selection.GetFiltered(SelectionMode.Unfiltered).Select(e => e.clip).Where(x => x != null).ToArray(); } set { if (value == null || value.Length == 0) { Selection.objects = null; } else { var objects = new List(); foreach (var clip in value) { if (clip == null) continue; var editorClip = EditorClipFactory.GetEditorClip(clip); if (editorClip != null) objects.Add(editorClip); } Selection.objects = objects.ToArray(); } } } /// /// The clip selected in the TimelineEditor. /// /// /// If there are multiple clips selected, this property returns the first clip. /// public static TimelineClip selectedClip { get { var editorClip = Selection.activeObject as EditorClip; if (editorClip != null) return editorClip.clip; return null; } set { var editorClip = (value != null) ? EditorClipFactory.GetEditorClip(value) : null; Selection.activeObject = editorClip; } } } /// /// uses these flags to determine what needs to be refreshed or updated. /// /// /// Use the | operator to combine flags. /// /// TimelineEditor.Refresh(RefreshReason.ContentsModified | RefreshReason.SceneNeedsUpdate); /// /// [Flags] public enum RefreshReason { /// /// Use this flag when a change to the Timeline requires that the Timeline window be redrawn. /// WindowNeedsRedraw = 1 << 0, /// /// Use this flag when a change to the Timeline requires that the Scene be updated. /// SceneNeedsUpdate = 1 << 1, /// /// Use this flag when a Timeline element was modified. /// ContentsModified = 1 << 2, /// /// Use this flag when an element was added to or removed from the Timeline. /// ContentsAddedOrRemoved = 1 << 3 } }