experiments with fresnel and shadergraph
[WindSway-HDRP.git] / Library / PackageCache / com.unity.postprocessing@2.1.6 / PostProcessing / Runtime / PostProcessProfile.cs
blob472aec454b503ec140688038070c828802718306
1 using System;
2 using System.Collections.Generic;
4 namespace UnityEngine.Rendering.PostProcessing
6 /// <summary>
7 /// An asset holding a set of post-processing settings to use with a <see cref="PostProcessVolume"/>.
8 /// </summary>
9 /// <seealso cref="PostProcessVolume"/>
10 public sealed class PostProcessProfile : ScriptableObject
12 /// <summary>
13 /// A list of all settings stored in this profile.
14 /// </summary>
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
19 [NonSerialized]
20 public bool isDirty = true;
22 void OnEnable()
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);
32 /// <summary>
33 /// Adds settings for an effect to the profile.
34 /// </summary>
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));
44 /// <summary>
45 /// Adds settings for an effect to the profile.
46 /// </summary>
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;
59 settings.Add(effect);
60 isDirty = true;
61 return effect;
64 /// <summary>
65 /// Adds settings for an effect to the profile.
66 /// </summary>
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");
75 settings.Add(effect);
76 isDirty = true;
77 return effect;
80 /// <summary>
81 /// Removes settings for an effect from the profile.
82 /// </summary>
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));
92 /// <summary>
93 /// Removes settings for an effect from the profile.
94 /// </summary>
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)
100 int toRemove = -1;
102 for (int i = 0; i < settings.Count; i++)
104 if (settings[i].GetType() == type)
106 toRemove = i;
107 break;
111 if (toRemove < 0)
112 throw new InvalidOperationException("Effect doesn't exist in the profile");
114 settings.RemoveAt(toRemove);
115 isDirty = true;
118 /// <summary>
119 /// Checks if an effect has been added to the profile.
120 /// </summary>
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));
129 /// <summary>
130 /// Checks if an effect has been added to the profile.
131 /// </summary>
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)
139 return true;
142 return false;
145 /// <summary>
146 /// Returns settings for a given effect type.
147 /// </summary>
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)
154 if (setting is T)
155 return setting as T;
158 return null;
161 /// <summary>
162 /// Gets settings for a given effect type.
163 /// </summary>
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);
173 outSetting = null;
175 foreach (var setting in settings)
177 if (setting.GetType() == type)
179 outSetting = (T)setting;
180 return true;
184 return false;