StyledMessageDrawer.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Cristian Pop - https://boxophobic.com/
  2. using UnityEngine;
  3. using UnityEditor;
  4. namespace Boxophobic.StyledGUI
  5. {
  6. [CustomPropertyDrawer(typeof(StyledMessage))]
  7. public class StyledMessageAttributeDrawer : PropertyDrawer
  8. {
  9. StyledMessage a;
  10. bool show;
  11. MessageType messageType;
  12. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  13. {
  14. show = property.boolValue;
  15. if (show)
  16. {
  17. a = (StyledMessage)attribute;
  18. if (a.Type == "None")
  19. {
  20. messageType = MessageType.None;
  21. }
  22. else if (a.Type == "Info")
  23. {
  24. messageType = MessageType.Info;
  25. }
  26. else if (a.Type == "Warning")
  27. {
  28. messageType = MessageType.Warning;
  29. }
  30. else if (a.Type == "Error")
  31. {
  32. messageType = MessageType.Error;
  33. }
  34. GUILayout.Space(a.Top);
  35. EditorGUILayout.HelpBox(a.Message, messageType);
  36. GUILayout.Space(a.Down);
  37. }
  38. }
  39. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  40. {
  41. return -2;
  42. }
  43. }
  44. }