using System; using System.Collections.Generic; using UnityEditor; namespace Misaki.ShaderGUI { public abstract class ScopedShaderGUI : UnityEditor.ShaderGUI, IMaterialUIScopeContainer { private readonly List _scopes = new(); protected bool initialized; public void AddUIScope(IMaterialUIScope scope) { _scopes.Add(scope); } public T GetUIScope() where T : class, IMaterialUIScope { return _scopes.Find(s => s is T) as T; } public void Initialize(MaterialEditor materialEditor, MaterialProperty[] properties) { foreach (var scope in _scopes) { scope.Initialize(materialEditor, properties, this); } initialized = true; } public void DrawShaderGUI(IEnumerable properties) { if (!initialized) { throw new InvalidOperationException("Initialize must be called before Draw"); } foreach (var scope in _scopes) { scope.UpdateMaterialProperties(properties); scope.Draw(); } } } }