-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostProcessProfile.cs
More file actions
131 lines (110 loc) · 3.78 KB
/
Copy pathPostProcessProfile.cs
File metadata and controls
131 lines (110 loc) · 3.78 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Collections.Generic;
namespace UnityEngine.Rendering.PostProcessing
{
public sealed class PostProcessProfile : ScriptableObject
{
[Tooltip("A list of all settings & overrides.")]
public List<PostProcessEffectSettings> settings = new List<PostProcessEffectSettings>();
// Editor only, doesn't have any use outside of it
[NonSerialized]
public bool isDirty = true;
void OnEnable()
{
// Make sure every setting is valid. If a profile holds a script that doesn't exist
// anymore, nuke it to keep the profile clean. Note that if you delete a script that is
// currently in use in a profile you'll still get a one-time error in the console, it's
// harmless and happens because Unity does a redraw of the editor (and thus the current
// frame) before the recompilation step.
settings.RemoveAll(x => x == null);
}
public void Reset()
{
isDirty = true;
}
public T AddSettings<T>()
where T : PostProcessEffectSettings
{
return (T)AddSettings(typeof(T));
}
public PostProcessEffectSettings AddSettings(Type type)
{
if (HasSettings(type))
throw new InvalidOperationException("Effect already exists in the stack");
var effect = (PostProcessEffectSettings)CreateInstance(type);
effect.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy;
effect.name = type.Name;
effect.enabled.value = true;
settings.Add(effect);
isDirty = true;
return effect;
}
public PostProcessEffectSettings AddSettings(PostProcessEffectSettings effect)
{
if (HasSettings(settings.GetType()))
throw new InvalidOperationException("Effect already exists in the stack");
settings.Add(effect);
isDirty = true;
return effect;
}
public void RemoveSettings<T>()
where T : PostProcessEffectSettings
{
RemoveSettings(typeof(T));
}
public void RemoveSettings(Type type)
{
int toRemove = -1;
for (int i = 0; i < settings.Count; i++)
{
if (settings[i].GetType() == type)
{
toRemove = i;
break;
}
}
if (toRemove < 0)
throw new InvalidOperationException("Effect doesn't exist in the stack");
settings.RemoveAt(toRemove);
isDirty = true;
}
public bool HasSettings<T>()
where T : PostProcessEffectSettings
{
return HasSettings(typeof(T));
}
public bool HasSettings(Type type)
{
foreach (var setting in settings)
{
if (setting.GetType() == type)
return true;
}
return false;
}
public T GetSetting<T>() where T : PostProcessEffectSettings
{
foreach (var setting in settings)
{
if (setting is T)
return setting as T;
}
return null;
}
public bool TryGetSettings<T>(out T outSetting)
where T : PostProcessEffectSettings
{
var type = typeof(T);
outSetting = null;
foreach (var setting in settings)
{
if (setting.GetType() == type)
{
outSetting = (T)setting;
return true;
}
}
return false;
}
}
}