using System;
using System.Linq.Expressions;
using UnityEngine.Rendering.PostProcessing;
namespace UnityEditor.Rendering.PostProcessing
{
///
/// The class to inherit from when designing custom effect editors.
///
/// The effect type to create an editor for
public class PostProcessEffectEditor : PostProcessEffectBaseEditor
where T : PostProcessEffectSettings
{
///
/// Find a serialized property using an expression instead of a string. This is safer as it
/// helps avoiding typos and make code refactoring easier.
///
/// The serialized value type
/// The expression to parse to reach the property
/// A or null if none was found
///
///
/// [Serializable]
/// public class MyEffect : PostProcessEffectSettings
/// {
/// public float myParameter = 1f;
/// }
///
/// [PostProcessEditor(typeof(MyEffect))]
/// public class MyEffectEditor : PostProcessEffectEditor<MyEffect>
/// {
/// SerializedProperty m_MyParameter;
///
/// public override void OnEnable()
/// {
/// m_MyParameter = FindProperty(x => x.myParameter);
/// }
/// }
///
///
///
/// If you're trying to retrieve a , you should
/// use instead.
///
///
///
protected SerializedProperty FindProperty(Expression> expr)
{
return serializedObject.FindProperty(RuntimeUtilities.GetFieldPath(expr));
}
///
/// Find a serialized parameter override using an expression instead of a string. This is
/// safer as it helps avoiding typos and make code refactoring easier.
///
/// The serialized value type
/// The expression to parse to reach the parameter override
/// A or null if none was
/// found
///
///
/// [Serializable]
/// public class MyEffect : PostProcessEffectSettings
/// {
/// public FloatParameter myParameter = new FloatParameter { value = 1f };
/// }
///
/// [PostProcessEditor(typeof(MyEffect))]
/// public class MyEffectEditor : PostProcessEffectEditor<MyEffect>
/// {
/// SerializedParameterOverride m_MyParameter;
///
/// public override void OnEnable()
/// {
/// m_MyParameter = FindParameterOverride(x => x.myParameter);
/// }
/// }
///
///
///
protected SerializedParameterOverride FindParameterOverride(Expression> expr)
{
var property = serializedObject.FindProperty(RuntimeUtilities.GetFieldPath(expr));
var attributes = RuntimeUtilities.GetMemberAttributes(expr);
return new SerializedParameterOverride(property, attributes);
}
}
}