Initial upload

This commit is contained in:
2025-02-01 23:08:14 +09:00
commit 4723c9833a
31 changed files with 660 additions and 0 deletions

81
Editor/MaterialUIScope.cs Normal file
View File

@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.Rendering;
using UnityEngine;
namespace Misaki.ShaderGUI
{
public abstract class MaterialUIScope<TExpandableBit> : IMaterialUIScope where TExpandableBit : Enum, IConvertible
{
protected MaterialEditor editor;
protected IEnumerable<MaterialProperty> materialProperties;
protected IMaterialUIScopeContainer owner;
protected virtual bool ShowSection => true;
protected virtual bool IsSubHeader => false;
protected virtual bool SpaceAtEnd => true;
protected virtual string DocumentationURL => string.Empty;
protected abstract TExpandableBit ExpandableBit
{
get;
}
protected abstract GUIContent Header
{
get;
}
public MaterialEditor Editor => editor;
public abstract void LoadMaterialProperties();
protected abstract void DrawContent();
public void Initialize(MaterialEditor materialEditor, IEnumerable<MaterialProperty> properties, IMaterialUIScopeContainer container)
{
editor = materialEditor;
materialProperties = properties;
owner = container;
UpdateMaterialProperties(properties);
}
public MaterialProperty FindProperty(string propertyName)
{
if (materialProperties == null)
{
throw new Exception("Material properties are not initialized.");
}
if (string.IsNullOrEmpty(propertyName))
{
throw new ArgumentException("Property name cannot be null or empty.", nameof(propertyName));
}
return materialProperties.First(p => p.name == propertyName);
}
public void UpdateMaterialProperties(IEnumerable<MaterialProperty> properties)
{
materialProperties = properties;
LoadMaterialProperties();
}
public void Draw()
{
if (!ShowSection)
{
return;
}
using var scope = new MaterialHeaderScope(Header, Convert.ToUInt32(ExpandableBit), editor, spaceAtEnd: SpaceAtEnd, subHeader: IsSubHeader, documentationURL: DocumentationURL);
if (scope.expanded)
{
DrawContent();
}
}
}
}