TimelineItemGUI.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine.Timeline;
  4. using UnityEngine;
  5. namespace UnityEditor.Timeline
  6. {
  7. static class ItemToItemGui
  8. {
  9. static Dictionary<object, TimelineItemGUI> s_ItemToItemGUI =
  10. new Dictionary<object, TimelineItemGUI>();
  11. public static void Add(TimelineClip clip, TimelineItemGUI gui)
  12. {
  13. s_ItemToItemGUI[clip] = gui;
  14. }
  15. public static void Add(IMarker marker, TimelineItemGUI gui)
  16. {
  17. s_ItemToItemGUI[marker] = gui;
  18. }
  19. public static TimelineClipGUI GetGuiForClip(TimelineClip clip)
  20. {
  21. return GetGuiForItem(clip) as TimelineClipGUI;
  22. }
  23. public static TimelineMarkerGUI GetGuiForMarker(IMarker marker)
  24. {
  25. return GetGuiForItem(marker) as TimelineMarkerGUI;
  26. }
  27. static TimelineItemGUI GetGuiForItem(object item)
  28. {
  29. if (item == null)
  30. return null;
  31. TimelineItemGUI gui;
  32. s_ItemToItemGUI.TryGetValue(item, out gui);
  33. return gui;
  34. }
  35. }
  36. abstract class TimelineItemGUI : ISelectable
  37. {
  38. protected readonly DirectorStyles m_Styles;
  39. public abstract ITimelineItem item { get; }
  40. public abstract double start { get; }
  41. public abstract double end { get; }
  42. public abstract void Draw(Rect rect, bool rectChanged, WindowState state);
  43. public abstract Rect RectToTimeline(Rect trackRect, WindowState state);
  44. public virtual void Select() {}
  45. public virtual bool IsSelected() { return false; }
  46. public virtual void Deselect() {}
  47. public virtual void StartDrag() {}
  48. public virtual void StopDrag() {}
  49. public LayerZOrder zOrder { get; set; }
  50. public bool visible { get; set; }
  51. public bool isInvalid { get; set; }
  52. public IRowGUI parent { get; }
  53. public Rect rect
  54. {
  55. get { return parent.ToWindowSpace(treeViewRect); }
  56. }
  57. public Rect treeViewRect
  58. {
  59. get { return m_TreeViewRect; }
  60. protected set
  61. {
  62. m_TreeViewRect = value;
  63. if (value.width < 0.0f)
  64. m_TreeViewRect.width = 1.0f;
  65. }
  66. }
  67. Rect m_TreeViewRect;
  68. protected TimelineItemGUI(IRowGUI parent)
  69. {
  70. this.parent = parent;
  71. m_Styles = DirectorStyles.Instance;
  72. }
  73. }
  74. }