StyledTextureDrawer.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Cristian Pop - https://boxophobic.com/
  2. using UnityEngine;
  3. using UnityEditor;
  4. namespace Boxophobic.StyledGUI
  5. {
  6. public class StyledTextureDrawer : MaterialPropertyDrawer
  7. {
  8. public float size;
  9. public float top;
  10. public float down;
  11. public StyledTextureDrawer()
  12. {
  13. this.size = 50;
  14. this.top = 0;
  15. this.down = 0;
  16. }
  17. public StyledTextureDrawer(float size)
  18. {
  19. this.size = size;
  20. this.top = 0;
  21. this.down = 0;
  22. }
  23. public StyledTextureDrawer(float size, float top, float down)
  24. {
  25. this.size = size;
  26. this.top = top;
  27. this.down = down;
  28. }
  29. public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor materialEditor)
  30. {
  31. GUILayout.Space(top);
  32. EditorGUI.BeginChangeCheck();
  33. EditorGUI.showMixedValue = prop.hasMixedValue;
  34. Texture tex = null;
  35. if (prop.textureDimension == UnityEngine.Rendering.TextureDimension.Tex2D)
  36. {
  37. tex = (Texture2D)EditorGUILayout.ObjectField(prop.displayName, prop.textureValue, typeof(Texture2D), false, GUILayout.Height(50));
  38. }
  39. if (prop.textureDimension == UnityEngine.Rendering.TextureDimension.Cube)
  40. {
  41. tex = (Cubemap)EditorGUILayout.ObjectField(prop.displayName, prop.textureValue, typeof(Cubemap), false, GUILayout.Height(50));
  42. }
  43. EditorGUI.showMixedValue = false;
  44. if (EditorGUI.EndChangeCheck())
  45. {
  46. prop.textureValue = tex;
  47. }
  48. GUILayout.Space(down);
  49. }
  50. public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor)
  51. {
  52. return -2;
  53. }
  54. }
  55. }