Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

OverlayDrawer.cs 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.Timeline
  4. {
  5. readonly struct OverlayDrawer
  6. {
  7. enum OverlayType
  8. {
  9. BackgroundColor,
  10. BackgroundTexture,
  11. TextBox
  12. }
  13. readonly OverlayType m_Type;
  14. readonly Rect m_Rect;
  15. readonly string m_Text;
  16. readonly Texture2D m_Texture;
  17. readonly Color m_Color;
  18. readonly GUIStyle m_BackgroundTextStyle;
  19. readonly GUIStyle m_TextStyle;
  20. OverlayDrawer(Rect rectangle, Color backgroundColor)
  21. {
  22. m_Type = OverlayType.BackgroundColor;
  23. m_Rect = rectangle;
  24. m_Color = backgroundColor;
  25. m_Text = string.Empty;
  26. m_Texture = null;
  27. m_BackgroundTextStyle = null;
  28. m_TextStyle = null;
  29. }
  30. OverlayDrawer(Rect rectangle, Texture2D backTexture)
  31. {
  32. m_Type = OverlayType.BackgroundTexture;
  33. m_Rect = rectangle;
  34. m_Color = Color.clear;
  35. m_Text = string.Empty;
  36. m_Texture = backTexture;
  37. m_BackgroundTextStyle = null;
  38. m_TextStyle = null;
  39. }
  40. OverlayDrawer(Rect rectangle, string msg, GUIStyle textStyle, Color textColor, Color bgTextColor, GUIStyle bgTextStyle)
  41. {
  42. m_Type = OverlayType.TextBox;
  43. m_Rect = rectangle;
  44. m_Text = msg;
  45. m_TextStyle = textStyle;
  46. m_TextStyle.normal.textColor = textColor;
  47. m_BackgroundTextStyle = bgTextStyle;
  48. m_BackgroundTextStyle.normal.textColor = bgTextColor;
  49. m_Texture = null;
  50. m_Color = Color.clear;
  51. }
  52. public static OverlayDrawer CreateColorOverlay(Rect rectangle, Color backgroundColor)
  53. {
  54. return new OverlayDrawer(rectangle, backgroundColor);
  55. }
  56. public static OverlayDrawer CreateTextureOverlay(Rect rectangle, Texture2D backTexture)
  57. {
  58. return new OverlayDrawer(rectangle, backTexture);
  59. }
  60. public static OverlayDrawer CreateTextBoxOverlay(Rect rectangle, string msg, GUIStyle textStyle, Color textColor, Color bgTextColor, GUIStyle bgTextStyle)
  61. {
  62. return new OverlayDrawer(rectangle, msg, textStyle, textColor, bgTextColor, bgTextStyle);
  63. }
  64. public void Draw()
  65. {
  66. Rect overlayRect = GUIClip.Clip(m_Rect);
  67. switch (m_Type)
  68. {
  69. case OverlayType.BackgroundColor:
  70. EditorGUI.DrawRect(overlayRect, m_Color);
  71. break;
  72. case OverlayType.BackgroundTexture:
  73. Graphics.DrawTextureRepeated(overlayRect, m_Texture);
  74. break;
  75. case OverlayType.TextBox:
  76. {
  77. using (new GUIColorOverride(m_BackgroundTextStyle.normal.textColor))
  78. GUI.Box(overlayRect, GUIContent.none, m_BackgroundTextStyle);
  79. Graphics.ShadowLabel(overlayRect, GUIContent.Temp(m_Text), m_TextStyle, m_TextStyle.normal.textColor, Color.black);
  80. break;
  81. }
  82. }
  83. }
  84. }
  85. }