using System;
using System.Linq;
using UnityEngine.Rendering.PostProcessing;
namespace UnityEditor.Rendering.PostProcessing
{
///
/// A wrapper used for serialization and easy access to the
/// underlying property and override state.
///
public sealed class SerializedParameterOverride
{
///
/// The override state property of the serialized parameter.
///
public SerializedProperty overrideState { get; private set; }
///
/// The value property of the serialized parameter.
///
public SerializedProperty value { get; private set; }
///
/// An array of all attributes set on the original parameter.
///
public Attribute[] attributes { get; private set; }
internal SerializedProperty baseProperty;
///
/// Returns the display name of the property.
///
public string displayName
{
get { return baseProperty.displayName; }
}
internal SerializedParameterOverride(SerializedProperty property, Attribute[] attributes)
{
baseProperty = property.Copy();
var localCopy = baseProperty.Copy();
localCopy.Next(true);
overrideState = localCopy.Copy();
localCopy.Next(false);
value = localCopy.Copy();
this.attributes = attributes;
}
///
/// Gets the attribute of type T from the original parameter.
///
/// The type of attribute to look for
/// And attribute or type T, or null if none has been found
public T GetAttribute()
where T : Attribute
{
return (T)attributes.FirstOrDefault(x => x is T);
}
}
}