StyledInteractiveDrawer.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Cristian Pop - https://boxophobic.com/
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System;
  5. namespace Boxophobic.StyledGUI
  6. {
  7. public class StyledInteractiveDrawer : MaterialPropertyDrawer
  8. {
  9. public string keyword;
  10. public float value1 = -1f;
  11. public float value2 = -1f;
  12. public float value3 = -1f;
  13. protected int type;
  14. public StyledInteractiveDrawer(string k)
  15. {
  16. type = 0;
  17. keyword = k;
  18. }
  19. public StyledInteractiveDrawer(string k, float v1)
  20. {
  21. type = 1;
  22. keyword = k;
  23. value1 = v1;
  24. }
  25. public StyledInteractiveDrawer(string k, float v1, float v2)
  26. {
  27. type = 1;
  28. keyword = k;
  29. value1 = v1;
  30. value2 = v2;
  31. }
  32. public StyledInteractiveDrawer(string k, float v1, float v2, float v3)
  33. {
  34. type = 1;
  35. keyword = k;
  36. value1 = v1;
  37. value2 = v2;
  38. value3 = v3;
  39. }
  40. public override void OnGUI(Rect position, MaterialProperty prop, String label, MaterialEditor materialEditor)
  41. {
  42. Material material = materialEditor.target as Material;
  43. if (type == 1)
  44. {
  45. if (material.HasProperty(keyword))
  46. {
  47. if (value1 == material.GetFloat(keyword) || value2 == material.GetFloat(keyword) || value3 == material.GetFloat(keyword))
  48. {
  49. GUI.enabled = true;
  50. }
  51. else
  52. {
  53. GUI.enabled = false;
  54. }
  55. }
  56. }
  57. else if (type == 0)
  58. {
  59. if (keyword == "ON")
  60. {
  61. GUI.enabled = true;
  62. }
  63. else if (keyword == "OFF")
  64. {
  65. GUI.enabled = false;
  66. }
  67. else if (material.IsKeywordEnabled(keyword))
  68. {
  69. GUI.enabled = true;
  70. }
  71. else
  72. {
  73. GUI.enabled = false;
  74. }
  75. }
  76. }
  77. public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor)
  78. {
  79. return -2;
  80. }
  81. }
  82. }