1
0

StyledTextDrawer.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Cristian Pop - https://boxophobic.com/
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System;
  5. namespace Boxophobic.StyledGUI
  6. {
  7. public class StyledTextDrawer : MaterialPropertyDrawer
  8. {
  9. public string text = "";
  10. public string alignment = "Center";
  11. public string font = "Normal";
  12. public string disabled = "";
  13. public float size = 11;
  14. public float top = 0;
  15. public float down = 0;
  16. public StyledTextDrawer(string text)
  17. {
  18. this.text = text;
  19. }
  20. public StyledTextDrawer(string text, string alignment, string font, string disabled, float size)
  21. {
  22. this.text = text;
  23. this.alignment = alignment;
  24. this.font = font;
  25. this.disabled = disabled;
  26. this.size = size;
  27. }
  28. public StyledTextDrawer(string text, string alignment, string font, string disabled, float size, float top, float down)
  29. {
  30. this.text = text;
  31. this.alignment = alignment;
  32. this.font = font;
  33. this.disabled = disabled;
  34. this.size = size;
  35. this.top = top;
  36. this.down = down;
  37. }
  38. public override void OnGUI(Rect position, MaterialProperty prop, String label, MaterialEditor materialEditor)
  39. {
  40. //Material material = materialEditor.target as Material;
  41. GUIStyle styleLabel = new GUIStyle(EditorStyles.label)
  42. {
  43. richText = true,
  44. alignment = TextAnchor.MiddleCenter,
  45. wordWrap = true
  46. };
  47. GUILayout.Space(top);
  48. if (alignment == "Center")
  49. {
  50. styleLabel.alignment = TextAnchor.MiddleCenter;
  51. }
  52. else if (alignment == "Left")
  53. {
  54. styleLabel.alignment = TextAnchor.MiddleLeft;
  55. }
  56. else if (alignment == "Right")
  57. {
  58. styleLabel.alignment = TextAnchor.MiddleRight;
  59. }
  60. if (font == "Normal")
  61. {
  62. styleLabel.fontStyle = FontStyle.Normal;
  63. }
  64. else if (font == "Bold")
  65. {
  66. styleLabel.fontStyle = FontStyle.Bold;
  67. }
  68. else if (font == "Italic")
  69. {
  70. styleLabel.fontStyle = FontStyle.Italic;
  71. }
  72. else if (font == "BoldAndItalic")
  73. {
  74. styleLabel.fontStyle = FontStyle.BoldAndItalic;
  75. }
  76. styleLabel.fontSize = (int)size;
  77. if (disabled == "Disabled")
  78. {
  79. GUI.enabled = false;
  80. }
  81. GUILayout.Label(text, styleLabel);
  82. GUI.enabled = true;
  83. GUILayout.Space(down);
  84. }
  85. public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor)
  86. {
  87. return -2;
  88. }
  89. }
  90. }