SkyboxExtendedShaderGUI.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //Cristian Pop - https://boxophobic.com/
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.Collections.Generic;
  5. public class SkyboxExtendedShaderGUI : ShaderGUI
  6. {
  7. public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
  8. {
  9. //base.OnGUI(materialEditor, props);
  10. var material0 = materialEditor.target as Material;
  11. DrawDynamicInspector(material0, materialEditor, props);
  12. }
  13. void DrawDynamicInspector(Material material, MaterialEditor materialEditor, MaterialProperty[] props)
  14. {
  15. var customPropsList = new List<MaterialProperty>();
  16. for (int i = 0; i < props.Length; i++)
  17. {
  18. var prop = props[i];
  19. if (prop.flags == MaterialProperty.PropFlags.HideInInspector)
  20. continue;
  21. customPropsList.Add(prop);
  22. }
  23. //Draw Custom GUI
  24. for (int i = 0; i < customPropsList.Count; i++)
  25. {
  26. var prop = customPropsList[i];
  27. if (prop.type == MaterialProperty.PropType.Texture)
  28. {
  29. EditorGUI.BeginChangeCheck();
  30. EditorGUI.showMixedValue = prop.hasMixedValue;
  31. Texture tex = null;
  32. if (prop.textureDimension == UnityEngine.Rendering.TextureDimension.Tex2D)
  33. {
  34. tex = (Texture2D)EditorGUILayout.ObjectField(prop.displayName, prop.textureValue, typeof(Texture2D), false, GUILayout.Height(50));
  35. }
  36. if (prop.textureDimension == UnityEngine.Rendering.TextureDimension.Cube)
  37. {
  38. tex = (Cubemap)EditorGUILayout.ObjectField(prop.displayName, prop.textureValue, typeof(Cubemap), false, GUILayout.Height(50));
  39. }
  40. EditorGUI.showMixedValue = false;
  41. if (EditorGUI.EndChangeCheck())
  42. {
  43. prop.textureValue = tex;
  44. }
  45. }
  46. else
  47. {
  48. materialEditor.ShaderProperty(customPropsList[i], customPropsList[i].displayName);
  49. }
  50. }
  51. GUILayout.Space(10);
  52. }
  53. }