PolyverseSkiesShaderGUI.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //Cristian Pop - https://boxophobic.com/
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.Collections.Generic;
  5. public class PolyverseSkiesShaderGUI : ShaderGUI
  6. {
  7. bool multiSelection = false;
  8. public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
  9. {
  10. //base.OnGUI(materialEditor, props);
  11. var material0 = materialEditor.target as Material;
  12. var materials = materialEditor.targets;
  13. if (materials.Length > 1)
  14. multiSelection = true;
  15. DrawDynamicInspector(material0, materialEditor, props);
  16. }
  17. void DrawDynamicInspector(Material material, MaterialEditor materialEditor, MaterialProperty[] props)
  18. {
  19. var customPropsList = new List<MaterialProperty>();
  20. if (multiSelection)
  21. {
  22. for (int i = 0; i < props.Length; i++)
  23. {
  24. var prop = props[i];
  25. if (prop.flags == MaterialProperty.PropFlags.HideInInspector)
  26. continue;
  27. customPropsList.Add(prop);
  28. }
  29. }
  30. else
  31. {
  32. for (int i = 0; i < props.Length; i++)
  33. {
  34. var prop = props[i];
  35. if (prop.flags == MaterialProperty.PropFlags.HideInInspector)
  36. {
  37. continue;
  38. }
  39. if (material.HasProperty("_BackgroundMode"))
  40. {
  41. if (material.GetInt("_BackgroundMode") == 0 && prop.name == "_BackgroundCubemapSpace")
  42. continue;
  43. if (material.GetInt("_BackgroundMode") == 0 && prop.name == "_BackgroundCubemap")
  44. continue;
  45. if (material.GetInt("_BackgroundMode") == 0 && prop.name == "_BackgroundExposure")
  46. continue;
  47. if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_SkyColor")
  48. continue;
  49. if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_EquatorColor")
  50. continue;
  51. if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_GroundColor")
  52. continue;
  53. if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_EquatorHeight")
  54. continue;
  55. if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_EquatorSmoothness")
  56. continue;
  57. }
  58. customPropsList.Add(prop);
  59. }
  60. }
  61. //Draw Custom GUI
  62. for (int i = 0; i < customPropsList.Count; i++)
  63. {
  64. var prop = customPropsList[i];
  65. if (prop.type == MaterialProperty.PropType.Texture)
  66. {
  67. EditorGUI.BeginChangeCheck();
  68. EditorGUI.showMixedValue = prop.hasMixedValue;
  69. Texture tex = null;
  70. if (prop.textureDimension == UnityEngine.Rendering.TextureDimension.Tex2D)
  71. {
  72. tex = (Texture2D)EditorGUILayout.ObjectField(prop.displayName, prop.textureValue, typeof(Texture2D), false, GUILayout.Height(50));
  73. }
  74. if (prop.textureDimension == UnityEngine.Rendering.TextureDimension.Cube)
  75. {
  76. tex = (Cubemap)EditorGUILayout.ObjectField(prop.displayName, prop.textureValue, typeof(Cubemap), false, GUILayout.Height(50));
  77. }
  78. EditorGUI.showMixedValue = false;
  79. if (EditorGUI.EndChangeCheck())
  80. {
  81. prop.textureValue = tex;
  82. }
  83. }
  84. else
  85. {
  86. materialEditor.ShaderProperty(customPropsList[i], customPropsList[i].displayName);
  87. }
  88. }
  89. GUILayout.Space(10);
  90. }
  91. }