2 using System
.Collections
.Generic
;
4 namespace UnityEngine
.Rendering
.PostProcessing
7 /// An asset holding a set of post-processing settings to use with a <see cref="PostProcessVolume"/>.
9 /// <seealso cref="PostProcessVolume"/>
10 public sealed class PostProcessProfile
: ScriptableObject
13 /// A list of all settings stored in this profile.
15 [Tooltip("A list of all settings currently stored in this profile.")]
16 public List
<PostProcessEffectSettings
> settings
= new List
<PostProcessEffectSettings
>();
18 // Editor only, doesn't have any use outside of it
20 public bool isDirty
= true;
24 // Make sure every setting is valid. If a profile holds a script that doesn't exist
25 // anymore, nuke it to keep the profile clean. Note that if you delete a script that is
26 // currently in use in a profile you'll still get a one-time error in the console, it's
27 // harmless and happens because Unity does a redraw of the editor (and thus the current
28 // frame) before the recompilation step.
29 settings
.RemoveAll(x
=> x
== null);
33 /// Adds settings for an effect to the profile.
35 /// <typeparam name="T">A type of <see cref="PostProcessEffectSettings"/></typeparam>
36 /// <returns>The instance created from the given type</returns>
37 /// <seealso cref="PostProcessEffectSettings"/>
38 public T AddSettings
<T
>()
39 where T
: PostProcessEffectSettings
41 return (T
)AddSettings(typeof(T
));
45 /// Adds settings for an effect to the profile.
47 /// <param name="type">A type of <see cref="PostProcessEffectSettings"/></param>
48 /// <returns>The instance created from the given type</returns>
49 /// <seealso cref="PostProcessEffectSettings"/>
50 public PostProcessEffectSettings
AddSettings(Type type
)
52 if (HasSettings(type
))
53 throw new InvalidOperationException("Effect already exists in the stack");
55 var effect
= (PostProcessEffectSettings
)CreateInstance(type
);
56 effect
.hideFlags
= HideFlags
.HideInInspector
| HideFlags
.HideInHierarchy
;
57 effect
.name
= type
.Name
;
58 effect
.enabled
.value = true;
65 /// Adds settings for an effect to the profile.
67 /// <param name="effect">An instance of <see cref="PostProcessEffectSettings"/></param>
68 /// <returns>The given effect instance</returns>
69 /// <seealso cref="PostProcessEffectSettings"/>
70 public PostProcessEffectSettings
AddSettings(PostProcessEffectSettings effect
)
72 if (HasSettings(settings
.GetType()))
73 throw new InvalidOperationException("Effect already exists in the stack");
81 /// Removes settings for an effect from the profile.
83 /// <typeparam name="T">The type to look for and remove from the profile</typeparam>
84 /// <exception cref="InvalidOperationException">Thrown if the effect doesn't exist in the
85 /// profile</exception>
86 public void RemoveSettings
<T
>()
87 where T
: PostProcessEffectSettings
89 RemoveSettings(typeof(T
));
93 /// Removes settings for an effect from the profile.
95 /// <param name="type">The type to look for and remove from the profile</param>
96 /// <exception cref="InvalidOperationException">Thrown if the effect doesn't exist in the
97 /// profile</exception>
98 public void RemoveSettings(Type type
)
102 for (int i
= 0; i
< settings
.Count
; i
++)
104 if (settings
[i
].GetType() == type
)
112 throw new InvalidOperationException("Effect doesn't exist in the profile");
114 settings
.RemoveAt(toRemove
);
119 /// Checks if an effect has been added to the profile.
121 /// <typeparam name="T">The type to look for</typeparam>
122 /// <returns><c>true</c> if the effect exists in the profile, <c>false</c> otherwise</returns>
123 public bool HasSettings
<T
>()
124 where T
: PostProcessEffectSettings
126 return HasSettings(typeof(T
));
130 /// Checks if an effect has been added to the profile.
132 /// <param name="type">The type to look for</param>
133 /// <returns><c>true</c> if the effect exists in the profile, <c>false</c> otherwise</returns>
134 public bool HasSettings(Type type
)
136 foreach (var setting
in settings
)
138 if (setting
.GetType() == type
)
146 /// Returns settings for a given effect type.
148 /// <typeparam name="T">The type to look for</typeparam>
149 /// <returns>Settings for the given effect type, <c>null</c> otherwise</returns>
150 public T GetSetting
<T
>() where T
: PostProcessEffectSettings
152 foreach (var setting
in settings
)
162 /// Gets settings for a given effect type.
164 /// <typeparam name="T">The type to look for</typeparam>
165 /// <param name="outSetting">When this method returns, contains the value associated with
166 /// the specified type, if the type is found; otherwise, this parameter will be <c>null</c>.
167 /// This parameter is passed uninitialized.</param>
168 /// <returns><c>true</c> if the effect exists in the profile, <c>false</c> otherwise</returns>
169 public bool TryGetSettings
<T
>(out T outSetting
)
170 where T
: PostProcessEffectSettings
172 var type
= typeof(T
);
175 foreach (var setting
in settings
)
177 if (setting
.GetType() == type
)
179 outSetting
= (T
)setting
;