using System;
using System.Reflection;
using UnityEngine;
using UnityEditor;
using UnityEngine.Rendering.Universal;
namespace UnityEditor.Rendering.Universal
{
///
/// Class ShadowShape2DProvider_ProperyDrawer is the default property drawer for all shadow providers and will render the providers serialized properties
///
[CustomPropertyDrawer(typeof(ShadowShape2DProvider), true)]
public class ShadowShape2DProvider_ProperyDrawer : PropertyDrawer
{
delegate void ProcessChild(SerializedProperty child);
void ProcessChildren(SerializedProperty parentProperty, ProcessChild onProcessChild)
{
var enumerator = parentProperty.GetEnumerator();
while (enumerator.MoveNext())
{
SerializedProperty child = enumerator.Current as SerializedProperty;
if (child != null)
{
onProcessChild(child);
}
}
}
///
/// Gets the name to be listed in the ShadowCaster2D Casting Option drop down.
///
/// Rectangle on the screen to use for the property GUI.
/// The SerializedProperty to make the custom GUI for.
/// The label of this property.
public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
{
ProcessChildren(property, (SerializedProperty child) =>
{
rect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(rect, child);
rect.y += EditorGUIUtility.standardVerticalSpacing + EditorGUIUtility.singleLineHeight;
});
}
///
/// Gets the name to be listed in the ShadowCaster2D Casting Option drop down.
///
/// The SerializedProperty to make the custom GUI for.
/// The label of this property.
/// The float height in pixels.
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
float height = 0;
ProcessChildren(property, (SerializedProperty child) =>
{
height += EditorGUIUtility.standardVerticalSpacing + EditorGUIUtility.singleLineHeight;
});
return height;
}
}
}