Tooltip.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using UnityEngine;
  2. namespace UnityEditor.Timeline
  3. {
  4. class Tooltip
  5. {
  6. public GUIStyle style { get; set; }
  7. public string text { get; set; }
  8. GUIStyle m_Font;
  9. public GUIStyle font
  10. {
  11. get
  12. {
  13. if (m_Font != null)
  14. return m_Font;
  15. if (style != null)
  16. return style;
  17. // Default Font.
  18. m_Font = new GUIStyle();
  19. m_Font.font = EditorStyles.label.font;
  20. return m_Font;
  21. }
  22. set { m_Font = value; }
  23. }
  24. float m_Pad = 4.0f;
  25. public float pad
  26. {
  27. get { return m_Pad; }
  28. set { m_Pad = value; }
  29. }
  30. GUIContent m_TextContent;
  31. GUIContent textContent
  32. {
  33. get
  34. {
  35. if (m_TextContent == null)
  36. m_TextContent = new GUIContent();
  37. m_TextContent.text = text;
  38. return m_TextContent;
  39. }
  40. }
  41. Color m_ForeColor = Color.white;
  42. public Color foreColor
  43. {
  44. get { return m_ForeColor; }
  45. set { m_ForeColor = value; }
  46. }
  47. Rect m_Bounds;
  48. public Rect bounds
  49. {
  50. get
  51. {
  52. var size = font.CalcSize(textContent);
  53. m_Bounds.width = size.x + (2.0f * pad);
  54. m_Bounds.height = size.y + 2.0f;
  55. return m_Bounds;
  56. }
  57. set { m_Bounds = value; }
  58. }
  59. public Tooltip(GUIStyle theStyle, GUIStyle font)
  60. {
  61. style = theStyle;
  62. m_Font = font;
  63. }
  64. public Tooltip()
  65. {
  66. style = null;
  67. m_Font = null;
  68. }
  69. public void Draw()
  70. {
  71. if (string.IsNullOrEmpty(text))
  72. return;
  73. if (style != null)
  74. {
  75. using (new GUIColorOverride(DirectorStyles.Instance.customSkin.colorTooltipBackground))
  76. GUI.Label(bounds, GUIContent.none, style);
  77. }
  78. var textBounds = bounds;
  79. textBounds.x += pad;
  80. textBounds.width -= pad;
  81. using (new GUIColorOverride(foreColor))
  82. GUI.Label(textBounds, textContent, font);
  83. }
  84. }
  85. }