No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Invoker.cs 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Timeline;
  5. namespace UnityEditor.Timeline.Actions
  6. {
  7. /// <summary>
  8. /// Class containing methods to invoke actions.
  9. /// </summary>
  10. public static class Invoker
  11. {
  12. /// <summary>
  13. /// Execute a given action with a context parameter.
  14. /// </summary>
  15. /// <typeparam name="T">Action type to execute.</typeparam>
  16. /// <param name="context">Context for the action.</param>
  17. /// <returns>True if the action has been executed, false otherwise.</returns>
  18. public static bool Invoke<T>(this ActionContext context) where T : TimelineAction
  19. {
  20. var action = ActionManager.TimelineActions.GetCachedAction<T, TimelineAction>();
  21. return ActionManager.ExecuteTimelineAction(action, context);
  22. }
  23. /// <summary>
  24. /// Execute a given action with tracks
  25. /// </summary>
  26. /// <typeparam name="T">Action type to execute.</typeparam>
  27. /// <param name="tracks">Tracks that the action will act on.</param>
  28. /// <returns>True if the action has been executed, false otherwise.</returns>
  29. public static bool Invoke<T>(this IEnumerable<TrackAsset> tracks) where T : TrackAction
  30. {
  31. var action = ActionManager.TrackActions.GetCachedAction<T, TrackAction>();
  32. return ActionManager.ExecuteTrackAction(action, tracks);
  33. }
  34. /// <summary>
  35. /// Execute a given action with clips
  36. /// </summary>
  37. /// <typeparam name="T">Action type to execute.</typeparam>
  38. /// <param name="clips">Clips that the action will act on.</param>
  39. /// <returns>True if the action has been executed, false otherwise.</returns>
  40. public static bool Invoke<T>(this IEnumerable<TimelineClip> clips) where T : ClipAction
  41. {
  42. var action = ActionManager.ClipActions.GetCachedAction<T, ClipAction>();
  43. return ActionManager.ExecuteClipAction(action, clips);
  44. }
  45. /// <summary>
  46. /// Execute a given action with markers
  47. /// </summary>
  48. /// <typeparam name="T">Action type to execute.</typeparam>
  49. /// <param name="markers">Markers that the action will act on.</param>
  50. /// <returns>True if the action has been executed, false otherwise.</returns>
  51. public static bool Invoke<T>(this IEnumerable<IMarker> markers) where T : MarkerAction
  52. {
  53. var action = ActionManager.MarkerActions.GetCachedAction<T, MarkerAction>();
  54. return ActionManager.ExecuteMarkerAction(action, markers);
  55. }
  56. /// <summary>
  57. /// Execute a given timeline action with the selected clips, tracks and markers.
  58. /// </summary>
  59. /// <typeparam name="T">Action type to execute.</typeparam>
  60. /// <returns>True if the action has been executed, false otherwise.</returns>
  61. public static bool InvokeWithSelected<T>() where T : TimelineAction
  62. {
  63. return Invoke<T>(TimelineEditor.CurrentContext());
  64. }
  65. /// <summary>
  66. /// Execute a given clip action with the selected clips.
  67. /// </summary>
  68. /// <typeparam name="T">Action type to execute.</typeparam>
  69. /// <returns>True if the action has been executed, false otherwise.</returns>
  70. public static bool InvokeWithSelectedClips<T>() where T : ClipAction
  71. {
  72. return Invoke<T>(SelectionManager.SelectedClips());
  73. }
  74. /// <summary>
  75. /// Execute a given track action with the selected tracks.
  76. /// </summary>
  77. /// <typeparam name="T">Action type to execute.</typeparam>
  78. /// <returns>True if the action has been executed, false otherwise.</returns>
  79. public static bool InvokeWithSelectedTracks<T>() where T : TrackAction
  80. {
  81. return Invoke<T>(SelectionManager.SelectedTracks());
  82. }
  83. /// <summary>
  84. /// Execute a given marker action with the selected markers.
  85. /// </summary>
  86. /// <typeparam name="T">Action type to execute.</typeparam>
  87. /// <returns>True if the action has been executed, false otherwise.</returns>
  88. public static bool InvokeWithSelectedMarkers<T>() where T : MarkerAction
  89. {
  90. return Invoke<T>(SelectionManager.SelectedMarkers());
  91. }
  92. }
  93. }