StyledButtonDrawer.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Cristian Pop - https://boxophobic.com/
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System;
  5. namespace Boxophobic.StyledGUI
  6. {
  7. public class StyledButtonDrawer : MaterialPropertyDrawer
  8. {
  9. public string text;
  10. public string target = "";
  11. public float value = 1;
  12. public float top;
  13. public float down;
  14. public StyledButtonDrawer(string text)
  15. {
  16. this.text = text;
  17. this.value = 1;
  18. this.top = 0;
  19. this.down = 0;
  20. }
  21. public StyledButtonDrawer(string text, float value, float top, float down)
  22. {
  23. this.text = text;
  24. this.value = value;
  25. this.top = top;
  26. this.down = down;
  27. }
  28. public StyledButtonDrawer(string text, string target, float value, float top, float down)
  29. {
  30. this.text = text;
  31. this.target = target;
  32. this.value = value;
  33. this.top = top;
  34. this.down = down;
  35. }
  36. public override void OnGUI(Rect position, MaterialProperty prop, String label, MaterialEditor materialEditor)
  37. {
  38. Material material = materialEditor.target as Material;
  39. GUILayout.Space(top);
  40. if (GUILayout.Button(text))
  41. {
  42. if (target == "")
  43. {
  44. prop.floatValue = value;
  45. }
  46. else
  47. {
  48. if (material.HasProperty(target))
  49. {
  50. material.SetFloat(target, value);
  51. }
  52. }
  53. }
  54. GUILayout.Space(down);
  55. }
  56. public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor)
  57. {
  58. return -2;
  59. }
  60. }
  61. }