Graphics.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using UnityEngine;
  2. namespace UnityEditor.Timeline
  3. {
  4. static class Graphics
  5. {
  6. public static void ShadowLabel(Rect rect, string text, GUIStyle style, Color textColor, Color shadowColor)
  7. {
  8. ShadowLabel(rect, GUIContent.Temp(text), style, textColor, shadowColor);
  9. }
  10. public static void ShadowLabel(Rect rect, GUIContent content, GUIStyle style, Color textColor, Color shadowColor)
  11. {
  12. var shadowRect = rect;
  13. shadowRect.xMin += 2.0f;
  14. shadowRect.yMin += 2.0f;
  15. style.normal.textColor = Color.black;
  16. GUI.Label(shadowRect, content, style);
  17. style.normal.textColor = textColor;
  18. GUI.Label(rect, content, style);
  19. }
  20. public static void DrawLine(Vector3 p1, Vector3 p2, Color color)
  21. {
  22. var c = Handles.color;
  23. Handles.color = color;
  24. Handles.DrawLine(p1, p2);
  25. Handles.color = c;
  26. }
  27. public static void DrawPolygonAA(Color color, Vector3[] vertices)
  28. {
  29. var prevColor = Handles.color;
  30. Handles.color = color;
  31. Handles.DrawAAConvexPolygon(vertices);
  32. Handles.color = prevColor;
  33. }
  34. public static void DrawDottedLine(Vector3 p1, Vector3 p2, float segmentsLength, Color col)
  35. {
  36. HandleUtility.ApplyWireMaterial();
  37. GL.Begin(GL.LINES);
  38. GL.Color(col);
  39. var length = Vector3.Distance(p1, p2); // ignore z component
  40. var count = Mathf.CeilToInt(length / segmentsLength);
  41. for (var i = 0; i < count; i += 2)
  42. {
  43. GL.Vertex((Vector3.Lerp(p1, p2, i * segmentsLength / length)));
  44. GL.Vertex((Vector3.Lerp(p1, p2, (i + 1) * segmentsLength / length)));
  45. }
  46. GL.End();
  47. }
  48. public static void DrawLineAtTime(WindowState state, double time, Color color, bool dotted = false)
  49. {
  50. var t = state.TimeToPixel(time);
  51. var p0 = new Vector3(t, state.timeAreaRect.yMax);
  52. var p1 = new Vector3(t, state.timeAreaRect.yMax + state.windowHeight - WindowConstants.sliderWidth);
  53. if (dotted)
  54. DrawDottedLine(p0, p1, 4.0f, color);
  55. else
  56. DrawLine(p0, p1, color);
  57. }
  58. public static void DrawTextureRepeated(Rect area, Texture texture)
  59. {
  60. if (texture == null || Event.current.type != EventType.Repaint)
  61. return;
  62. GUI.BeginClip(area);
  63. int w = Mathf.CeilToInt(area.width / texture.width);
  64. int h = Mathf.CeilToInt(area.height / texture.height);
  65. for (int x = 0; x < w; x++)
  66. {
  67. for (int y = 0; y < h; y++)
  68. {
  69. GUI.DrawTexture(new Rect(x * texture.width, y * texture.height, texture.width, texture.height), texture);
  70. }
  71. }
  72. GUI.EndClip();
  73. }
  74. public static void DrawShadow(Rect clientRect)
  75. {
  76. var rect = clientRect;
  77. rect.height = WindowConstants.shadowUnderTimelineHeight;
  78. GUI.Box(rect, GUIContent.none, DirectorStyles.Instance.bottomShadow);
  79. }
  80. public static void DrawBackgroundRect(WindowState state, Rect rect, bool subSequenceMode = false)
  81. {
  82. Color c = subSequenceMode ? DirectorStyles.Instance.customSkin.colorSubSequenceBackground : DirectorStyles.Instance.customSkin.colorSequenceBackground;
  83. EditorGUI.DrawRect(rect, c);
  84. if (state.IsEditingAPrefabAsset())
  85. {
  86. c = SceneView.kSceneViewPrefabBackground.Color;
  87. c.a = 0.5f;
  88. EditorGUI.DrawRect(rect, c);
  89. }
  90. }
  91. }
  92. }