暫無描述
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.

Graphics.cs 4.2KB

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