47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEditor;
|
|
|
|
namespace Misaki.ShaderGUI
|
|
{
|
|
public abstract class ScopedShaderGUI : UnityEditor.ShaderGUI, IMaterialUIScopeContainer
|
|
{
|
|
private readonly List<IMaterialUIScope> _scopes = new();
|
|
|
|
protected bool initialized;
|
|
|
|
public void AddUIScope(IMaterialUIScope scope)
|
|
{
|
|
_scopes.Add(scope);
|
|
}
|
|
|
|
public T GetUIScope<T>() 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<MaterialProperty> properties)
|
|
{
|
|
if (!initialized)
|
|
{
|
|
throw new InvalidOperationException("Initialize must be called before Draw");
|
|
}
|
|
|
|
foreach (var scope in _scopes)
|
|
{
|
|
scope.UpdateMaterialProperties(properties);
|
|
scope.Draw();
|
|
}
|
|
}
|
|
}
|
|
} |