Ei kuvausta
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.

ReplaceAnnotationDescriptionAction.cs 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEditor;
  5. using UnityEditor.Timeline.Actions;
  6. using UnityEngine;
  7. using UnityEngine.Timeline;
  8. namespace Timeline.Samples
  9. {
  10. // Adds an additional item in context menus that will replace an annotation's description field
  11. // with the clipboard's contents.
  12. [MenuEntry("Replace description with clipboard contents")]
  13. public class ReplaceAnnotationDescriptionAction : MarkerAction
  14. {
  15. // Specifies the action's prerequisites:
  16. // - Invalid (grayed out in the menu) if no text content is in the clipboard;
  17. // - NotApplicable (not shown in the menu) if the current marker is not an Annotation.
  18. public override ActionValidity Validate(IEnumerable<IMarker> markers)
  19. {
  20. if (!markers.All(marker => marker is AnnotationMarker))
  21. {
  22. return ActionValidity.NotApplicable;
  23. }
  24. // get the current text content of the clipboard
  25. string clipboardTextContent = EditorGUIUtility.systemCopyBuffer;
  26. if (clipboardTextContent.Length == 0)
  27. {
  28. return ActionValidity.Invalid;
  29. }
  30. return ActionValidity.Valid;
  31. }
  32. // Sets the Annotation's description based on the contents of the clipboard.
  33. public override bool Execute(IEnumerable<IMarker> markers)
  34. {
  35. // get the current text content of the clipboard
  36. string clipboardTextContent = EditorGUIUtility.systemCopyBuffer;
  37. foreach (AnnotationMarker annotation in markers.Cast<AnnotationMarker>())
  38. {
  39. annotation.description = clipboardTextContent;
  40. }
  41. return true;
  42. }
  43. // Assigns a shortcut to the action.
  44. [TimelineShortcut("Replace annotation description with clipboard", KeyCode.D)]
  45. public static void InvokeShortcut()
  46. {
  47. Invoker.InvokeWithSelectedMarkers<ReplaceAnnotationDescriptionAction>();
  48. }
  49. }
  50. }