2026-04-16 오브젝트 그림자
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace BadDog.Rendering.AreaLight
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom property drawer for AreaLightShadowSettings
|
||||
/// </summary>
|
||||
[CustomPropertyDrawer(typeof(AreaLightShadowSettings))]
|
||||
public class AreaLightShadowSettingsDrawer : PropertyDrawer
|
||||
{
|
||||
private SerializedProperty m_ShadowAtlasResolution;
|
||||
private SerializedProperty m_MaxShadowCastingLights;
|
||||
private SerializedProperty m_ShadowFilter;
|
||||
private SerializedProperty m_PcssShadowSoftness;
|
||||
private SerializedProperty m_PcssBlockerSampleCount;
|
||||
private SerializedProperty m_PcssFilterSampleCount;
|
||||
|
||||
private string m_CachedPropertyPath;
|
||||
|
||||
private void FindProperties(SerializedProperty property)
|
||||
{
|
||||
string currentPath = property.propertyPath;
|
||||
|
||||
if (m_CachedPropertyPath != currentPath)
|
||||
{
|
||||
m_ShadowAtlasResolution = property.FindPropertyRelative("shadowAtlasResolution");
|
||||
m_MaxShadowCastingLights = property.FindPropertyRelative("maxShadowCastingLights");
|
||||
m_ShadowFilter = property.FindPropertyRelative("shadowFilter");
|
||||
m_PcssShadowSoftness = property.FindPropertyRelative("pcssShadowSoftness");
|
||||
m_PcssBlockerSampleCount = property.FindPropertyRelative("pcssBlockerSampleCount");
|
||||
m_PcssFilterSampleCount = property.FindPropertyRelative("pcssFilterSampleCount");
|
||||
m_CachedPropertyPath = currentPath;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
FindProperties(property);
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
Rect foldoutRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
|
||||
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label, true);
|
||||
|
||||
if (!property.isExpanded)
|
||||
{
|
||||
EditorGUI.EndProperty();
|
||||
return;
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
float yOffset = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
DrawProperty(m_ShadowAtlasResolution, ref yOffset, position);
|
||||
DrawProperty(m_MaxShadowCastingLights, ref yOffset, position);
|
||||
|
||||
Rect shadowFilterRect = new Rect(position.x, position.y + yOffset, position.width, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.PropertyField(shadowFilterRect, m_ShadowFilter, new GUIContent("Shadow Filter"));
|
||||
yOffset += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
if (m_ShadowFilter != null)
|
||||
{
|
||||
AreaLightShadowSettings.BGAreaLightShadowMode shadowFilterMode =
|
||||
(AreaLightShadowSettings.BGAreaLightShadowMode)m_ShadowFilter.enumValueIndex;
|
||||
|
||||
if (shadowFilterMode == AreaLightShadowSettings.BGAreaLightShadowMode.PCSS)
|
||||
{
|
||||
Rect headerRect = new Rect(position.x, position.y + yOffset, position.width, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.LabelField(headerRect, "PCSS", EditorStyles.boldLabel);
|
||||
yOffset += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
DrawProperty(m_PcssShadowSoftness, ref yOffset, position);
|
||||
DrawProperty(m_PcssBlockerSampleCount, ref yOffset, position);
|
||||
DrawProperty(m_PcssFilterSampleCount, ref yOffset, position);
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
private void DrawProperty(SerializedProperty prop, ref float yOffset, Rect position)
|
||||
{
|
||||
if (prop != null)
|
||||
{
|
||||
Rect rect = new Rect(position.x, position.y + yOffset, position.width, EditorGUI.GetPropertyHeight(prop));
|
||||
EditorGUI.PropertyField(rect, prop, true);
|
||||
yOffset += EditorGUI.GetPropertyHeight(prop) + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
float height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
if (!property.isExpanded)
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
FindProperties(property);
|
||||
|
||||
height += GetPropertyHeight(m_ShadowAtlasResolution);
|
||||
height += GetPropertyHeight(m_MaxShadowCastingLights);
|
||||
|
||||
if (m_ShadowFilter != null)
|
||||
{
|
||||
height += EditorGUI.GetPropertyHeight(m_ShadowFilter) + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
AreaLightShadowSettings.BGAreaLightShadowMode shadowFilterMode =
|
||||
(AreaLightShadowSettings.BGAreaLightShadowMode)m_ShadowFilter.enumValueIndex;
|
||||
|
||||
if (shadowFilterMode == AreaLightShadowSettings.BGAreaLightShadowMode.PCSS)
|
||||
{
|
||||
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
height += GetPropertyHeight(m_PcssShadowSoftness);
|
||||
height += GetPropertyHeight(m_PcssBlockerSampleCount);
|
||||
height += GetPropertyHeight(m_PcssFilterSampleCount);
|
||||
}
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
private float GetPropertyHeight(SerializedProperty prop)
|
||||
{
|
||||
if (prop != null)
|
||||
{
|
||||
return EditorGUI.GetPropertyHeight(prop) + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user