forked from Unity-Technologies/Graphics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializedParameterOverride.cs
More file actions
62 lines (53 loc) · 1.98 KB
/
Copy pathSerializedParameterOverride.cs
File metadata and controls
62 lines (53 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Linq;
using UnityEngine.Rendering.PostProcessing;
namespace UnityEditor.Rendering.PostProcessing
{
/// <summary>
/// A wrapper used for <see cref="ParameterOverride{T}"/> serialization and easy access to the
/// underlying property and override state.
/// </summary>
public sealed class SerializedParameterOverride
{
/// <summary>
/// The override state property of the serialized parameter.
/// </summary>
public SerializedProperty overrideState { get; private set; }
/// <summary>
/// The value property of the serialized parameter.
/// </summary>
public SerializedProperty value { get; private set; }
/// <summary>
/// An array of all attributes set on the original parameter.
/// </summary>
public Attribute[] attributes { get; private set; }
internal SerializedProperty baseProperty;
/// <summary>
/// Returns the display name of the property.
/// </summary>
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;
}
/// <summary>
/// Gets the attribute of type <c>T</c> from the original parameter.
/// </summary>
/// <typeparam name="T">The type of attribute to look for</typeparam>
/// <returns>And attribute or type <c>T</c>, or <c>null</c> if none has been found</returns>
public T GetAttribute<T>()
where T : Attribute
{
return (T)attributes.FirstOrDefault(x => x is T);
}
}
}