TimeIndicator.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using UnityEngine;
  2. namespace UnityEditor.Timeline
  3. {
  4. static class TimeIndicator
  5. {
  6. static readonly Tooltip s_Tooltip = new Tooltip(DirectorStyles.Instance.displayBackground, DirectorStyles.Instance.tinyFont);
  7. public static void Draw(WindowState state, double time)
  8. {
  9. var bounds = state.timeAreaRect;
  10. bounds.xMin = Mathf.Max(bounds.xMin, state.TimeToTimeAreaPixel(time));
  11. using (new GUIViewportScope(state.timeAreaRect))
  12. {
  13. s_Tooltip.text = TimeReferenceUtility.ToTimeString(time);
  14. var tooltipBounds = s_Tooltip.bounds;
  15. tooltipBounds.xMin = bounds.xMin - (tooltipBounds.width / 2.0f);
  16. tooltipBounds.y = bounds.y;
  17. s_Tooltip.bounds = tooltipBounds;
  18. if (time >= 0)
  19. s_Tooltip.Draw();
  20. }
  21. if (time >= 0)
  22. {
  23. Graphics.DrawLineAtTime(state, time, Color.black, true);
  24. }
  25. }
  26. public static void Draw(WindowState state, double start, double end)
  27. {
  28. var bounds = state.timeAreaRect;
  29. bounds.xMin = Mathf.Max(bounds.xMin, state.TimeToTimeAreaPixel(start));
  30. bounds.xMax = Mathf.Min(bounds.xMax, state.TimeToTimeAreaPixel(end));
  31. var color = DirectorStyles.Instance.selectedStyle.focused.textColor;
  32. color.a = 0.12f;
  33. EditorGUI.DrawRect(bounds, color);
  34. Draw(state, start);
  35. Draw(state, end);
  36. }
  37. }
  38. }