StyledMessageDrawer.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Cristian Pop - https://boxophobic.com/
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System;
  5. namespace Boxophobic.StyledGUI
  6. {
  7. public class StyledMessageDrawer : MaterialPropertyDrawer
  8. {
  9. public string type;
  10. public string message;
  11. public string keyword;
  12. public float value;
  13. public float top;
  14. public float down;
  15. MessageType mType;
  16. public StyledMessageDrawer(string t, string m)
  17. {
  18. type = t;
  19. message = m;
  20. keyword = null;
  21. this.top = 0;
  22. this.down = 0;
  23. }
  24. public StyledMessageDrawer(string t, string m, float top, float down)
  25. {
  26. type = t;
  27. message = m;
  28. keyword = null;
  29. this.top = top;
  30. this.down = down;
  31. }
  32. public StyledMessageDrawer(string t, string m, string k, float v, float top, float down)
  33. {
  34. type = t;
  35. message = m;
  36. keyword = k;
  37. value = v;
  38. this.top = top;
  39. this.down = down;
  40. }
  41. public override void OnGUI(Rect position, MaterialProperty prop, String label, MaterialEditor materialEditor)
  42. {
  43. Material material = materialEditor.target as Material;
  44. if (type == "None")
  45. {
  46. mType = MessageType.None;
  47. }
  48. else if (type == "Info")
  49. {
  50. mType = MessageType.Info;
  51. }
  52. else if (type == "Warning")
  53. {
  54. mType = MessageType.Warning;
  55. }
  56. else if (type == "Error")
  57. {
  58. mType = MessageType.Error;
  59. }
  60. if (keyword != null)
  61. {
  62. if (material.HasProperty(keyword))
  63. {
  64. if (material.GetFloat(keyword) == value)
  65. {
  66. GUILayout.Space(top);
  67. //EditorGUI.DrawRect(new Rect(position.x, position.y + Top, position.width, position.height), new Color(1,0,0,0.3f));
  68. EditorGUILayout.HelpBox(message, mType);
  69. //EditorGUI.HelpBox(new Rect(position.x, position.y + top, position.width, position.height), message, mType);
  70. GUILayout.Space(down);
  71. }
  72. }
  73. }
  74. else
  75. {
  76. GUILayout.Space(top);
  77. EditorGUILayout.HelpBox(message, mType);
  78. GUILayout.Space(down);
  79. }
  80. }
  81. public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor)
  82. {
  83. return -2;
  84. }
  85. }
  86. }