PickerUtils.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using UnityEngine;
  4. namespace UnityEditor.Timeline
  5. {
  6. static class PickerUtils
  7. {
  8. public static List<object> pickedElements { get; private set; }
  9. public static void DoPick(WindowState state, Vector2 mousePosition)
  10. {
  11. if (state.GetWindow().sequenceContentRect.Contains(mousePosition))
  12. {
  13. pickedElements = state.spacePartitioner.GetItemsAtPosition<object>(mousePosition).ToList();
  14. }
  15. else
  16. {
  17. if (pickedElements != null)
  18. pickedElements.Clear();
  19. else
  20. pickedElements = new List<object>();
  21. }
  22. }
  23. public static T PickedLayerableOfType<T>() where T : class, ILayerable
  24. {
  25. return pickedElements.OfType<ILayerable>().OrderBy(x => x.zOrder).LastOrDefault() as T;
  26. }
  27. public static InlineCurveResizeHandle PickedInlineCurveResizer()
  28. {
  29. return pickedElements.FirstOrDefault(e => e is InlineCurveResizeHandle) as InlineCurveResizeHandle;
  30. }
  31. public static TimelineTrackBaseGUI PickedTrackBaseGUI()
  32. {
  33. return pickedElements.FirstOrDefault(e => e is TimelineTrackBaseGUI) as TimelineTrackBaseGUI;
  34. }
  35. }
  36. }