123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- //Cristian Pop - https://boxophobic.com/
- using UnityEngine;
- using UnityEditor;
- using System.Collections.Generic;
- public class PolyverseSkiesShaderGUI : ShaderGUI
- {
- bool multiSelection = false;
- public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
- {
- //base.OnGUI(materialEditor, props);
- var material0 = materialEditor.target as Material;
- var materials = materialEditor.targets;
- if (materials.Length > 1)
- multiSelection = true;
-
- DrawDynamicInspector(material0, materialEditor, props);
- }
- void DrawDynamicInspector(Material material, MaterialEditor materialEditor, MaterialProperty[] props)
- {
- var customPropsList = new List<MaterialProperty>();
- if (multiSelection)
- {
- for (int i = 0; i < props.Length; i++)
- {
- var prop = props[i];
- if (prop.flags == MaterialProperty.PropFlags.HideInInspector)
- continue;
- customPropsList.Add(prop);
- }
- }
- else
- {
- for (int i = 0; i < props.Length; i++)
- {
- var prop = props[i];
- if (prop.flags == MaterialProperty.PropFlags.HideInInspector)
- {
- continue;
- }
- if (material.HasProperty("_BackgroundMode"))
- {
- if (material.GetInt("_BackgroundMode") == 0 && prop.name == "_BackgroundCubemapSpace")
- continue;
- if (material.GetInt("_BackgroundMode") == 0 && prop.name == "_BackgroundCubemap")
- continue;
- if (material.GetInt("_BackgroundMode") == 0 && prop.name == "_BackgroundExposure")
- continue;
- if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_SkyColor")
- continue;
- if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_EquatorColor")
- continue;
- if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_GroundColor")
- continue;
- if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_EquatorHeight")
- continue;
- if (material.GetInt("_BackgroundMode") == 1 && prop.name == "_EquatorSmoothness")
- continue;
- }
- customPropsList.Add(prop);
- }
- }
- //Draw Custom GUI
- for (int i = 0; i < customPropsList.Count; i++)
- {
- var prop = customPropsList[i];
- if (prop.type == MaterialProperty.PropType.Texture)
- {
- EditorGUI.BeginChangeCheck();
- EditorGUI.showMixedValue = prop.hasMixedValue;
- Texture tex = null;
- if (prop.textureDimension == UnityEngine.Rendering.TextureDimension.Tex2D)
- {
- tex = (Texture2D)EditorGUILayout.ObjectField(prop.displayName, prop.textureValue, typeof(Texture2D), false, GUILayout.Height(50));
- }
- if (prop.textureDimension == UnityEngine.Rendering.TextureDimension.Cube)
- {
- tex = (Cubemap)EditorGUILayout.ObjectField(prop.displayName, prop.textureValue, typeof(Cubemap), false, GUILayout.Height(50));
- }
- EditorGUI.showMixedValue = false;
- if (EditorGUI.EndChangeCheck())
- {
- prop.textureValue = tex;
- }
- }
- else
- {
- materialEditor.ShaderProperty(customPropsList[i], customPropsList[i].displayName);
- }
- }
- GUILayout.Space(10);
- }
- }
|