InspectorCommentDrawer.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace RootMotion
  4. {
  5. // Custom drawer for the LargeHeader attribute
  6. [CustomPropertyDrawer(typeof(InspectorComment))]
  7. public class InspectorCommentDrawer : DecoratorDrawer
  8. {
  9. // Used to calculate the height of the box
  10. public static Texture2D lineTex = null;
  11. private GUIStyle style;
  12. InspectorComment comment { get { return ((InspectorComment)attribute); } }
  13. // Get the height of the element
  14. public override float GetHeight()
  15. {
  16. style = GetStyle();
  17. return style.CalcHeight(new GUIContent(comment.name), EditorGUIUtility.currentViewWidth) + 10f;
  18. //return base.GetHeight() * 1.5f;
  19. }
  20. // Override the GUI drawing for this attribute
  21. public override void OnGUI(Rect pos)
  22. {
  23. // Get the color the line should be
  24. Color color = Color.white;
  25. switch (comment.color.ToString().ToLower())
  26. {
  27. case "white": color = Color.white; break;
  28. case "red": color = Color.red; break;
  29. case "blue": color = Color.blue; break;
  30. case "green": color = Color.green; break;
  31. case "gray": color = Color.gray; break;
  32. case "grey": color = Color.grey; break;
  33. case "black": color = Color.black; break;
  34. }
  35. color *= 0.5f;
  36. style = GetStyle();
  37. GUI.color = color;
  38. Rect labelRect = pos;
  39. //labelRect.y += 10;
  40. EditorGUI.LabelField(labelRect, new GUIContent(comment.name), style);
  41. GUI.color = Color.white;
  42. }
  43. private GUIStyle GetStyle()
  44. {
  45. var style = new GUIStyle(GUI.skin.label);
  46. style.fontSize = 10;
  47. style.fontStyle = FontStyle.Normal;
  48. style.wordWrap = true;
  49. style.alignment = TextAnchor.LowerLeft;
  50. return style;
  51. }
  52. }
  53. }