BHeaderDrawer.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace HQFPSWeapons
  4. {
  5. [CustomPropertyDrawer(typeof(BHeader))]
  6. public class BHeaderDrawer : DecoratorDrawer
  7. {
  8. private const float k_HeaderSpacing = 10f;
  9. public override void OnGUI(Rect position)
  10. {
  11. var attr = (BHeader)attribute;
  12. var indentedRect = EditorGUI.IndentedRect(new Rect(position.x, position.y - (attr.IsTitle ? 5f : 4f), position.width, position.height));
  13. Vector2 textSize = EditorStyles.boldLabel.CalcSize(new GUIContent(attr.Name));
  14. Color prevColor = GUI.color;
  15. if (attr.IsTitle)
  16. {
  17. GUI.backgroundColor = EditorGUICustom.HighlightColor2;
  18. GUI.Box(new Rect(indentedRect.x, indentedRect.y + indentedRect.height * 0.5f - 3f, indentedRect.width, textSize.y * 1.2f), "");
  19. GUI.backgroundColor = prevColor;
  20. indentedRect.position += Vector2.up * indentedRect.height * 0.45f;
  21. GUI.Label(indentedRect, attr.Name, EditorGUICustom.CenteredBoldMiniLabel);
  22. }
  23. else
  24. {
  25. GUI.backgroundColor = EditorGUICustom.HighlightColor1;
  26. Rect newRect = new Rect(indentedRect.x, indentedRect.y + indentedRect.height * 0.5f - 3f, textSize.x + 16f, textSize.y * 1.1f);
  27. GUI.Box(newRect, "");
  28. GUI.backgroundColor = prevColor;
  29. indentedRect.position += Vector2.up * indentedRect.height * 0.45f;
  30. indentedRect.x += 4f;
  31. GUI.Label(newRect, attr.Name, EditorGUICustom.CenteredBoldMiniLabel);
  32. }
  33. GUI.color = prevColor;
  34. }
  35. public override float GetHeight()
  36. {
  37. var attr = (BHeader)attribute;
  38. if (!attr.IsTitle)
  39. return base.GetHeight() + k_HeaderSpacing - 5;
  40. else
  41. return base.GetHeight() + k_HeaderSpacing + 5;
  42. }
  43. }
  44. }