using System.Collections.Generic; using UnityEditor; using UnityEngine; namespace Plugins.Animate_UI_Materials.Editor { using PropertyType = ShaderUtil.ShaderPropertyType; internal class ShaderPropertyInfo { /// /// The index of the property inside the shader /// public int index; /// /// The name of the property inside the shader /// public string name; /// /// The type of the property, as defined by ShaderUtil /// public PropertyType type; /// /// Get all properties from a shader, with their name, index, and type /// /// The shader to get the properties from /// Include properties marked as hidden and _MainTex /// public static List GetShaderProperties(Shader shader, bool allowHidden = false) { List properties = new List(); int propertyCount = ShaderUtil.GetPropertyCount(shader); for (int i = 0; i < propertyCount; i++) if (!ShaderUtil.IsShaderPropertyHidden(shader, i) || !allowHidden) if (!ShaderUtil.IsShaderPropertyNonModifiableTexureProperty(shader, i) || allowHidden) properties.Add(new ShaderPropertyInfo { index = i, name = ShaderUtil.GetPropertyName(shader, i), type = ShaderUtil.GetPropertyType(shader, i) }); return properties; } /// /// Get all properties from a material, with their name, index, and type /// /// The material to get the properties from /// Include properties marked as hidden and _MainTex /// public static List GetMaterialProperties(Material material, bool allowHidden = false) { if (!material) return new List(); return GetShaderProperties(material.shader, allowHidden); } } }