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 /// /// The title of the scope /// The mask identifying the scope /// The action that will be drawn if the scope is expanded /// The enum for the scope 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(); } } } }