99 lines
4.0 KiB
C#
99 lines
4.0 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using UnityEngine.Rendering;
|
|
using BadDog.Rendering.AreaLight;
|
|
|
|
namespace BadDog.Rendering.AreaLight.Editor
|
|
{
|
|
[CustomEditor(typeof(BGAreaLight))]
|
|
[CanEditMultipleObjects]
|
|
public class BGAreaLightEditor : UnityEditor.Editor
|
|
{
|
|
private SerializedProperty m_CastShadows;
|
|
private SerializedProperty m_UseCustomShadow;
|
|
private SerializedProperty m_CustomShadowResolution;
|
|
private SerializedProperty m_ShadowCone;
|
|
private SerializedProperty m_ShadowStrength;
|
|
private SerializedProperty m_ShadowNormalBias;
|
|
private SerializedProperty m_ShadowDepthBias;
|
|
private SerializedProperty m_ShadowNearPlane;
|
|
private SerializedProperty m_RenderingLayerMask;
|
|
|
|
private void OnEnable()
|
|
{
|
|
m_CastShadows = serializedObject.FindProperty("m_CastShadows");
|
|
m_UseCustomShadow = serializedObject.FindProperty("m_UseCustomShadow");
|
|
m_CustomShadowResolution = serializedObject.FindProperty("m_CustomShadowResolution");
|
|
m_ShadowCone = serializedObject.FindProperty("m_ShadowCone");
|
|
m_ShadowStrength = serializedObject.FindProperty("m_ShadowStrength");
|
|
m_ShadowNormalBias = serializedObject.FindProperty("m_ShadowNormalBias");
|
|
m_ShadowDepthBias = serializedObject.FindProperty("m_ShadowDepthBias");
|
|
m_ShadowNearPlane = serializedObject.FindProperty("m_ShadowNearPlane");
|
|
m_RenderingLayerMask = serializedObject.FindProperty("m_RenderingLayerMask");
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
serializedObject.Update();
|
|
|
|
// Cast Shadows toggle
|
|
EditorGUILayout.PropertyField(m_CastShadows, new GUIContent("Cast Shadows", "Enable shadow casting for this area light."));
|
|
|
|
EditorGUILayout.Space();
|
|
|
|
// Disable all shadow settings if Cast Shadows is off
|
|
EditorGUI.BeginDisabledGroup(!m_CastShadows.boolValue);
|
|
|
|
EditorGUILayout.PropertyField(m_UseCustomShadow, new GUIContent("Custom Shadow", "Enable custom shadow settings for this area light."));
|
|
|
|
EditorGUILayout.Space();
|
|
|
|
EditorGUI.indentLevel++;
|
|
|
|
if (!m_UseCustomShadow.boolValue)
|
|
{
|
|
m_CustomShadowResolution.intValue = 0;
|
|
m_ShadowCone.floatValue = AreaShadowUtils.k_DefaultAreaLightShadowCone;
|
|
m_ShadowStrength.floatValue = 1f;
|
|
m_ShadowNormalBias.floatValue = 0.0f;
|
|
m_ShadowDepthBias.floatValue = 0.05f;
|
|
m_ShadowNearPlane.floatValue = 0.05f;
|
|
}
|
|
|
|
EditorGUI.BeginDisabledGroup(!m_UseCustomShadow.boolValue);
|
|
EditorGUILayout.PropertyField(m_CustomShadowResolution);
|
|
EditorGUILayout.PropertyField(m_ShadowCone);
|
|
EditorGUILayout.PropertyField(m_ShadowStrength);
|
|
EditorGUILayout.PropertyField(m_ShadowNormalBias);
|
|
EditorGUILayout.PropertyField(m_ShadowDepthBias);
|
|
EditorGUILayout.PropertyField(m_ShadowNearPlane);
|
|
EditorGUI.EndDisabledGroup();
|
|
|
|
EditorGUI.indentLevel--;
|
|
|
|
EditorGUI.EndDisabledGroup(); // End Cast Shadows disabled group
|
|
|
|
EditorGUILayout.Space();
|
|
DrawRenderingLayersField();
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
}
|
|
|
|
private void DrawRenderingLayersField()
|
|
{
|
|
EditorGUI.showMixedValue = m_RenderingLayerMask.hasMultipleDifferentValues;
|
|
EditorGUI.BeginChangeCheck();
|
|
uint mask = m_RenderingLayerMask.uintValue;
|
|
mask = EditorGUILayout.RenderingLayerMaskField(
|
|
new GUIContent("Rendering Layers", "Rendering Layer Mask used for area light lighting/shadow filtering."),
|
|
mask);
|
|
if (EditorGUI.EndChangeCheck())
|
|
{
|
|
m_RenderingLayerMask.uintValue = mask;
|
|
}
|
|
EditorGUI.showMixedValue = false;
|
|
}
|
|
}
|
|
}
|
|
|