Files
ichni_Official/Packages/NB_FX/XuanXuanRenderUtility/Editor/ShaderGUIItems/BlockItem.cs
SoulliesOfficial 40fa80cd70 NB_FX
2026-07-17 17:46:16 -04:00

89 lines
2.6 KiB
C#

using System;
using UnityEditor;
using UnityEngine;
namespace NBShaderEditor
{
public class BlockItem : ShaderGUIItem
{
protected readonly ShaderGUIRootItem SharedRootItem;
private readonly ShaderGUIFoldOutHelper _foldOutHelper;
private readonly Func<GUIContent> _contentProvider;
protected virtual GUIStyle TitleStyle => EditorStyles.label;
protected virtual bool DrawSeparatorLine => false;
public string FoldOutPropertyName { get; }
public BlockItem(
ShaderGUIRootItem rootItem,
ShaderGUIItem parentItem,
string foldOutPropertyName,
Func<GUIContent> contentProvider) : base(rootItem, parentItem)
{
SharedRootItem = rootItem;
FoldOutPropertyName = foldOutPropertyName;
_contentProvider = contentProvider ?? (() => GUIContent.none);
GuiContent = _contentProvider();
_foldOutHelper = new ShaderGUIFoldOutHelper(rootItem, foldOutPropertyName);
}
public override void OnGUI()
{
DrawLeadingSpace();
GetRect();
_foldOutHelper.DrawFoldOut(LabelRect);
using (ParentControlDisabledScope())
{
EditorGUI.LabelField(LabelRect, GuiContent, TitleStyle);
}
DrawResetButton();
EditorGUI.indentLevel++;
if (_foldOutHelper.BeginFadeGroup())
{
DrawBlock();
}
_foldOutHelper.EndFadedGroup();
EditorGUI.indentLevel--;
if (DrawSeparatorLine)
{
Rect rect = ApplyGlobalRectCompensation(LayoutRect(1));
EditorGUI.DrawRect(rect, new Color(0.5f, 0.5f, 0.5f, 0.5f));
}
}
protected virtual void DrawLeadingSpace()
{
}
public override void DrawBlock()
{
for (int i = 0; i < ChildrenItemList.Count; i++)
{
ChildrenItemList[i].OnGUI();
}
}
}
public class BigBlockItem : BlockItem
{
protected override GUIStyle TitleStyle => EditorStyles.boldLabel;
protected override bool DrawSeparatorLine => true;
public BigBlockItem(
ShaderGUIRootItem rootItem,
ShaderGUIItem parentItem,
string foldOutPropertyName,
Func<GUIContent> contentProvider) : base(rootItem, parentItem, foldOutPropertyName, contentProvider)
{
}
protected override void DrawLeadingSpace()
{
LayoutSpace();
}
}
}