using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Timeline; namespace UnityEditor.Timeline.Actions { /// /// Class containing methods to invoke actions. /// public static class Invoker { /// /// Execute a given action with a context parameter. /// /// Action type to execute. /// Context for the action. /// True if the action has been executed, false otherwise. public static bool Invoke(this ActionContext context) where T : TimelineAction { var action = ActionManager.TimelineActions.GetCachedAction(); return ActionManager.ExecuteTimelineAction(action, context); } /// /// Execute a given action with tracks /// /// Action type to execute. /// Tracks that the action will act on. /// True if the action has been executed, false otherwise. public static bool Invoke(this IEnumerable tracks) where T : TrackAction { var action = ActionManager.TrackActions.GetCachedAction(); return ActionManager.ExecuteTrackAction(action, tracks); } /// /// Execute a given action with clips /// /// Action type to execute. /// Clips that the action will act on. /// True if the action has been executed, false otherwise. public static bool Invoke(this IEnumerable clips) where T : ClipAction { var action = ActionManager.ClipActions.GetCachedAction(); return ActionManager.ExecuteClipAction(action, clips); } /// /// Execute a given action with markers /// /// Action type to execute. /// Markers that the action will act on. /// True if the action has been executed, false otherwise. public static bool Invoke(this IEnumerable markers) where T : MarkerAction { var action = ActionManager.MarkerActions.GetCachedAction(); return ActionManager.ExecuteMarkerAction(action, markers); } /// /// Execute a given timeline action with the selected clips, tracks and markers. /// /// Action type to execute. /// True if the action has been executed, false otherwise. public static bool InvokeWithSelected() where T : TimelineAction { return Invoke(TimelineEditor.CurrentContext()); } /// /// Execute a given clip action with the selected clips. /// /// Action type to execute. /// True if the action has been executed, false otherwise. public static bool InvokeWithSelectedClips() where T : ClipAction { return Invoke(SelectionManager.SelectedClips()); } /// /// Execute a given track action with the selected tracks. /// /// Action type to execute. /// True if the action has been executed, false otherwise. public static bool InvokeWithSelectedTracks() where T : TrackAction { return Invoke(SelectionManager.SelectedTracks()); } /// /// Execute a given marker action with the selected markers. /// /// Action type to execute. /// True if the action has been executed, false otherwise. public static bool InvokeWithSelectedMarkers() where T : MarkerAction { return Invoke(SelectionManager.SelectedMarkers()); } } }