using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; namespace UnityEditor.Rendering { /// /// Collection to store /// public class MaterialHeaderScopeList { readonly uint m_DefaultExpandedState; internal readonly List m_Items = new List(); /// /// Constructor that initializes it with the default expanded state for the internal scopes /// /// By default, everything is expanded public MaterialHeaderScopeList(uint defaultExpandedState = uint.MaxValue) { m_DefaultExpandedState = defaultExpandedState; } /// /// Registers a into the list /// /// A valid and /// The title of the scope /// The mask identifying the scope /// The action that will be drawn if the scope is expanded public void RegisterHeaderScope(GUIContent title, TEnum expandable, Action action) where TEnum : struct, IConvertible { m_Items.Add(new MaterialHeaderScopeItem() { headerTitle = title, expandable = Convert.ToUInt32(expandable), drawMaterialScope = action, url = DocumentationUtils.GetHelpURL(expandable) }); } /// /// Draws all the with its information stored /// /// /// public void DrawHeaders(MaterialEditor materialEditor, Material material) { if (material == null) throw new ArgumentNullException(nameof(material)); if (materialEditor == null) throw new ArgumentNullException(nameof(materialEditor)); foreach (var item in m_Items) { using var header = new MaterialHeaderScope( item.headerTitle, item.expandable, materialEditor, defaultExpandedState: m_DefaultExpandedState, documentationURL: item.url); if (!header.expanded) continue; item.drawMaterialScope(material); EditorGUILayout.Space(); } // Reset label width back to the default of 0 (fix UUM-66215) // NOTE: Because of how EditorGUIUtility.labelWidth works, when the internal value is 0, // we cannot read that value back from the property getter. So we just set it to 0 here. EditorGUIUtility.labelWidth = 0; } } }