SerializedParameterOverride.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Linq;
  3. using UnityEngine.Rendering.PostProcessing;
  4. namespace UnityEditor.Rendering.PostProcessing
  5. {
  6. /// <summary>
  7. /// A wrapper used for <see cref="ParameterOverride{T}"/> serialization and easy access to the
  8. /// underlying property and override state.
  9. /// </summary>
  10. public sealed class SerializedParameterOverride
  11. {
  12. /// <summary>
  13. /// The override state property of the serialized parameter.
  14. /// </summary>
  15. public SerializedProperty overrideState { get; private set; }
  16. /// <summary>
  17. /// The value property of the serialized parameter.
  18. /// </summary>
  19. public SerializedProperty value { get; private set; }
  20. /// <summary>
  21. /// An array of all attributes set on the original parameter.
  22. /// </summary>
  23. public Attribute[] attributes { get; private set; }
  24. internal SerializedProperty baseProperty;
  25. /// <summary>
  26. /// Returns the display name of the property.
  27. /// </summary>
  28. public string displayName
  29. {
  30. get { return baseProperty.displayName; }
  31. }
  32. internal SerializedParameterOverride(SerializedProperty property, Attribute[] attributes)
  33. {
  34. baseProperty = property.Copy();
  35. var localCopy = baseProperty.Copy();
  36. localCopy.Next(true);
  37. overrideState = localCopy.Copy();
  38. localCopy.Next(false);
  39. value = localCopy.Copy();
  40. this.attributes = attributes;
  41. }
  42. /// <summary>
  43. /// Gets the attribute of type <c>T</c> from the original parameter.
  44. /// </summary>
  45. /// <typeparam name="T">The type of attribute to look for</typeparam>
  46. /// <returns>And attribute or type <c>T</c>, or <c>null</c> if none has been found</returns>
  47. public T GetAttribute<T>()
  48. where T : Attribute
  49. {
  50. return (T)attributes.FirstOrDefault(x => x is T);
  51. }
  52. }
  53. }